Skip to content

Commit

Permalink
feat(nginx-pwa): Refactor envsubst script to use NGINX_CONFIG_JS_URI
Browse files Browse the repository at this point in the history
  • Loading branch information
AliMD committed Jan 23, 2024
1 parent 2429161 commit 6b09d96
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions nginx-pwa/etc/nginx/entrypoint.d/90-envsubst-on-config-js.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ set -e

ME=$(basename $0)

test -z "$NGINX_CONFIG_JS_PATH" && exit 0
test ! -f "$NGINX_CONFIG_JS_PATH" && exit 1
test -z "$NGINX_CONFIG_JS_URI" && exit 0

configJsPath="$NGINX_DOCUMENT_ROOT/$NGINX_CONFIG_JS_URI"
if test ! -f "$configJsPath"; then
echo "$ME: ERROR: $configJsPath does not exist"
exit 1
fi

definedEnvs=$(printf '${%s} ' $(env | cut -d= -f1))
if [ ! -w "$NGINX_CONFIG_JS_PATH" ]; then
echo >&3 "$ME: ERROR: $NGINX_CONFIG_JS_PATH exists, but is not writable"
if [ ! -w "$configJsPath" ]; then
echo "$ME: ERROR: $configJsPath exists, but is not writable"
return 0
fi
echo >&3 "$ME: Running envsubst on $NGINX_CONFIG_JS_PATH"
envsubst "$definedEnvs" <"$NGINX_CONFIG_JS_PATH" >"${NGINX_CONFIG_JS_PATH}.tmp"
mv -f "${NGINX_CONFIG_JS_PATH}.tmp" "$NGINX_CONFIG_JS_PATH"
echo "$ME: Running envsubst on $configJsPath"
envsubst "$definedEnvs" <"$configJsPath" >"${configJsPath}.tmp"
mv -f "${configJsPath}.tmp" "$configJsPath"

exit 0

0 comments on commit 6b09d96

Please sign in to comment.