Skip to content

Commit

Permalink
Merge branch 'main' into combined-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon authored Sep 28, 2023
2 parents c488ef2 + 71f21f8 commit 432d703
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 47 deletions.
85 changes: 42 additions & 43 deletions legacy/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -586,29 +585,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
Expand Down Expand Up @@ -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

##############################################
Expand All @@ -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


Expand Down Expand Up @@ -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

##############################################
Expand Down Expand Up @@ -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=()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

##############################################
Expand Down Expand Up @@ -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

##############################################
Expand Down Expand Up @@ -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

##############################################
Expand Down Expand Up @@ -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

##############################################
Expand Down Expand Up @@ -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

##############################################
Expand All @@ -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

##############################################
Expand Down Expand Up @@ -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
##############################################
Expand Down
8 changes: 5 additions & 3 deletions legacy/build-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +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)
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;
Expand Down
11 changes: 10 additions & 1 deletion legacy/scripts/exec-backup-generation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 432d703

Please sign in to comment.