From 634e7662a5a3963e0a8417e6ca642c724f4acd85 Mon Sep 17 00:00:00 2001 From: vermaas <vermaas@astron.nl> Date: Thu, 20 Oct 2022 10:43:41 +0200 Subject: [PATCH] updating ci/cd pipeline with stages testing if deploy still works (after 3 months) --- .gitignore | 1 + .gitlab-ci.yml | 73 +++++++++++++++---- .../templates/taskdatabase/index.html | 2 +- 3 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..5f4486cc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/atdb/logs/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 14f5c661..4775a40c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,8 @@ stages: - build - deploy + - deploy_to_test + - deploy_to_production docker-build-master: # Official docker image. @@ -18,21 +20,21 @@ docker-build-master: - acceptance - release -#docker-build-branch: - # Official docker image. -# image: docker:latest -# stage: build -# services: -# - docker:dind -# before_script: -# - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY -# script: -# - docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" atdb -# - docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" -# except: -# - master -# - acceptance -# - release +docker-build-branch: +# Official docker image. + image: docker:latest + stage: build + services: + - docker:dind + before_script: + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + script: + - docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" atdb + - docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" + except: + - master + - acceptance + - release # deploy test/dev version on 'sdc-dev.astron.nl' docker-deploy-master: @@ -53,6 +55,7 @@ docker-deploy-master: only: - master + # deploy acceptance version on 'dop457.astron.nl' docker-deploy-acceptance: image: docker:latest @@ -89,5 +92,45 @@ docker-deploy-release: - ssh -o StrictHostKeyChecking=no sdco@dop821.astron.nl "docker pull "$CI_REGISTRY_IMAGE"" - ssh -o StrictHostKeyChecking=no sdco@dop821.astron.nl "docker-compose -p atdb -f /opt/dockercompose/atdb-ldv-compose/docker-compose-production-cd.yml up -d" when: manual + only: + - release + + +# deploy master branch to 'sdc-dev.astron.nl' +docker-deploy-to-test: + image: docker:latest + stage: deploy-to-test + before_script: + - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )' + - eval $(ssh-agent -s) + - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - ssh-keyscan dop814.astron.nl >> ~/.ssh/known_hosts + - chmod 644 ~/.ssh/known_hosts + script: + - ssh -o StrictHostKeyChecking=no vermaas@dop814.astron.nl "docker pull "$CI_REGISTRY_IMAGE"" + - ssh -o StrictHostKeyChecking=no vermaas@dop814.astron.nl "docker-compose -p atdb -f /docker_compose/atdb-ldv/docker-compose-dev-cd.yml up -d" + when: manual +# only: +# - master + +# deploy master branch to 'sdc.astron.nl' +docker-deploy-to-production: + image: docker:latest + stage: deploy-to-production + before_script: + - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )' + - eval $(ssh-agent -s) + - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - ssh-keyscan dop821.astron.nl >> ~/.ssh/known_hosts + - chmod 644 ~/.ssh/known_hosts + script: + - ssh -o StrictHostKeyChecking=no sdco@dop821.astron.nl "echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY" + - ssh -o StrictHostKeyChecking=no sdco@dop821.astron.nl "docker pull "$CI_REGISTRY_IMAGE"" + - ssh -o StrictHostKeyChecking=no sdco@dop821.astron.nl "docker-compose -p atdb -f /opt/dockercompose/atdb-ldv-compose/docker-compose-production-cd.yml up -d" + when: manual only: - release \ No newline at end of file diff --git a/atdb/taskdatabase/templates/taskdatabase/index.html b/atdb/taskdatabase/templates/taskdatabase/index.html index 55ba5dde..1e74cca1 100644 --- a/atdb/taskdatabase/templates/taskdatabase/index.html +++ b/atdb/taskdatabase/templates/taskdatabase/index.html @@ -34,7 +34,7 @@ {% include 'taskdatabase/pagination.html' %} </div> </div> - <p class="footer"> Version 1.0.0 (11 jul 2022 - 9:00) + <p class="footer"> Version 1.0.0 (20 oct 2022 - 10:00) </div> -- GitLab