From 0ec13bf018ca353573d8cf548a53b91c377956b8 Mon Sep 17 00:00:00 2001
From: Jacek Lebioda <jacek.lebioda@uni.lu>
Date: Thu, 19 Mar 2020 14:38:30 +0100
Subject: [PATCH] feat: deploy to staticpages vm

---
 .gitlab-ci.yml | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 10392b2e..03ba98cf 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -48,3 +48,25 @@ pages:
     expire_in: 1 week
     paths:
       - public
+
+## Deploys the website to a separate VM
+Deploy to production:
+  stage: deploy
+  image: alpine:3.1
+  before_script:
+    - 'which ssh-agent || ( apk add --update openssh )'
+    - eval $(ssh-agent -s)
+    - echo "$B64SSHPRIVKEY" | base64 -d | tr -d '\r' | ssh-add - > /dev/null
+    - mkdir -p ~/.ssh && chmod 700 ~/.ssh
+    - 'echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
+    - echo "$KNOWNHOSTS" > ~/.ssh/known_hosts
+    - chmod 644 ~/.ssh/known_hosts
+  rules:
+    - if: '$CI_COMMIT_BRANCH == "develop" && $CI_PROJECT_PATH == "R3/howto-cards"'
+    - if: '$CI_COMMIT_BRANCH == "master" && $CI_PROJECT_PATH == "R3/howto-cards"'
+    - if: '$CI_COMMIT_BRANCH == "16-deploy-to-staticpages-vm"'
+  script:
+    - ssh -p $SSHPORT $SSHCONNECT "mkdir -p ~/sources/public/web_$CI_JOB_ID ~/web/public"
+    - scp -P $SSHPORT -r processed_build/* $SSHCONNECT:~/sources/public/web_$CI_JOB_ID
+    - ssh -p $SSHPORT $SSHCONNECT "cd ~/web/public && ln -fs ~/sources/public/web_$CI_JOB_ID/* . && cd ~/sources/public/ && find . -type d -not -newermt '-1 minutes' -exec rm -rf {} +;"
+
-- 
GitLab