Skip to content

Commit

Permalink
Merge pull request #81 from veezor/fix-env
Browse files Browse the repository at this point in the history
Fix .env generation with multiline, like private key
  • Loading branch information
MatheusdeMelo authored Apr 2, 2024
2 parents 4e16ecf + dae268a commit af2797e
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions main.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash

set -eo pipefail

if [ ! -z "$MAESTRO_REPO_OVERRIDE" ]; then
Expand Down Expand Up @@ -53,21 +52,12 @@ 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)

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
while IFS= read -r ENV_LINE; do
export "$ENV_LINE"
echo "$ENV_LINE" >> .env
done <<< "$main_application_environment_variables"

if [ -z "$MAESTRO_SKIP_BUILD" ]; then
build.sh --image-name $IMAGE_NAME
Expand Down

0 comments on commit af2797e

Please sign in to comment.