From b3b1be736ff1bda8de588b111bd41e981a7b6384 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 26 Jul 2024 15:20:43 +1000 Subject: [PATCH 1/2] feat: implement feature to start failing builds on docker-compose yaml errors --- legacy/build-deploy-docker-compose.sh | 37 ++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index 4e0abc52..ba73c5ab 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -255,11 +255,36 @@ dccExit2=$? if [ "${dccExit2}" != "0" ]; then ((++DOCKER_COMPOSE_WARNING_COUNT)) if [ "${dccExit}" == "0" ]; then + + # this logic is to phase rollout of https://github.com/uselagoon/build-deploy-tool/pull/304 + # anything returned by this section will be a yaml error that we need to check if the feature to enable/disable errors + # is configured, and that the environment type matches. + # eventually this logic will be changed entirely from warnings to errors + DOCKER_COMPOSE_VALIDATION_ERROR=false + # this logic will make development environments return an error by default + # adding LAGOON_FEATURE_FLAG_DEVELOPMENT_DOCKER_COMPOSE_VALIDATION=disabled can be used to disable the error and revert to a warning per project or environment + # or add LAGOON_FEATURE_FLAG_DEFAULT_DEVELOPMENT_DOCKER_COMPOSE_VALIDATION=disabled to the remote-controller as a default to disable for a cluster + if [[ "$(featureFlag DEVELOPMENT_DOCKER_COMPOSE_VALIDATION)" != disabled ]] && [[ "$ENVIRONMENT_TYPE" == "development" ]]; then + DOCKER_COMPOSE_VALIDATION_ERROR=true + fi + # by default, production environments won't return an error unless the feature flag is enabled. + # this allows using the feature flag to selectively apply to production environments if required + # adding LAGOON_FEATURE_FLAG_PRODUCTION_DOCKER_COMPOSE_VALIDATION=enabled can be used to enable the error per project or environment + # or add LAGOON_FEATURE_FLAG_DEFAULT_PRODUCTION_DOCKER_COMPOSE_VALIDATION=enabled to the remote-controller as a default to disable for a cluster + if [[ "$(featureFlag PRODUCTION_DOCKER_COMPOSE_VALIDATION)" = enabled ]] && [[ "$ENVIRONMENT_TYPE" == "production" ]]; then + DOCKER_COMPOSE_VALIDATION_ERROR=true + fi + ((++BUILD_WARNING_COUNT)) echo " -############################################## -Warning! -There are issues with your docker compose file that lagoon uses that should be fixed. +##############################################" + if [[ "$DOCKER_COMPOSE_VALIDATION_ERROR" == "true" ]]; then + echo "Error!" + else + echo "Warning!" + fi + + echo "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. " fi @@ -281,6 +306,12 @@ else previousStepEnd=${currentStepEnd} fi + +if [[ "$DOCKER_COMPOSE_VALIDATION_ERROR" == "true" ]]; then + # drop the exit here if this should be an error + exit 1 +fi + beginBuildStep ".lagoon.yml Validation" "lagoonYmlValidation" ############################################## ### RUN lagoon-yml validation against the final data which may have overrides From 036fd3cbca22a4ad27b532bf87b1e62ee64519c0 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Tue, 22 Oct 2024 09:33:34 +1100 Subject: [PATCH 2/2] feat: implement feature to start failing builds on docker-compose yaml errors --- legacy/build-deploy-docker-compose.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index ba73c5ab..9a3f510b 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -261,6 +261,7 @@ if [ "${dccExit2}" != "0" ]; then # is configured, and that the environment type matches. # eventually this logic will be changed entirely from warnings to errors DOCKER_COMPOSE_VALIDATION_ERROR=false + DOCKER_COMPOSE_VALIDATION_ERROR_VARIABLE=LAGOON_FEATURE_FLAG_DEVELOPMENT_DOCKER_COMPOSE_VALIDATION # this logic will make development environments return an error by default # adding LAGOON_FEATURE_FLAG_DEVELOPMENT_DOCKER_COMPOSE_VALIDATION=disabled can be used to disable the error and revert to a warning per project or environment # or add LAGOON_FEATURE_FLAG_DEFAULT_DEVELOPMENT_DOCKER_COMPOSE_VALIDATION=disabled to the remote-controller as a default to disable for a cluster @@ -273,6 +274,7 @@ if [ "${dccExit2}" != "0" ]; then # or add LAGOON_FEATURE_FLAG_DEFAULT_PRODUCTION_DOCKER_COMPOSE_VALIDATION=enabled to the remote-controller as a default to disable for a cluster if [[ "$(featureFlag PRODUCTION_DOCKER_COMPOSE_VALIDATION)" = enabled ]] && [[ "$ENVIRONMENT_TYPE" == "production" ]]; then DOCKER_COMPOSE_VALIDATION_ERROR=true + DOCKER_COMPOSE_VALIDATION_ERROR_VARIABLE=LAGOON_FEATURE_FLAG_PRODUCTION_DOCKER_COMPOSE_VALIDATION fi ((++BUILD_WARNING_COUNT)) @@ -309,6 +311,10 @@ fi if [[ "$DOCKER_COMPOSE_VALIDATION_ERROR" == "true" ]]; then # drop the exit here if this should be an error + echo "> You can instruct Lagoon to change this to a warning by setting the following variable" + echo "> '${DOCKER_COMPOSE_VALIDATION_ERROR_VARIABLE}=disabled' as a GLOBAL scoped variable to this environment or project." + echo "> A future release of Lagoon will not be able to change this error." + echo "> You should correct the issue as soon as possible to prevent future build failures." exit 1 fi