File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed
Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change 1- #! /usr/ bin/env sh
2- set -eu
1+ #! /bin/sh
2+ set -euo pipefail
33
4- ENV_JSON=$( env | grep ' ^REACT_APP_*' | jq -c ' . | split("\n") | map(select(. != "")) | map(split("=") | { (.[0]) : .[1] }) | reduce .[] as $item ({}; . * $item)' -R -s)
5- ESCAPED_ENV_JSON=$( echo $ENV_JSON | sed ' s/\"/\\\"/g' | sed ' s/\//\\\//g' | tr -d ' \n' | tr -d ' [[:blank:]]' )
6- sed -i ' s/%REACT_APP_ENV%/' " $ESCAPED_ENV_JSON " ' /g' /var/www/index.html
4+ # Capture all environment variables starting with REACT_APP_ and make JSON string from them
5+ ENV_JSON=" $( jq --compact-output --null-input ' env | with_entries(select(.key | startswith("REACT_APP_")))' ) "
6+
7+ # Escape sed replacement's special characters: \, &, /.
8+ # No need to escape newlines, because --compact-output already removed them.
9+ # Inside of JSON strings newlines are already escaped.
10+ ENV_JSON_ESCAPED=" $( printf " %s" " ${ENV_JSON} " | sed -e ' s/[\&/]/\\&/g' ) "
11+
12+ sed -i " s/%REACT_APP_ENV%/${ENV_JSON_ESCAPED} /g" /var/www/index.html
713
814exec " $@ "
You can’t perform that action at this time.
0 commit comments