From 906c9cd0b58219ff63b0a3b4f82c574506611978 Mon Sep 17 00:00:00 2001
From: "orestis.malaspin" <orestis.malaspinas@hesge.ch>
Date: Wed, 12 Jul 2023 22:49:51 +0200
Subject: [PATCH] Resolve "Add CI/CD for deployment of the book."

---
 .gitlab-ci.yml      | 34 ++++++++++++++++++++++++++++++++--
 book/src/SUMMARY.md |  4 ++--
 2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 6f0fb81..1f2662d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -5,10 +5,34 @@ image: "rust:1.70-alpine3.17"
 before_script:
   - apk add --no-cache musl-dev curl
   - mkdir -p $HOME/.cargo/bin
-  - which rustc
-  - which cargo
   - curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.31/mdbook-v0.4.31-x86_64-unknown-linux-musl.tar.gz | tar -xz --directory=$HOME/.cargo/bin
   - export PATH=$PATH:$HOME/.cargo/bin
+  ##
+  ## Install ssh-agent if not already installed, it is required by Docker.
+  ##
+  - 'which ssh-agent || (apk add --update openssh-client)'
+  - 'which rsync || (apk add --update rsync)'
+  - 'which chmod || (apk add --update chmod)'
+  ##
+  ## Run ssh-agent (inside the build environment)
+  ##
+  - eval $(ssh-agent -s)
+  ##
+  ## Give the right permissions, otherwise ssh-add will refuse to add files
+  ## Add the SSH key stored in SSH_PRIVATE_KEY file type CI/CD variable to the agent store
+  ##
+  - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
+  ##
+  ## Create the SSH directory and give it the right permissions
+  ##
+  - mkdir -p ~/.ssh
+  - chmod 700 ~/.ssh
+  ##
+  ## Assuming you created the SSH_KNOWN_HOSTS file type CI/CD variable, uncomment the
+  ## following two lines.
+  ##
+  - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
+  - chmod 644 ~/.ssh/known_hosts
 
 test:cargo:
   script:
@@ -21,3 +45,9 @@ run_test_doc:
     - cd ../book
     - mdbook test
     - mdbook build
+
+run_deploy_book:
+  script:
+    - cd book
+    - mdbook build
+    - rsync -avz book/* ur1bg_malas@ur1bg.ftp.infomaniak.com:web/malaspinas/rust-101/
diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md
index a8f86ad..265cd88 100644
--- a/book/src/SUMMARY.md
+++ b/book/src/SUMMARY.md
@@ -1,4 +1,4 @@
-# Sommaire
+# Summary
 
 - [Part 00](./part00.md)
 - [Part 01](./part01.md)
@@ -22,4 +22,4 @@ $ mdbook build
 et vous retrouverez l'index dans le fichier
 ```bash
 $ book/index.html
-```
\ No newline at end of file
+```
-- 
GitLab