From d6850f056c5d88a36eaab3624062e594260dc77b Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Sat, 16 May 2020 22:59:05 -0400 Subject: [PATCH] Substitutes environment variables in multiple files --- Dockerfile | 7 ++----- docker/substitute-env-variables.sh | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) mode change 100644 => 100755 docker/substitute-env-variables.sh diff --git a/Dockerfile b/Dockerfile index 77fd5d0..0781b10 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,11 +22,8 @@ COPY --from=builder /crc-bpmn/nginx.conf /etc/nginx/conf.d/default.conf COPY ./docker/substitute-env-variables.sh ./entrypoint.sh RUN chmod +x ./entrypoint.sh -# Substitute environment variables in nginx configuration -CMD ["./entrypoint.sh", "/etc/nginx/conf.d/default.conf"] - -# Substitute environment variables in index.html -ENTRYPOINT ["./entrypoint.sh", "/usr/share/nginx/html/index.html"] +# Substitute environment variables in nginx configuration and index.html +ENTRYPOINT ["./entrypoint.sh", "/usr/share/nginx/html/index.html,/etc/nginx/conf.d/default.conf"] ### STAGE 3: Profit! ### CMD ["nginx", "-g", "daemon off;"] diff --git a/docker/substitute-env-variables.sh b/docker/substitute-env-variables.sh old mode 100644 new mode 100755 index 438c144..73be4a6 --- a/docker/substitute-env-variables.sh +++ b/docker/substitute-env-variables.sh @@ -1,18 +1,22 @@ #!/bin/bash -# The first parameter is the path to the file which should be substituted +# The first parameter is a comma-delimited list of paths to files which should be substituted if [[ -z $1 ]]; then - echo 'ERROR: No target file given.' + echo 'ERROR: No target files given.' exit 1 fi -# Replace strings in the given file that have the format ${ENV_VAR} -envsubst '\$PRODUCTION \$API_URL \$IRB_URL \$PORT0' < "$1" > "$1".tmp && mv "$1".tmp "$1" +env_list='\$PRODUCTION \$API_URL \$IRB_URL \$HOME_ROUTE \$PORT0' +for i in $(echo $1 | sed "s/,/ /g") +do + # Replace strings in the given file(s) in env_list + envsubst "$env_list" < "$i" > "$i".tmp && mv "$i".tmp "$i" -# Set DEBUG=true in order to log the replaced file -if [ "$DEBUG" = true ] ; then - exec cat $1 -fi + # Set DEBUG=true in order to log the replaced file + if [ "$DEBUG" = true ] ; then + exec cat $i + fi +done # Execute all other commands with parameters exec "${@:2}"