Skip to content

Commit

Permalink
feat: add additional extend list for variable replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
milanhorvath authored Aug 19, 2024
1 parent e7a647e commit c7a56aa
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ else
fi

IFS=, read -ra config_env_names <<< "$CONFIG_ENV_LIST"
IFS=, read -ra config_env_ext_names <<< "$CONFIG_ENV_EXT_LIST"
config_env_names=( "${config_env_names[@]}" "${config_env_ext_names[@]}" )

# Update environment variables in env.json
if [ -f ${DIR_ASSETS}/env.json ]; then
Expand All @@ -34,14 +36,25 @@ if [ -f ${DIR_ASSETS}/env.json ]; then
done

echo "Updating ${DIR_ASSETS}/env.json"
for item in $config_env_names; do
for item in ${config_env_names[@]}; do
value=$(printf '%s\n' "${!item}")
if [[ ! -z "$value" ]]; then
echo "Replace '$item' with '$value' in env.json"
sed -i "s|\${$item}|$value|g" ${DIR_ASSETS}/env.json
fi
done

if [[ ${ADDITIONAL_REPLACE:-false} == true ]]; then
echo "Second update ${DIR_ASSETS}/env.json"
for item in ${config_env_names[@]}; do
value=$(printf '%s\n' "${!item}")
if [[ ! -z "$value" ]]; then
echo "Replace '$item' with '$value' in env.json"
sed -i "s|\${$item}|$value|g" ${DIR_ASSETS}/env.json
fi
done
fi

# Create INJECTED_ENV from env.json
envJsonAsString=$(sed -E 's/\$\{.*\}/@UNDEFINED/' ${DIR_ASSETS}/env.json | tr -d "\n")
escaped_conf=$(printf '%s\n' "$envJsonAsString" | sed -e 's/[\/&]/\\&/g')
Expand Down

0 comments on commit c7a56aa

Please sign in to comment.