From ac822f8d759548ef4f7580b2fddf7043e2bd4492 Mon Sep 17 00:00:00 2001 From: Carlos Fagiani Junior Date: Tue, 2 Apr 2024 02:39:32 +0000 Subject: [PATCH 1/2] Fix .env generation with multiline, like private key --- main.sh | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/main.sh b/main.sh index 5e01b44..1b21ecd 100755 --- a/main.sh +++ b/main.sh @@ -53,17 +53,13 @@ COMMIT_SHORT=$(head -c 8 <<<$CODEBUILD_RESOLVED_SOURCE_VERSION) IMAGE_NAME=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REPO_SLUG-$BRANCH:$COMMIT_SHORT main_application_secrets=$(aws secretsmanager get-secret-value --secret-id $BRANCH/$REPO_SLUG) -main_application_environment_variables=$(jq -r '.SecretString | fromjson | to_entries | .[] | .key + "=" + (.value|tostring)' <<<$main_application_secrets) -main_export_regex="^([A-Z0-9_])+[=]+(.*)" -for ENV_LINE in $main_application_environment_variables; do - if [[ $ENV_LINE =~ ${main_export_regex} ]]; then - export $ENV_LINE - echo $ENV_LINE >> .env - else - echo " SKIPPED: >> ${ENV_LINE}" - main_export_errors=true - fi -done +main_application_environment_variables=$(jq -r '.SecretString | fromjson | to_entries[] | "\(.key)=\(.value|tostring)"' <<<$main_application_secrets) + +while IFS= read -r ENV_LINE; do + export "$ENV_LINE" + echo "$ENV_LINE" >> .env +done <<< "$main_application_environment_variables" + if [ ! -z "$main_export_errors" ]; then echo " WARNING: The above noted environment variables were skipped from the export, as they were not identified as a valid value or by a flag." From dae268ac1d70b662b6cb77c6487fe7e8ee652d45 Mon Sep 17 00:00:00 2001 From: Carlos Fagiani Junior Date: Tue, 2 Apr 2024 13:14:34 +0000 Subject: [PATCH 2/2] Remove warning --- main.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/main.sh b/main.sh index 1b21ecd..f341365 100755 --- a/main.sh +++ b/main.sh @@ -1,5 +1,4 @@ #!/bin/bash - set -eo pipefail if [ ! -z "$MAESTRO_REPO_OVERRIDE" ]; then @@ -60,11 +59,6 @@ while IFS= read -r ENV_LINE; do echo "$ENV_LINE" >> .env done <<< "$main_application_environment_variables" - -if [ ! -z "$main_export_errors" ]; then - echo " WARNING: The above noted environment variables were skipped from the export, as they were not identified as a valid value or by a flag." -fi - if [ -z "$MAESTRO_SKIP_BUILD" ]; then build.sh --image-name $IMAGE_NAME if [ ! -z "$MAESTRO_ONLY_BUILD" ]; then