Skip to content

Commit

Permalink
feat: flags to disable build sections (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Clifford authored Feb 1, 2023
1 parent b5c8103 commit fee988f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 9 deletions.
78 changes: 72 additions & 6 deletions legacy/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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=()

Expand All @@ -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 \
Expand Down Expand Up @@ -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}}')
Expand Down Expand Up @@ -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)" ]
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions legacy/scripts/exec-backup-generation.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash

set +x
##############################################
# it is possible to override the retention using a variable defined in the api
#
Expand Down Expand Up @@ -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

0 comments on commit fee988f

Please sign in to comment.