From d36b0e295cbb736bfafd211a6f05826ed4576984 Mon Sep 17 00:00:00 2001 From: Paulo Fagiani Date: Fri, 14 Apr 2023 13:44:30 -0300 Subject: [PATCH 1/8] Introduce Dockerfile support to maestro workflow --- build.sh | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/build.sh b/build.sh index 71ea619..ddc4e83 100755 --- a/build.sh +++ b/build.sh @@ -28,12 +28,20 @@ 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 [ -f Dockerfile ]; then + docker build -t ${build_image_name%:*}:latest -t $build_image_name . + build_built=true +fi + +if [ -f 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 @@ -42,9 +50,16 @@ 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 + $( [[ -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" ]; 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 From 72552e235883460e72a8ebb243f65852cd193f8a Mon Sep 17 00:00:00 2001 From: Matheus Ferreira Date: Fri, 14 Apr 2023 20:08:19 +0000 Subject: [PATCH 2/8] Add path and build-mode env variables --- build.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index ddc4e83..ded8ec7 100755 --- a/build.sh +++ b/build.sh @@ -31,12 +31,14 @@ if [ $(DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect $build_image_name exit 0 fi -if [ -f Dockerfile ]; then +if [ ! -z $MAESTRO_BUILD_FOLDER ]; then + cd $MAESTRO_BUILD_FOLDER +fi + +if [ $MAESTRO_BUILD_MODE == Dockerfile ]; then docker build -t ${build_image_name%:*}:latest -t $build_image_name . build_built=true -fi - -if [ -f project.toml ]; then +elif [ $MAESTRO_BUILD_FOLDER == 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 From 1181d51387b1b56449165d0308ab81c56d284578 Mon Sep 17 00:00:00 2001 From: Matheus Ferreira Date: Mon, 17 Apr 2023 17:05:01 +0000 Subject: [PATCH 3/8] Fix variables names and workload paths --- build.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/build.sh b/build.sh index ded8ec7..f912508 100755 --- a/build.sh +++ b/build.sh @@ -31,14 +31,10 @@ if [ $(DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect $build_image_name exit 0 fi -if [ ! -z $MAESTRO_BUILD_FOLDER ]; then - cd $MAESTRO_BUILD_FOLDER -fi - if [ $MAESTRO_BUILD_MODE == Dockerfile ]; then - docker build -t ${build_image_name%:*}:latest -t $build_image_name . + docker build -t ${build_image_name%:*}:latest -t $build_image_name $WORKLOAD_PATH build_built=true -elif [ $MAESTRO_BUILD_FOLDER == project.toml ]; then +elif [ $MAESTRO_BUILD_MODE == 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 From bf00391d5d08840023de1c805ae4351e0c5d44e7 Mon Sep 17 00:00:00 2001 From: Matheus Ferreira Date: Mon, 17 Apr 2023 17:45:13 +0000 Subject: [PATCH 4/8] Change build checks --- build.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index f912508..ac68e1e 100755 --- a/build.sh +++ b/build.sh @@ -31,10 +31,12 @@ if [ $(DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect $build_image_name exit 0 fi -if [ $MAESTRO_BUILD_MODE == Dockerfile ]; then +if [ ! -z $MAESTRO_DOCKER_BUILD ]; then docker build -t ${build_image_name%:*}:latest -t $build_image_name $WORKLOAD_PATH build_built=true -elif [ $MAESTRO_BUILD_MODE == project.toml ]; then +fi + +if [ -f project.toml && $build_built != true ]; 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 From 09a70cd26efcb83778a326bc558ec554208b4432 Mon Sep 17 00:00:00 2001 From: Paulo Fagiani Date: Mon, 17 Apr 2023 16:01:53 -0300 Subject: [PATCH 5/8] Improve workload path workflow --- build.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index ac68e1e..c108d89 100755 --- a/build.sh +++ b/build.sh @@ -31,12 +31,11 @@ if [ $(DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect $build_image_name exit 0 fi -if [ ! -z $MAESTRO_DOCKER_BUILD ]; then - docker build -t ${build_image_name%:*}:latest -t $build_image_name $WORKLOAD_PATH - build_built=true +if [ -z "$WORKLOAD_PATH" ]; then + $WORKLOAD_PATH=. fi -if [ -f project.toml && $build_built != true ]; then +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 @@ -50,12 +49,18 @@ if [ -f project.toml && $build_built != true ]; then --env-file .env \ --publish \ --trust-builder \ + --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 From 4b4b31f52707f90da43bda864cc757c9f3e9c8fc Mon Sep 17 00:00:00 2001 From: Matheus Ferreira <80073655+MatheusdeMelo@users.noreply.github.com> Date: Mon, 17 Apr 2023 17:39:32 -0300 Subject: [PATCH 6/8] Add workload_path variable --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b468b69..424079a 100644 --- a/README.md +++ b/README.md @@ -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 correct directory| ./Projects/my-app, ./ ### How to enable scheduled tasks - Create a file tasks/run_tasks.conf with the schedules on your code: From 2eaa3b3f9065ba598c4041280055338ace50f63c Mon Sep 17 00:00:00 2001 From: Matheus Ferreira Date: Tue, 18 Apr 2023 17:19:14 +0000 Subject: [PATCH 7/8] Fix variable check --- build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index c108d89..4016869 100755 --- a/build.sh +++ b/build.sh @@ -49,7 +49,7 @@ if [ -f "${WORKLOAD_PATH}/project.toml" ]; then --env-file .env \ --publish \ --trust-builder \ - --path ${WORKLOAD_PATH:-.} + --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") @@ -57,7 +57,7 @@ if [ -f "${WORKLOAD_PATH}/project.toml" ]; then fi if [ -z "$build_built" && -f "${WORKLOAD_PATH}/Dockerfile" ]; then - docker build -t ${build_image_name%:*}:latest -t $build_image_name ${WORKLOAD_PATH:-.} + docker build -t ${build_image_name%:*}:latest -t $build_image_name ${WORKLOAD_PATH} build_built=true fi From 33a2a8cae13c22361b469c7fdb798752c877aaae Mon Sep 17 00:00:00 2001 From: Matheus Ferreira Date: Tue, 30 May 2023 18:53:28 +0000 Subject: [PATCH 8/8] Fix variable description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 424079a..88853ed 100644 --- a/README.md +++ b/README.md @@ -79,7 +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 correct directory| ./Projects/my-app, ./ + `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: