Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Dockerfile support to maestro workflow #68

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Variable | Description | Examples/Values | Default
`DEPLOYMENT_CIRCUIT_BREAKER_RULE` | Enable or disable circuit breaker | `enable=true,rollback=true`
`ECS_CONTAINER_STOP_TIMEOUT` | Set stopTimeout on taskdefinition | min: 0, max: 120, default: 30
`TZ`| Set this variable to the desired task timezone | America/Sao_Paulo
`WORKLOAD_PATH`| Set the workload path to run build commands on should do it | ./Projects/my-app, ./

### How to enable scheduled tasks
- Create a file tasks/run_tasks.conf with the schedules on your code:
Expand Down
34 changes: 27 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,19 @@ fi

if [ $(DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect $build_image_name 2> /dev/null ; echo $?) -eq 0 ]; then
echo "----> Skipping build as image already exists"
else
exit 0
fi

if [ -z "$WORKLOAD_PATH" ]; then
$WORKLOAD_PATH=.
Comment on lines +34 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fagiani here $WORKLOAD_PATH receive the "." as value if it's empty, thinking about this with @fagianijunior we think wich is unnecessary utilize bash parameter expansion to change the value to "." again.

fi

if [ -f "${WORKLOAD_PATH}/project.toml" ]; then
build_builder_name=`grep builder project.toml | cut -d= -f2 | tr -d '" '`
build_builder_tag=`echo $build_builder_name | tr /: -`
docker pull ${build_image_name%:*}:$build_builder_tag 2> /dev/null || true
docker tag ${build_image_name%:*}:$build_builder_tag $build_builder_name 2> /dev/null || true
build_assume_role=$(curl -s http://169.254.170.2$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI)
build_assume_role=$(curl -s http://169.254.170.2$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI)
echo "AWS_ACCESS_KEY_ID=$(jq -r '.AccessKeyId' <<<$build_assume_role)" >> .env
echo "AWS_SECRET_ACCESS_KEY=$(jq -r '.SecretAccessKey' <<<$build_assume_role)" >> .env
echo "AWS_SESSION_TOKEN=$(jq -r '.Token' <<<$build_assume_role)" >> .env
Expand All @@ -42,9 +49,22 @@ else
--env-file .env \
--publish \
--trust-builder \
$( [[ -z $MAESTRO_NO_CACHE || $MAESTRO_NO_CACHE = "false" ]] && echo "--pull-policy if-not-present --cache-image ${build_image_name%:*}:cache") \
$( [ $MAESTRO_NO_CACHE = "true" ] && echo "--pull-policy always --clear-cache --env USE_YARN_CACHE=false --env NODE_MODULES_CACHE=false") \
$( [ $MAESTRO_DEBUG = "true" ] && echo "--env NPM_CONFIG_LOGLEVEL=debug --env NODE_VERBOSE=true --verbose")
docker tag $build_builder_name ${build_image_name%:*}:$build_builder_tag
docker push ${build_image_name%:*}:$build_builder_tag 2> /dev/null
--path ${WORKLOAD_PATH}
$( [[ -z $MAESTRO_NO_CACHE || $MAESTRO_NO_CACHE = "false" ]] && echo "--pull-policy if-not-present --cache-image ${build_image_name%:*}:cache") \
$( [ $MAESTRO_NO_CACHE = "true" ] && echo "--pull-policy always --clear-cache --env USE_YARN_CACHE=false --env NODE_MODULES_CACHE=false") \
$( [ $MAESTRO_DEBUG = "true" ] && echo "--env NPM_CONFIG_LOGLEVEL=debug --env NODE_VERBOSE=true --verbose")
build_built=true
fi

if [ -z "$build_built" && -f "${WORKLOAD_PATH}/Dockerfile" ]; then
docker build -t ${build_image_name%:*}:latest -t $build_image_name ${WORKLOAD_PATH}
build_built=true
fi

if [ -z "$build_built" ]; then
echo "Error: Expected either a Dockerfile or a project.toml within the project's root path"
exit 1
fi

docker tag $build_builder_name ${build_image_name%:*}:$build_builder_tag
docker push ${build_image_name%:*}:$build_builder_tag 2> /dev/null