Skip to content

Commit

Permalink
feat: implement feature to start failing builds on docker-compose yam…
Browse files Browse the repository at this point in the history
…l errors
  • Loading branch information
shreddedbacon committed Aug 21, 2024
1 parent 2ed9ebd commit 103d8c7
Showing 1 changed file with 50 additions and 4 deletions.
54 changes: 50 additions & 4 deletions legacy/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,53 @@ 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.
You can run docker compose config locally to check that your docker-compose file is valid.
##############################################"
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 the command 'docker compose config' locally to check that your docker-compose file is valid.
"
if [[ "$DOCKER_COMPOSE_VALIDATION_ERROR" == "true" ]]; then
# if the error is set, outline how the error can be temporarily ignored by the user
echo ""
echo "This error can temporarily be disabled using the following environment variable defined in the project or environment with the 'GLOBAL' scope."
if [[ "$ENVIRONMENT_TYPE" == "development" ]]; then
echo " LAGOON_FEATURE_FLAG_DEVELOPMENT_DOCKER_COMPOSE_VALIDATION=disabled"
fi
if [[ "$ENVIRONMENT_TYPE" == "production" ]]; then
echo " LAGOON_FEATURE_FLAG_PRODUCTION_DOCKER_COMPOSE_VALIDATION=disabled"
fi
# make sure that the error is clear that the docker-compose file needs to be fixed ASAP
echo "Disabling this error should be seen as a temporary measure."
echo "In a future Lagoon release it will not be possible to ignore this error."
echo "You should address the error in your docker compose file as soon as possible to prevent issues in the future."
fi
fi
echo "> There are yaml validation errors in your docker-compose file that should be corrected."
echo ERR: ${dccOutput}
Expand All @@ -282,6 +322,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
Expand Down

0 comments on commit 103d8c7

Please sign in to comment.