From fee988f6e5197b2fdc72afe366a9210ed9d89100 Mon Sep 17 00:00:00 2001 From: Tim Clifford Date: Wed, 1 Feb 2023 23:08:16 +0000 Subject: [PATCH] feat: flags to disable build sections (#169) --- legacy/build-deploy-docker-compose.sh | 78 ++++++++++++++++++++++-- legacy/scripts/exec-backup-generation.sh | 3 - 2 files changed, 72 insertions(+), 9 deletions(-) diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index 0d5e82f4..b31afc7a 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -1020,8 +1020,24 @@ set -x ############################################## ### CREATE SERVICES, AUTOGENERATED ROUTES AND DBAAS CONFIG ############################################## +# start custom routes disabled +AUTOGEN_ROUTES_DISABLED=false +if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then + AUTOGEN_ROUTES_DISABLED=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.scope == "build") | select(.name == "LAGOON_AUTOGEN_ROUTES_DISABLED") | "\(.value)"')) +fi +if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then + TEMP_AUTOGEN_ROUTES_DISABLED=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.scope == "build") | select(.name == "LAGOON_AUTOGEN_ROUTES_DISABLED") | "\(.value)"')) + if [ ! -z $TEMP_AUTOGEN_ROUTES_DISABLED ]; then + AUTOGEN_ROUTES_DISABLED=$TEMP_AUTOGEN_ROUTES_DISABLED + fi +fi +if [ ! "$AUTOGEN_ROUTES_DISABLED" == true ]; then build-deploy-tool template autogenerated-ingress +else + echo ">> Autogenerated ingress templates disabled for this build" +# end custom route +fi for SERVICE_TYPES_ENTRY in "${SERVICE_TYPES[@]}" do @@ -1056,7 +1072,6 @@ currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "serviceConfiguration2Complete" "Service Configuration Phase 2" previousStepEnd=${currentStepEnd} beginBuildStep "Route/Ingress Configuration" -set -x TEMPLATE_PARAMETERS=() @@ -1065,21 +1080,50 @@ TEMPLATE_PARAMETERS=() ############################################## # Run the route generation process + +# start custom routes disabled +CUSTOM_ROUTES_DISABLED=false +if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then + CUSTOM_ROUTES_DISABLED=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.scope == "build") | select(.name == "LAGOON_CUSTOM_ROUTES_DISABLED") | "\(.value)"')) +fi +if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then + TEMP_CUSTOM_ROUTES_DISABLED=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.scope == "build") | select(.name == "LAGOON_CUSTOM_ROUTES_DISABLED") | "\(.value)"')) + if [ ! -z $TEMP_CUSTOM_ROUTES_DISABLED ]; then + CUSTOM_ROUTES_DISABLED=$TEMP_CUSTOM_ROUTES_DISABLED + fi +fi + +if [ ! "$CUSTOM_ROUTES_DISABLED" == true ]; then build-deploy-tool template ingress +else + echo ">> Custom ingress templates disabled for this build" +# end custom route +fi -set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "routeConfigurationComplete" "Route/Ingress Configuration" previousStepEnd=${currentStepEnd} beginBuildStep "Backup Configuration" -set -x - # Run the backup generation script -. /kubectl-build-deploy/scripts/exec-backup-generation.sh +BACKUPS_DISABLED=false +if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then + BACKUPS_DISABLED=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.scope == "build") | select(.name == "LAGOON_BACKUPS_DISABLED") | "\(.value)"')) +fi +if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then + TEMP_BACKUPS_DISABLED=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.scope == "build") | select(.name == "LAGOON_BACKUPS_DISABLED") | "\(.value)"')) + if [ ! -z $TEMP_BACKUPS_DISABLED ]; then + BACKUPS_DISABLED=$TEMP_BACKUPS_DISABLED + fi +fi + +if [ ! "$BACKUPS_DISABLED" == true ]; then + . /kubectl-build-deploy/scripts/exec-backup-generation.sh +else + echo ">> Backup configurations disabled for this build" +fi # check for ISOLATION_NETWORK_POLICY feature flag, disabled by default -set +x if [ "$(featureFlag ISOLATION_NETWORK_POLICY)" = enabled ]; then # add namespace isolation network policy to deployment helm template isolation-network-policy /kubectl-build-deploy/helmcharts/isolation-network-policy \ @@ -1113,6 +1157,10 @@ ROUTE=$(build-deploy-tool identify primary-ingress) if [ ! -z "${ROUTE}" ]; then ROUTE=${ROUTE} fi +# if both route generations are disabled, don't set a route +if [[ "$CUSTOM_ROUTES_DISABLED" == true ]] && [[ "$AUTOGEN_ROUTES_DISABLED" == true ]]; then + ROUTE="" +fi # Load all routes with correct schema and comma separated ROUTES=$(kubectl -n ${NAMESPACE} get ingress --sort-by='{.metadata.name}' -l "acme.openshift.io/exposer!=true" -o=go-template --template='{{range $indexItems, $ingress := .items}}{{if $indexItems}},{{end}}{{$tls := .spec.tls}}{{range $indexRule, $rule := .spec.rules}}{{if $indexRule}},{{end}}{{if $tls}}https://{{else}}http://{{end}}{{.host}}{{end}}{{end}}') @@ -1373,6 +1421,19 @@ do # TEMPLATE_PARAMETERS+=(-p DEPLOYMENT_STRATEGY="${DEPLOYMENT_STRATEGY}") # fi + # start cronjob disabled + CRONJOBS_DISABLED=false + if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then + CRONJOBS_DISABLED=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.scope == "build") | select(.name == "LAGOON_CRONJOBS_DISABLED") | "\(.value)"')) + fi + if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then + TEMP_CRONJOBS_DISABLED=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.scope == "build") | select(.name == "LAGOON_CRONJOBS_DISABLED") | "\(.value)"')) + if [ ! -z $TEMP_CRONJOBS_DISABLED ]; then + CRONJOBS_DISABLED=$TEMP_CRONJOBS_DISABLED + fi + fi + + if [ ! "$CRONJOBS_DISABLED" == true ]; then CRONJOB_COUNTER=0 CRONJOBS_ARRAY_INSIDE_POD=() #crons run inside an existing pod more frequently than every 15 minutes while [ -n "$(cat .lagoon.yml | shyaml keys environments.${BRANCH//./\\.}.cronjobs.$CRONJOB_COUNTER 2> /dev/null)" ] @@ -1423,6 +1484,11 @@ do yq3 write -i --tag '!!str' -- /kubectl-build-deploy/${SERVICE_NAME}-values.yaml 'inPodCronjobs' '' fi + else + echo ">> Cronjob configurations disabled for this build" + fi + # end cronjob disabled + . /kubectl-build-deploy/scripts/exec-kubectl-resources-with-images.sh done diff --git a/legacy/scripts/exec-backup-generation.sh b/legacy/scripts/exec-backup-generation.sh index c4ebfe49..a5726738 100755 --- a/legacy/scripts/exec-backup-generation.sh +++ b/legacy/scripts/exec-backup-generation.sh @@ -1,6 +1,5 @@ #!/bin/bash -set +x ############################################## # it is possible to override the retention using a variable defined in the api # @@ -326,5 +325,3 @@ if [[ "${CAPABILITIES[@]}" =~ "backup.appuio.ch/v1alpha1/Schedule" ]]; then --set customBackupLocation.accessKey="${BAAS_CUSTOM_BACKUP_ACCESS_KEY}" \ --set customBackupLocation.secretKey="${BAAS_CUSTOM_BACKUP_SECRET_KEY}" "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/k8up-lagoon-backup-schedule.yaml fi - -set -x \ No newline at end of file