From 1144245156f3803b04eaf65da019882176a0f283 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Thu, 20 Jul 2023 12:32:45 +1000 Subject: [PATCH 1/5] fix: move the pre and post rollout variable check to allow promote(#223) --- legacy/build-deploy-docker-compose.sh | 36 +++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index 60191587..151887da 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -586,29 +586,29 @@ readarray LAGOON_CACHE_BUILD_ARGS < <(kubectl -n ${NAMESPACE} get deployments -o ### BUILD IMAGES ############################################## +set +x # reduce noise in build logs +# Get the pre-rollout and post-rollout vars + if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then + LAGOON_PREROLLOUT_DISABLED=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_PREROLLOUT_DISABLED") | "\(.value)"')) + LAGOON_POSTROLLOUT_DISABLED=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_POSTROLLOUT_DISABLED") | "\(.value)"')) + fi + if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then + TEMP_LAGOON_PREROLLOUT_DISABLED=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_PREROLLOUT_DISABLED") | "\(.value)"')) + TEMP_LAGOON_POSTROLLOUT_DISABLED=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_POSTROLLOUT_DISABLED") | "\(.value)"')) + if [ ! -z $TEMP_LAGOON_PREROLLOUT_DISABLED ]; then + LAGOON_PREROLLOUT_DISABLED=$TEMP_LAGOON_PREROLLOUT_DISABLED + fi + if [ ! -z $TEMP_LAGOON_POSTROLLOUT_DISABLED ]; then + LAGOON_POSTROLLOUT_DISABLED=$TEMP_LAGOON_POSTROLLOUT_DISABLED + fi + fi +set -x + # we only need to build images for pullrequests and branches if [[ "$BUILD_TYPE" == "pullrequest" || "$BUILD_TYPE" == "branch" ]]; then BUILD_ARGS=() - set +x # reduce noise in build logs - # Get the pre-rollout and post-rollout vars - if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then - LAGOON_PREROLLOUT_DISABLED=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_PREROLLOUT_DISABLED") | "\(.value)"')) - LAGOON_POSTROLLOUT_DISABLED=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_POSTROLLOUT_DISABLED") | "\(.value)"')) - fi - if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then - TEMP_LAGOON_PREROLLOUT_DISABLED=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_PREROLLOUT_DISABLED") | "\(.value)"')) - TEMP_LAGOON_POSTROLLOUT_DISABLED=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_POSTROLLOUT_DISABLED") | "\(.value)"')) - if [ ! -z $TEMP_LAGOON_PREROLLOUT_DISABLED ]; then - LAGOON_PREROLLOUT_DISABLED=$TEMP_LAGOON_PREROLLOUT_DISABLED - fi - if [ ! -z $TEMP_LAGOON_POSTROLLOUT_DISABLED ]; then - LAGOON_POSTROLLOUT_DISABLED=$TEMP_LAGOON_POSTROLLOUT_DISABLED - fi - fi - set -x - set +x # reduce noise in build logs # Add environment variables from lagoon API as build args if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then From 9e7870a325d885a53df64635d5528eeb26a9b004 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Fri, 21 Jul 2023 13:37:17 +1000 Subject: [PATCH 2/5] feat: support a shared bucket for backups (#219) --- legacy/scripts/exec-backup-generation.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/legacy/scripts/exec-backup-generation.sh b/legacy/scripts/exec-backup-generation.sh index a5726738..df4dc63c 100755 --- a/legacy/scripts/exec-backup-generation.sh +++ b/legacy/scripts/exec-backup-generation.sh @@ -103,7 +103,16 @@ if [[ "${CAPABILITIES[@]}" =~ "backup.appuio.ch/v1alpha1/Schedule" ]]; then BAAS_BUCKET_NAME=$(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_BAAS_BUCKET_NAME") | "\(.value)"') fi if [ -z $BAAS_BUCKET_NAME ]; then - BAAS_BUCKET_NAME=baas-${PROJECT} + # check for shared/cluster scoped bucket + # use build scope for now for testing + SHARED_BUCKET_NAME=$(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.scope == "internal_system" and .name == "LAGOON_SYSTEM_PROJECT_SHARED_BUCKET") | "\(.value)"') + if [ -z $SHARED_BUCKET_NAME ]; then + # if no shared bucketname, create as normal + BAAS_BUCKET_NAME=baas-${PROJECT} + else + # if shared, create using shared bucketname + BAAS_BUCKET_NAME=${SHARED_BUCKET_NAME}/baas-${PROJECT} + fi fi # Pull in .lagoon.yml variables From a7a6ad337f5555d75e4bde044085288835710473 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Thu, 14 Sep 2023 11:04:37 +1000 Subject: [PATCH 3/5] refactor: prefer the service account token over the older deployer token (#225) --- legacy/build-deploy.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/legacy/build-deploy.sh b/legacy/build-deploy.sh index fbb667aa..89c306a9 100755 --- a/legacy/build-deploy.sh +++ b/legacy/build-deploy.sh @@ -62,11 +62,12 @@ PRIVATE_DOCKER_HUB_REGISTRY=0 PRIVATE_EXTERNAL_REGISTRY=0 set +x # reduce noise in build logs -if [[ -f "/var/run/secrets/lagoon/deployer/token" ]]; then - DEPLOYER_TOKEN=$(cat /var/run/secrets/lagoon/deployer/token) -else +if [[ -f "/var/run/secrets/kubernetes.io/serviceaccount/token" ]]; then DEPLOYER_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) -fi +else + if [[ -f "/var/run/secrets/lagoon/deployer/token" ]]; then + DEPLOYER_TOKEN=$(cat /var/run/secrets/lagoon/deployer/token) + fi if [ -z ${DEPLOYER_TOKEN} ]; then echo "No deployer token found"; exit 1; fi From 300b98c971bc3f93a4e985b804725e431f023fd6 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Mon, 18 Sep 2023 09:02:31 +1000 Subject: [PATCH 4/5] fix: add missing closing fi to if (#232) --- legacy/build-deploy.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/legacy/build-deploy.sh b/legacy/build-deploy.sh index 89c306a9..4179119a 100755 --- a/legacy/build-deploy.sh +++ b/legacy/build-deploy.sh @@ -68,6 +68,7 @@ else if [[ -f "/var/run/secrets/lagoon/deployer/token" ]]; then DEPLOYER_TOKEN=$(cat /var/run/secrets/lagoon/deployer/token) fi +fi if [ -z ${DEPLOYER_TOKEN} ]; then echo "No deployer token found"; exit 1; fi From dde19fb7c7c702316f1fc8b99403fd924018904d Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 28 Sep 2023 09:40:55 +1000 Subject: [PATCH 5/5] refactor: patch at the start of the step, rather than the end --- legacy/build-deploy-docker-compose.sh | 49 +++++++++++++-------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index 151887da..8dd9e3d4 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -99,10 +99,17 @@ set -x function beginBuildStep() { [ "$1" ] || return #Buildstep start + [ "$2" ] || return #buildstep echo -e "##############################################\nBEGIN ${1}\n##############################################" - sleep 0.5s + # patch the buildpod with the buildstep + if [ "${SCC_CHECK}" == false ]; then + kubectl patch -n ${NAMESPACE} pod ${LAGOON_BUILD_NAME} \ + -p "{\"metadata\":{\"labels\":{\"lagoon.sh/buildStep\":\"${2}\"}}}" &> /dev/null + # tiny sleep to allow patch to complete before logs roll again + sleep 0.5s + fi } function patchBuildStep() { @@ -124,23 +131,15 @@ function patchBuildStep() { diffTotalTime=$(date -d @${diffTotalSeconds} +"%H:%M:%S" -u) echo -e "##############################################\nSTEP ${6}: Completed at ${3} (${timeZone}) Duration ${diffTime} Elapsed ${diffTotalTime}\n##############################################" - - # patch the buildpod with the buildstep - if [ "${SCC_CHECK}" == false ]; then - kubectl patch -n ${4} pod ${LAGOON_BUILD_NAME} \ - -p "{\"metadata\":{\"labels\":{\"lagoon.sh/buildStep\":\"${5}\"}}}" &> /dev/null - - # tiny sleep to allow patch to complete before logs roll again - sleep 0.5s - fi } + ############################################## ### PREPARATION ############################################## set +x buildStartTime="$(date +"%Y-%m-%d %H:%M:%S")" -beginBuildStep "Initial Environment Setup" +beginBuildStep "Initial Environment Setup" "initialSetup" echo "STEP: Preparation started ${buildStartTime}" set -x @@ -256,7 +255,7 @@ set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${buildStartTime}" "${currentStepEnd}" "${NAMESPACE}" "initialSetup" "Initial Environment Setup" previousStepEnd=${currentStepEnd} -beginBuildStep "Configure Variables" +beginBuildStep "Configure Variables" "configuringVariables" set -x DEPLOY_TYPE=$(cat .lagoon.yml | shyaml get-value environments.${BRANCH//./\\.}.deploy-type default) @@ -571,7 +570,7 @@ set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${buildStartTime}" "${currentStepEnd}" "${NAMESPACE}" "configureVars" "Configure Variables" previousStepEnd=${currentStepEnd} -beginBuildStep "Image Builds" +beginBuildStep "Image Builds" "buildingImages" set -x ############################################## ### CACHE IMAGE LIST GENERATION @@ -796,7 +795,7 @@ set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "imageBuildComplete" "Image Builds" previousStepEnd=${currentStepEnd} -beginBuildStep "Pre-Rollout Tasks" +beginBuildStep "Pre-Rollout Tasks" "runningPreRolloutTasks" set -x ############################################## @@ -813,7 +812,7 @@ set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "preRolloutsCompleted" "Pre-Rollout Tasks" previousStepEnd=${currentStepEnd} -beginBuildStep "Service Configuration Phase 1" +beginBuildStep "Service Configuration Phase 1" "serviceConfigurationPhase1" set -x @@ -920,7 +919,7 @@ set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "serviceConfigurationComplete" "Service Configuration Phase 1" previousStepEnd=${currentStepEnd} -beginBuildStep "Service Configuration Phase 2" +beginBuildStep "Service Configuration Phase 2" "serviceConfigurationPhase2" set -x ############################################## @@ -1107,7 +1106,7 @@ set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "serviceConfiguration2Complete" "Service Configuration Phase 2" previousStepEnd=${currentStepEnd} -beginBuildStep "Route/Ingress Configuration" +beginBuildStep "Route/Ingress Configuration" "configuringRoutes" TEMPLATE_PARAMETERS=() @@ -1139,7 +1138,7 @@ fi currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "routeConfigurationComplete" "Route/Ingress Configuration" previousStepEnd=${currentStepEnd} -beginBuildStep "Backup Configuration" +beginBuildStep "Backup Configuration" "configuringBackups" # Run the backup generation script BACKUPS_DISABLED=false @@ -1177,7 +1176,7 @@ set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "backupConfigurationComplete" "Backup Configuration" previousStepEnd=${currentStepEnd} -beginBuildStep "Image Push to Registry" +beginBuildStep "Image Push to Registry" "pushingImages" set -x ############################################## @@ -1381,7 +1380,7 @@ set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "imagePushComplete" "Image Push to Registry" previousStepEnd=${currentStepEnd} -beginBuildStep "Deployment Templating" +beginBuildStep "Deployment Templating" "templatingDeployments" set -x ############################################## @@ -1533,7 +1532,7 @@ set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "deploymentTemplatingComplete" "Deployment Templating" previousStepEnd=${currentStepEnd} -beginBuildStep "Applying Deployments" +beginBuildStep "Applying Deployments" "applyingDeployments" set -x ############################################## @@ -1599,7 +1598,7 @@ set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "deploymentApplyComplete" "Applying Deployments" previousStepEnd=${currentStepEnd} -beginBuildStep "Cronjob Cleanup" +beginBuildStep "Cronjob Cleanup" "cleaningUpCronjobs" set -x ############################################## @@ -1627,7 +1626,7 @@ set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "cronjobCleanupComplete" "Cronjob Cleanup" previousStepEnd=${currentStepEnd} -beginBuildStep "Post-Rollout Tasks" +beginBuildStep "Post-Rollout Tasks" "runningPostRolloutTasks" set -x ############################################## @@ -1645,7 +1644,7 @@ set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "postRolloutsCompleted" "Post-Rollout Tasks" previousStepEnd=${currentStepEnd} -beginBuildStep "Build and Deploy" +beginBuildStep "Build and Deploy" "finalizingBuild" set -x ############################################## @@ -1679,7 +1678,7 @@ set -x set +x if [ "$(featureFlag INSIGHTS)" = enabled ]; then - beginBuildStep "Insights Gathering" + beginBuildStep "Insights Gathering" "gatheringInsights" ############################################## ### RUN insights gathering and store in configmap ##############################################