From 3c3e58293950dc1c7c36263f9e4e4c657db01a91 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Fri, 16 Feb 2024 04:11:09 +0000 Subject: [PATCH] Minor envsubst improvements. (#746) Minor fixes to envsubst for webapps. Somewhat specially treated is `LACONIC_HOSTED_CONFIG_homepage` which can be used to replace the homepage in package.json. With react, this gets an extra `/` though, which we need to remove. Reviewed-on: https://git.vdb.to/cerc-io/stack-orchestrator/pulls/746 Co-authored-by: Thomas E Lackey Co-committed-by: Thomas E Lackey --- .../cerc-nextjs-base/scripts/apply-runtime-env.sh | 4 ++-- .../cerc-webapp-base/scripts/apply-runtime-env.sh | 4 ++-- .../container-build/cerc-webapp-base/scripts/build-app.sh | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/apply-runtime-env.sh b/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/apply-runtime-env.sh index cf1e7ce5..a662ae02 100755 --- a/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/apply-runtime-env.sh +++ b/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/apply-runtime-env.sh @@ -33,8 +33,8 @@ if [ -f ".env" ]; then rm -f $TMP_ENV fi -for f in $(find "$TRG_DIR" -regex ".*.[tj]sx?$" -type f | grep -v 'node_modules'); do - for e in $(cat "${f}" | tr -s '[:blank:]' '\n' | tr -s '[{},();]' '\n' | egrep -o '^"CERC_RUNTIME_ENV_[^\"]+"'); do +for f in $(find . -type f \( -regex '.*.html?' -or -regex ".*.[tj]s\(x\|on\)?$" \) | grep -v 'node_modules' | grep -v '.git'); do + for e in $(cat "${f}" | tr -s '[:blank:]' '\n' | tr -s '["/\\{},();]' '\n' | tr -s "[']" '\n' | egrep -o -e '^CERC_RUNTIME_ENV_.+$' -e '^LACONIC_HOSTED_CONFIG_.+$'); do orig_name=$(echo -n "${e}" | sed 's/"//g') cur_name=$(echo -n "${orig_name}" | sed 's/CERC_RUNTIME_ENV_//g') cur_val=$(echo -n "\$${cur_name}" | envsubst) diff --git a/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/apply-runtime-env.sh b/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/apply-runtime-env.sh index d3ea1d34..0e48303f 100755 --- a/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/apply-runtime-env.sh +++ b/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/apply-runtime-env.sh @@ -18,8 +18,8 @@ if [ -f ".env" ]; then rm -f $TMP_ENV fi -for f in $(find . -regex ".*.[tj]sx?$" -type f | grep -v 'node_modules'); do - for e in $(cat "${f}" | tr -s '[:blank:]' '\n' | tr -s '[{},();]' '\n' | egrep -o -e '^"CERC_RUNTIME_ENV_[^\"]+"' -e '^"LACONIC_HOSTED_CONFIG_[^\"]+"'); do +for f in $(find . -type f \( -regex '.*.html?' -or -regex ".*.[tj]s\(x\|on\)?$" \) | grep -v 'node_modules' | grep -v '.git'); do + for e in $(cat "${f}" | tr -s '[:blank:]' '\n' | tr -s '["/\\{},();]' '\n' | tr -s "[']" '\n' | egrep -o -e '^CERC_RUNTIME_ENV_.+$' -e '^LACONIC_HOSTED_CONFIG_.+$'); do orig_name=$(echo -n "${e}" | sed 's/"//g') cur_name=$(echo -n "${orig_name}" | sed 's/CERC_RUNTIME_ENV_//g') cur_val=$(echo -n "\$${cur_name}" | envsubst) diff --git a/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/build-app.sh b/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/build-app.sh index c102a054..f44931f4 100755 --- a/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/build-app.sh +++ b/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/build-app.sh @@ -33,4 +33,10 @@ else mv "${WORK_DIR}" "${DEST_DIR}" fi +# One special fix ... +cd "${DEST_DIR}" +for f in $(find . -type f -name '*.htm*'); do + sed -i -e 's#/LACONIC_HOSTED_CONFIG_homepage/#LACONIC_HOSTED_CONFIG_homepage/#g' "$f" +done + exit 0