Skip to content

Commit

Permalink
feat: introduce warning system
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Nov 3, 2023
1 parent 6bd767a commit c7e6a67
Showing 1 changed file with 65 additions and 11 deletions.
76 changes: 65 additions & 11 deletions legacy/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# set it to something usable here
LAGOON_BUILD_NAME=$HOSTNAME

BUILD_WARNING_COUNT=0

function cronScheduleMoreOftenThan30Minutes() {
#takes a unexpanded cron schedule, returns 0 if it's more often that 30 minutes
MINUTE=$(echo $1 | (read -a ARRAY; echo ${ARRAY[0]}) )
Expand Down Expand Up @@ -198,17 +200,19 @@ if kubectl -n ${NAMESPACE} get configmap docker-compose-yaml &> /dev/null; then
fi

set +ex
currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")"
patchBuildStep "${buildStartTime}" "${buildStartTime}" "${currentStepEnd}" "${NAMESPACE}" "initialSetup" "Initial Environment Setup"
previousStepEnd=${currentStepEnd}
beginBuildStep "Docker Compose Validation" "dockerComposeValidation"
##############################################
### RUN docker compose config check against the provided docker-compose file
### use the `build-validate` built in validater to run over the provided docker-compose file
##############################################
dccOutput=$(bash -c 'build-deploy-tool validate docker-compose --docker-compose '${DOCKER_COMPOSE_YAML}'; exit $?' 2>&1)
dccExit=$?
echo "docker-compose validate exit code ${dccExit}: ${dccOutput}"

if [ "${dccExit}" != "0" ]; then
currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")"
patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "dockerComposeValidationError" "Docker Compose Validation Error"
patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "dockerComposeValidationError" "Docker Compose Validation"
previousStepEnd=${currentStepEnd}
echo "
##############################################
Expand All @@ -222,9 +226,32 @@ You can run docker compose config locally to check that your docker-compose file
##############################################"
exit 1
fi
set -ex

set +ex
## validate the docker-compose in a way to eventually phase out forked library by displaying warnings
dccOutput=$(bash -c 'build-deploy-tool validate docker-compose --ignore-non-string-key-errors=false --ignore-missing-env-files=false --docker-compose '${DOCKER_COMPOSE_YAML}'; exit $?' 2>&1)
dccExit=$?
if [ "${dccExit}" != "0" ]; then
((++BUILD_WARNING_COUNT))
currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")"
patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "dockerComposeValidationWarning" "Docker Compose Validation"
previousStepEnd=${currentStepEnd}
echo "
##############################################
Warning!
There are issues with your docker compose file that lagoon uses that should be fixed.
You can run docker compose config locally to check that your docker-compose file is valid.
##############################################
"
echo ${dccOutput}
echo "
##############################################"
else
currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")"
patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "dockerComposeValidation" "Docker Compose Validation"
previousStepEnd=${currentStepEnd}
fi

beginBuildStep ".lagoon.yml Validation" "lagoonYmlValidation"
##############################################
### RUN lagoon-yml validation against the final data which may have overrides
### from .lagoon.override.yml file or LAGOON_YAML_OVERRIDE environment variable
Expand All @@ -234,7 +261,7 @@ lyvExit=$?

if [ "${lyvExit}" != "0" ]; then
currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")"
patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "lagoonYmlValidationError" ".lagoon.yml Validation Error"
patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "lagoonYmlValidationError" ".lagoon.yml Validation"
previousStepEnd=${currentStepEnd}
echo "
##############################################
Expand Down Expand Up @@ -263,7 +290,7 @@ fi

set +x
currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")"
patchBuildStep "${buildStartTime}" "${buildStartTime}" "${currentStepEnd}" "${NAMESPACE}" "initialSetup" "Initial Environment Setup"
patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "lagoonYmlValidation" ".lagoon.yml Validation"
previousStepEnd=${currentStepEnd}
beginBuildStep "Configure Variables" "configuringVariables"
set -x
Expand Down Expand Up @@ -1778,8 +1805,21 @@ set -x

set +x
currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")"
patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "deployCompleted" "Build and Deploy"
previousStepEnd=${currentStepEnd}
if [[ "$BUILD_WARNING_COUNT" -gt 0 ]]; then
echo "This build completed with ${BUILD_WARNING_COUNT} warnings, you should scan the build for warnings and correct them as neccessary"
patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "deployCompletedWithWarnings" "Build and Deploy"
previousStepEnd=${currentStepEnd}
# 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\":\"deployCompletedWithWarnings\"}}}" &> /dev/null
# tiny sleep to allow patch to complete before logs roll again
sleep 5
fi
else
patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "deployCompleted" "Build and Deploy"
previousStepEnd=${currentStepEnd}
fi
set -x

set +x
Expand All @@ -1798,7 +1838,21 @@ if [ "$(featureFlag INSIGHTS)" = enabled ]; then
done

currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")"
patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "insightsCompleted" "Insights Gathering"
previousStepEnd=${currentStepEnd}

if [[ "$BUILD_WARNING_COUNT" -gt 0 ]]; then
echo "This build completed with ${BUILD_WARNING_COUNT} warnings, you should scan the build for warnings and correct them as neccessary"
patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "insightsCompletedWithWarnings" "Insights Gathering"
previousStepEnd=${currentStepEnd}
# 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\":\"deployCompletedWithWarnings\"}}}" &> /dev/null
# tiny sleep to allow patch to complete before logs roll again
sleep 5
fi
else
patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "insightsCompleted" "Insights Gathering"
previousStepEnd=${currentStepEnd}
fi
fi
set -x

0 comments on commit c7e6a67

Please sign in to comment.