Passes path to index.html in as optional parameter to substitute-env-variables.sh

This commit is contained in:
Aaron Louie 2020-05-23 11:50:31 -04:00
parent 2f8bba4f37
commit 198cfd90bb
3 changed files with 26 additions and 6 deletions

View File

@ -25,7 +25,10 @@ COPY ./docker/substitute-env-variables.sh ./entrypoint.sh
RUN chmod +x ./entrypoint.sh
# Substitute environment variables in nginx configuration and index.html
ENTRYPOINT ["./entrypoint.sh", "/usr/share/nginx/html/index.html,/etc/nginx/conf.d/default.conf", "PRODUCTION,API_URL,IRB_URL,HOME_ROUTE,BASE_HREF,PORT0"]
ENTRYPOINT ["./entrypoint.sh", \
"/usr/share/nginx/html/index.html,/etc/nginx/conf.d/default.conf", \
"PRODUCTION,API_URL,IRB_URL,HOME_ROUTE,BASE_HREF,PORT0", \
"/usr/share/nginx/html/index.html"]
### STAGE 3: Profit! ###
CMD ["nginx", "-g", "daemon off;"]

View File

@ -1,5 +1,13 @@
#!/bin/bash
#####################################################################
# Substitutes the given environment variables in the given files.
# Parameters:
# $1: Comma-delimited list of file paths
# $2: Comma-delimited list of environment variables
# $3: File path to index.html (optional)
#####################################################################
echo 'Substituting environment variables...'
# The first parameter is a comma-delimited list of paths to files which should be substituted
@ -32,8 +40,17 @@ do
echo "$env_var = ${!env_var}"
done
# Rewrite base href in index.html. Use @ as a sed delimiter because $BASE_HREF will contain a / character
sed -i -e 's@<base href\=\"\/\">@<base href\=\"'"$BASE_HREF"'\">@' "/usr/share/nginx/html/index.html"
# The third parameter is the path to the index.html file
# Rewrite base href in index.html.
# Use @ as a sed delimiter because $BASE_HREF will contain a / character
if [[ -z $3 ]]; then
# Execute all other commands with parameters
exit 0
else
sed -i -e 's@<base href\=\"\/\">@<base href\=\"'"$BASE_HREF"'\">@' "$3"
# Execute all other commands with parameters
exec "${@:4}"
fi
# Execute all other commands with parameters
exec "${@:3}"

View File

@ -21,7 +21,7 @@
"e2e-wf:db-setup": "docker exec -it backend pipenv run flask load-example-data",
"e2e-wf:pb-setup": "docker exec -it pb pipenv run flask db upgrade",
"e2e-wf": "npm run e2e-wf:stop && npm run e2e-wf:clean && npm run e2e-wf:build && npm run e2e-wf:start && npm run e2e-wf:db-upgrade && npm run e2e-wf:db-setup && npm run e2e-wf:pb-setup",
"env": "chmod +x ./docker/substitute-env-variables.sh && ./docker/substitute-env-variables.sh src/index.html PRODUCTION,API_URL,IRB_URL,HOME_ROUTE,BASE_HREF,PORT0",
"env": "chmod +x ./docker/substitute-env-variables.sh && ./docker/substitute-env-variables.sh src/index.html PRODUCTION,API_URL,IRB_URL,HOME_ROUTE,BASE_HREF,PORT0 src/index.html",
"ci": "npm run lint && npm run test:coverage && npm run env && npm run e2e:with-wf && sonar-scanner"
},
"private": true,