Substitutes deploy url with separate environment variable

This commit is contained in:
Aaron Louie 2020-05-26 09:33:49 -04:00
parent 47ddd834c7
commit e70a8a30af
4 changed files with 22 additions and 7 deletions

View File

@ -29,6 +29,6 @@ RUN chmod +x ./entrypoint.sh
# then starts/reloads nginx.
ENTRYPOINT ["./entrypoint.sh", \
"/etc/nginx/html/index.html,/etc/nginx/conf.d/default.conf", \
"PRODUCTION,API_URL,IRB_URL,HOME_ROUTE,BASE_HREF,PORT0", \
"PRODUCTION,API_URL,IRB_URL,HOME_ROUTE,BASE_HREF,DEPLOY_URL,PORT0", \
"/etc/nginx/html", \
"true"]

View File

@ -73,7 +73,8 @@ services:
# image: sartography/cr-connect-bpmn:$E2E_TAG
# environment:
# - API_URL=http://localhost:5000/v1.0
# - BASE_HREF=/bpmn
# - BASE_HREF=/
# - DEPLOY_URL=/bpmn
# - HOME_ROUTE=home
# - IRB_URL=http://localhost:5001/
# - PORT0=5002

View File

@ -42,12 +42,18 @@ else
num_args=4
fi
# Find & replace BASE_HREF and DEPLOY_URL in all files in the nginx html directory
if [[ "$2" == *"BASE_HREF"* ]] && [[ "$2" == *"DEPLOY_URL"* ]]; then
# Add trailing slash to $BASE_HREF if needed
if [[ "$2" == *"BASE_HREF"* ]]; then
length=${#BASE_HREF}
last_char=${BASE_HREF:length-1:1}
[[ $last_char != "/" ]] && BASE_HREF="$BASE_HREF/"; :
# Add trailing slash to $DEPLOY_URL if needed
length=${#DEPLOY_URL}
last_char=${DEPLOY_URL:length-1:1}
[[ $last_char != "/" ]] && DEPLOY_URL="$DEPLOY_URL/"; :
# The third parameter is the absolute path to the nginx html directory
if [[ $num_args -ge 3 ]]; then
# Replace all instances of __REPLACE_ME_WITH_BASE_HREF__ with $BASE_HREF
@ -57,6 +63,14 @@ if [[ "$2" == *"BASE_HREF"* ]]; then
echo 'Replacing base href...'
# Wait a few seconds in case find | sed needs more time
sleep 3
# Replace all instances of __REPLACE_ME_WITH_DEPLOY_URL__ with $DEPLOY_URL
find "$3" \( -type d -name .git -prune \) -o -type f -print0 | \
xargs -0 sed -i 's@__REPLACE_ME_WITH_DEPLOY_URL__@'"$DEPLOY_URL"'@g'
echo 'Replacing deploy URL...'
# Wait a few seconds in case find | sed needs more time
sleep 3
fi
fi

View File

@ -5,8 +5,8 @@
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"build:prod": "ng build --configuration=production --prod --base-href=__REPLACE_ME_WITH_BASE_HREF__ --deploy-url=__REPLACE_ME_WITH_BASE_HREF__",
"build:staging": "ng build --configuration=staging --prod --base-href=__REPLACE_ME_WITH_BASE_HREF__ --deploy-url=__REPLACE_ME_WITH_BASE_HREF__",
"build:prod": "ng build --configuration=production --prod --base-href=__REPLACE_ME_WITH_BASE_HREF__ --deploy-url=__REPLACE_ME_WITH_DEPLOY_URL__",
"build:staging": "ng build --configuration=staging --prod --base-href=__REPLACE_ME_WITH_BASE_HREF__ --deploy-url=__REPLACE_ME_WITH_DEPLOY_URL__",
"build:test": "ng build --configuration=test",
"test": "ng test",
"test:coverage": "ng test --codeCoverage=true --watch=false --browsers=ChromeHeadless",
@ -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,DEPLOY_URL,PORT0",
"ci": "npm run lint && npm run test:coverage && sonar-scanner"
},
"private": true,