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 and fagianijunior committed Feb 12, 2025
2 parents 4e16ecf + dae268a commit 3521b03
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 21 deletions.
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ RUN set -ex \

FROM tools AS runtimes

#Docker 19
#Docker 27
ENV DOCKER_BUCKET="download.docker.com" \
DOCKER_CHANNEL="stable" \
DIND_COMMIT="3b5fac462d21ca164b3778647420016315289034" \
DOCKER_COMPOSE_VERSION="1.26.0"
DOCKER_COMPOSE_VERSION="2.32.4"

ENV DOCKER_SHA256="0f4336378f61ed73ed55a356ac19e46699a995f2aff34323ba5874d131548b9e"
ENV DOCKER_VERSION="19.03.11"
ENV DOCKER_SHA256="4f798b3ee1e0140eab5bf30b0edc4e84f4cdb53255a429dc3bbae9524845d640"
ENV DOCKER_VERSION="27.5.1"

VOLUME /var/lib/docker

Expand All @@ -98,8 +98,8 @@ RUN set -ex \
&& useradd -g dockremap dockremap \
&& echo 'dockremap:165536:65536' >> /etc/subuid \
&& echo 'dockremap:165536:65536' >> /etc/subgid \
&& wget -nv "https://raw.githubusercontent.com/docker/docker/${DIND_COMMIT}/hack/dind" -O /usr/local/bin/dind \
&& curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-Linux-x86_64 > /usr/local/bin/docker-compose \
&& wget -nv "https://raw.githubusercontent.com/rollbar/docker/refs/heads/master/hack/dind" -O /usr/local/bin/dind \
&& curl -L https://github.com/docker/compose/releases/download/v${DOCKER_COMPOSE_VERSION}/docker-compose-Linux-x86_64 > /usr/local/bin/docker-compose \
&& chmod +x /usr/local/bin/dind /usr/local/bin/docker-compose \
&& docker-compose version

Expand Down
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

set -eo pipefail

if [ -z "$MAESTRO_DEBUG" ]; then
set -x
fi

VALID_ARGS=$(getopt -o i: --long image-name: -n 'build.sh' -- "$@")
if [[ $? -ne 0 ]]; then
exit 1;
Expand Down
3 changes: 3 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash

set -eo pipefail
if [ -z "$MAESTRO_DEBUG" ]; then
set -x
fi

VALID_ARGS=$(getopt -o a:ci:p:r:s: --long account-id:,create-service,cluster-id:,process-type:,repository-slug:,service-name: -n 'deploy.sh' -- "$@")
if [[ $? -ne 0 ]]; then
Expand Down
30 changes: 15 additions & 15 deletions main.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#!/bin/bash

set -eo pipefail

if [ ! -z "$MAESTRO_DEBUG" ]; then
set -x
fi

# if folder does not exist create it
if [ ! -d "/sys/fs/cgroup/systemd" ]; then
mkdir -p /sys/fs/cgroup/systemd
ls -la /sys/fs/cgroup/systemd
fi

if [ ! -z "$MAESTRO_REPO_OVERRIDE" ]; then
REPO_SLUG=$MAESTRO_REPO_OVERRIDE
fi
Expand Down Expand Up @@ -53,21 +62,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
4 changes: 4 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

set -eo pipefail

if [ -z "$MAESTRO_DEBUG" ]; then
set -x
fi

VALID_ARGS=$(getopt -o b:i:l:p:r: --long branch-name:,cluster-id:,image-name:,process-type:,repository-slug: -n 'release.sh' -- "$@")
if [[ $? -ne 0 ]]; then
exit 1;
Expand Down
3 changes: 3 additions & 0 deletions render.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash

set -eo pipefail
if [ -z "$MAESTRO_DEBUG" ]; then
set -x
fi

VALID_ARGS=$(getopt -o ac:e:f:i:n:p:st:u --long app-spec,use-secrets,container-name:,environment-variables:,family-name:,process-type:,image:,task-definition:,aws-sm-name:,aws-sm-arns -n 'render.sh' -- "$@")
if [[ $? -ne 0 ]]; then
Expand Down

0 comments on commit 3521b03

Please sign in to comment.