diff --git a/Dockerfile b/Dockerfile index e64090e..0781b10 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,9 +17,13 @@ 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 -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 ee28b93..b6b187b --- a/docker/substitute-env-variables.sh +++ b/docker/substitute-env-variables.sh @@ -1,18 +1,30 @@ #!/bin/bash -# The first parameter is the path to the file which should be substituted +echo 'Substituting environment variables...' + +# 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' < "$1" > "$1".tmp && mv "$1".tmp "$1" +env_list='\$PRODUCTION \$API_URL \$IRB_URL \$HOME_ROUTE \$PORT0' +for file_path in $(echo $1 | sed "s/,/ /g") +do + echo "replacing $env_list in $file_path" -# Set DEBUG=true in order to log the replaced file -if [ "$DEBUG" = true ] ; then - exec cat $1 -fi + # Replace strings in the given file(s) in env_list + envsubst "$env_list" < "$file_path" > "$file_path".tmp && mv "$file_path".tmp "$file_path" + + echo '...' +done + +echo 'Finished substituting environment variables.' +echo "PRODUCTION = $PRODUCTION" +echo "API_URL = $API_URL" +echo "IRB_URL = $IRB_URL" +echo "HOME_ROUTE = $HOME_ROUTE" +echo "PORT0 = $PORT0" # Execute all other commands with parameters exec "${@:2}" 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; diff --git a/package-lock.json b/package-lock.json index 7be706a..2854c01 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12291,9 +12291,9 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "sartography-workflow-lib": { - "version": "0.0.159", - "resolved": "https://registry.npmjs.org/sartography-workflow-lib/-/sartography-workflow-lib-0.0.159.tgz", - "integrity": "sha512-EkXmgoliJkBqsBrI/3N3GLNJmrVgwu4kekU8M6Z2E15+shRwmLH0vxFAWmW0JDG2JGcw7vOhPMb8iVlLlLcr7A==" + "version": "0.0.167", + "resolved": "https://registry.npmjs.org/sartography-workflow-lib/-/sartography-workflow-lib-0.0.167.tgz", + "integrity": "sha512-Ju6VehVOj6yjAYOTEN2PtFbWUXB6LTldaf5GO8iW2lx20Z+TGnrK0Lvgh1hv3/F+7yUqpcZjJvO+ppYahpURRA==" }, "sass": { "version": "1.23.3", diff --git a/package.json b/package.json index 0789b5e..7e1abb2 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "ngx-file-drop": "^8.0.8", "ngx-markdown": "^9.0.0", "rxjs": "~6.5.4", - "sartography-workflow-lib": "^0.0.159", + "sartography-workflow-lib": "^0.0.167", "tslib": "^1.11.1", "uuid": "^7.0.2", "zone.js": "^0.10.3"