From 5b631eedb8d5709b5af85f92aa07b4ee61e04451 Mon Sep 17 00:00:00 2001
From: thijsheijden <hi@thijsheijden.nl>
Date: Mon, 31 Jan 2022 11:28:16 +0100
Subject: [PATCH] Added Deploy stage

Deploy stage has essentially been copied over from the old frontend, so changes WILL have to be made to get it to work properly.
---
 .gitlab-ci.yml | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index a7a7dce05..93ea0055c 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -47,7 +47,7 @@ test:
   script:
     - yarn nx affected --base=HEAD~1 --target=test --parallel --max-parallel=2
 
-build-docker:
+docker:
   image: docker:stable
   stage: docker
   tags:
@@ -64,3 +64,26 @@ build-docker:
     - docker push datastropheregistry.azurecr.io/$CI_PROJECT_NAME:$DOCKER_TAG
   dependencies:
     - build
+
+deploy:
+  stage: deploy
+  only:
+    - main
+    - develop
+  script:
+    - apk add --update --no-cache openssh-client >/dev/null
+    - mkdir ~/.ssh/
+    - eval $(ssh-agent -s)
+    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
+    - chmod 600 ~/.ssh/id_rsa
+    - ssh-add ~/.ssh/id_rsa
+    - echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
+    - chmod 644 ~/.ssh/known_hosts
+    - ssh -fN -L 1234:science-vs260.science.uu.nl:22 sivan@up.science.uu.nl
+    # Copy kubernetes files over
+    - scp -r -o StrictHostKeyChecking=no -P 1234 -i ~/.ssh/id_rsa deployments/* root@localhost:/root/kubernetes/$CI_PROJECT_NAME
+    # Deploy all yml files
+    - ssh -p 1234 -i ~/.ssh/id_rsa root@localhost "for i in kubernetes/$CI_PROJECT_NAME/*.yml; do kubectl apply -f \$i; done"
+    # Perform rolling update for deployment
+    - ssh -p 1234 -i ~/.ssh/id_rsa root@localhost "kubectl rollout restart -f kubernetes/$CI_PROJECT_NAME/deployment.yml"
+  dependencies: []
-- 
GitLab