Substitutes environment variables in multiple files

This commit is contained in:
Aaron Louie 2020-05-16 22:59:05 -04:00
parent 9d28a472a5
commit d6850f056c
2 changed files with 14 additions and 13 deletions

View File

@ -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 COPY ./docker/substitute-env-variables.sh ./entrypoint.sh
RUN chmod +x ./entrypoint.sh RUN chmod +x ./entrypoint.sh
# Substitute environment variables in nginx configuration # Substitute environment variables in nginx configuration and index.html
CMD ["./entrypoint.sh", "/etc/nginx/conf.d/default.conf"] ENTRYPOINT ["./entrypoint.sh", "/usr/share/nginx/html/index.html,/etc/nginx/conf.d/default.conf"]
# Substitute environment variables in index.html
ENTRYPOINT ["./entrypoint.sh", "/usr/share/nginx/html/index.html"]
### STAGE 3: Profit! ### ### STAGE 3: Profit! ###
CMD ["nginx", "-g", "daemon off;"] CMD ["nginx", "-g", "daemon off;"]

20
docker/substitute-env-variables.sh Normal file → Executable file
View File

@ -1,18 +1,22 @@
#!/bin/bash #!/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 if [[ -z $1 ]]; then
echo 'ERROR: No target file given.' echo 'ERROR: No target files given.'
exit 1 exit 1
fi fi
# Replace strings in the given file that have the format ${ENV_VAR} env_list='\$PRODUCTION \$API_URL \$IRB_URL \$HOME_ROUTE \$PORT0'
envsubst '\$PRODUCTION \$API_URL \$IRB_URL \$PORT0' < "$1" > "$1".tmp && mv "$1".tmp "$1" 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 # Set DEBUG=true in order to log the replaced file
if [ "$DEBUG" = true ] ; then if [ "$DEBUG" = true ] ; then
exec cat $1 exec cat $i
fi fi
done
# Execute all other commands with parameters # Execute all other commands with parameters
exec "${@:2}" exec "${@:2}"