From 9d28a472a5d0fe953c24df429e94a7fd27863426 Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Sat, 16 May 2020 22:18:16 -0400 Subject: [PATCH] Runs nginx on port from environment variable --- Dockerfile | 7 +++++++ docker/substitute-env-variables.sh | 2 +- nginx.conf | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index e64090e..77fd5d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,8 +17,15 @@ RUN npm install && \ FROM nginx COPY --from=builder /crc-bpmn/dist/* /usr/share/nginx/html/ COPY --from=builder /crc-bpmn/nginx.conf /etc/nginx/conf.d/default.conf + +# Script for substituting environment variables 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"] ### STAGE 3: Profit! ### diff --git a/docker/substitute-env-variables.sh b/docker/substitute-env-variables.sh index ee28b93..438c144 100644 --- a/docker/substitute-env-variables.sh +++ b/docker/substitute-env-variables.sh @@ -7,7 +7,7 @@ if [[ -z $1 ]]; then fi # Replace strings in the given file that have the format ${ENV_VAR} -envsubst '\$PRODUCTION \$API_URL \$IRB_URL' < "$1" > "$1".tmp && mv "$1".tmp "$1" +envsubst '\$PRODUCTION \$API_URL \$IRB_URL \$PORT0' < "$1" > "$1".tmp && mv "$1".tmp "$1" # Set DEBUG=true in order to log the replaced file if [ "$DEBUG" = true ] ; then diff --git a/nginx.conf b/nginx.conf index fd4472f..51982f5 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,5 +1,5 @@ server { - listen 80; + listen $PORT0; location / { root /usr/share/nginx/html;