From eee6348e8d81be6ff42b5d9313c95d3693c47c58 Mon Sep 17 00:00:00 2001 From: Dominik Hebeler <dominik@suma-ev.de> Date: Fri, 27 May 2022 12:26:13 +0200 Subject: [PATCH] fixed deployment not stopping for review --- .gitlab/ci/build_docker_images.yml | 20 +++++++++---------- .gitlab/ci/deploy.yml | 15 ++++---------- .../deployment_scripts/delete_deployment.sh | 13 ++++++++++++ 3 files changed, 27 insertions(+), 21 deletions(-) create mode 100755 .gitlab/deployment_scripts/delete_deployment.sh diff --git a/.gitlab/ci/build_docker_images.yml b/.gitlab/ci/build_docker_images.yml index f373f686c..1e6748f93 100644 --- a/.gitlab/ci/build_docker_images.yml +++ b/.gitlab/ci/build_docker_images.yml @@ -10,9 +10,9 @@ fpm: - echo '!metager/vendor' >> .dockerignore script: - docker build --network=host - --target=production - -f build/fpm/Dockerfile - -t ${CI_REGISTRY_IMAGE}/$DOCKER_FPM_IMAGE_NAME:$DOCKER_FPM_IMAGE_TAG . + --target=production + -f build/fpm/Dockerfile + -t ${CI_REGISTRY_IMAGE}/$DOCKER_FPM_IMAGE_NAME:$DOCKER_FPM_IMAGE_TAG . - docker push ${CI_REGISTRY_IMAGE}/$DOCKER_FPM_IMAGE_NAME:$DOCKER_FPM_IMAGE_TAG after_script: - docker logout $CI_REGISTRY @@ -26,9 +26,9 @@ nginx: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY script: - docker build --network=host - --target=production - -f build/nginx/Dockerfile - -t ${CI_REGISTRY_IMAGE}/$DOCKER_NGINX_IMAGE_NAME:$DOCKER_NGINX_IMAGE_TAG . + --target=production + -f build/nginx/Dockerfile + -t ${CI_REGISTRY_IMAGE}/$DOCKER_NGINX_IMAGE_NAME:$DOCKER_NGINX_IMAGE_TAG . - docker push ${CI_REGISTRY_IMAGE}/$DOCKER_NGINX_IMAGE_NAME:$DOCKER_NGINX_IMAGE_TAG after_script: - docker logout $CI_REGISTRY @@ -42,8 +42,8 @@ nginx: variables: FPM_REPOSITORY_ID: 418 NGINX_REPOSITORY_ID: 416 - NODE_REPOSITORY_ID: 416 - KEEP_N: 9 # Trim to the latest 9 revisions as the 10th will be deleted in the next stage + NODE_REPOSITORY_ID: 419 + KEEP_N: 9 # Trim to the latest 9 revisions as the 10th will be deleted in the next stage before_script: - chmod go-r $KUBECONFIG script: @@ -61,7 +61,7 @@ cleanup_revision_images_review: rules: - if: '$CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "development"' when: never - - if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH' + - if: "$CI_COMMIT_TAG || $CI_COMMIT_BRANCH" cleanup_revision_images_development: extends: @@ -85,4 +85,4 @@ cleanup_revision_images_production: rules: - if: '$CI_COMMIT_BRANCH != "master"' when: never - - if: '$CI_COMMIT_BRANCH == "master"' \ No newline at end of file + - if: '$CI_COMMIT_BRANCH == "master"' diff --git a/.gitlab/ci/deploy.yml b/.gitlab/ci/deploy.yml index 014151c19..ef19825fa 100644 --- a/.gitlab/ci/deploy.yml +++ b/.gitlab/ci/deploy.yml @@ -59,7 +59,7 @@ deploy_review: rules: - if: '$CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "development"' when: never - - if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH' + - if: "$CI_COMMIT_TAG || $CI_COMMIT_BRANCH" stop_review: stage: deploy @@ -69,20 +69,13 @@ stop_review: action: stop variables: DEPLOYMENT_CHART_NAME: review-${CI_COMMIT_REF_SLUG} - KEEP_N: 0 # Environment gets deleted. No Image Tags to keep + KEEP_N: 0 # Environment gets deleted. No Image Tags to keep FPM_REPOSITORY_ID: 418 NGINX_REPOSITORY_ID: 416 script: - - echo "Removing Image Tags..." - - .gitlab/deployment_scripts/cleanup_tags_revision.sh - # For some reason an empty image tag gets created for this. We need to delete it until we find out why that is - - 'curl --fail --silent -X DELETE -H "JOB-TOKEN: $CI_JOB_TOKEN" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/registry/repositories/$FPM_REPOSITORY_ID/tags/$DOCKER_IMAGE_TAG_PREFIX"' - - 'curl --fail --silent -X DELETE -H "JOB-TOKEN: $CI_JOB_TOKEN" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/registry/repositories/$NGINX_REPOSITORY_ID/tags/$DOCKER_IMAGE_TAG_PREFIX"' - - echo "Stopping Deployment..." - - kubectl -n $KUBE_NAMESPACE delete secret $CI_COMMIT_REF_SLUG - - helm -n $KUBE_NAMESPACE delete $DEPLOYMENT_CHART_NAME + - .gitlab/deployment_scripts/delete_deployment.sh when: manual rules: - if: '$CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "development"' when: never - - if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH' \ No newline at end of file + - if: "$CI_COMMIT_TAG || $CI_COMMIT_BRANCH" diff --git a/.gitlab/deployment_scripts/delete_deployment.sh b/.gitlab/deployment_scripts/delete_deployment.sh new file mode 100755 index 000000000..3a02daa0b --- /dev/null +++ b/.gitlab/deployment_scripts/delete_deployment.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +HELM_RELEASE_NAME=${HELM_RELEASE_NAME:0:53} +HELM_RELEASE_NAME=${HELM_RELEASE_NAME%%*(-)} + +echo "Removing Image Tags..." +.gitlab/deployment_scripts/cleanup_tags_revision.sh +# For some reason an empty image tag gets created for this. We need to delete it until we find out why that is +'curl --fail --silent -X DELETE -H "JOB-TOKEN: $CI_JOB_TOKEN" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/registry/repositories/$FPM_REPOSITORY_ID/tags/$DOCKER_IMAGE_TAG_PREFIX"' +'curl --fail --silent -X DELETE -H "JOB-TOKEN: $CI_JOB_TOKEN" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/registry/repositories/$NGINX_REPOSITORY_ID/tags/$DOCKER_IMAGE_TAG_PREFIX"' +echo "Stopping Deployment..." +kubectl -n $KUBE_NAMESPACE delete secret $HELM_RELEASE_NAME +helm -n $KUBE_NAMESPACE delete $HELM_RELEASE_NAME \ No newline at end of file -- GitLab