From 214bc04ce0324cad5c16c8de6e96c59105d6bf47 Mon Sep 17 00:00:00 2001 From: dragongoose Date: Mon, 8 May 2023 20:34:30 -0400 Subject: [PATCH] Fix docker env not updating --- .gitignore | 2 ++ substitute_environment_variables.sh | 25 ++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 38adffa..f2e4131 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ coverage *.njsproj *.sln *.sw? + +.env.old diff --git a/substitute_environment_variables.sh b/substitute_environment_variables.sh index f49ef31..b885471 100755 --- a/substitute_environment_variables.sh +++ b/substitute_environment_variables.sh @@ -1,15 +1,34 @@ #!/bin/sh ROOT_DIR=/app +# Save old variables + +# Get old vars +if [ -f .env.old ]; then + export $(echo $(cat .env.old | sed 's/#.*//g'| xargs) | envsubst) +else + export VITE_BACKEND_DOMAIN_PLACEHOLDER=VITE_BACKEND_DOMAIN_PLACEHOLDER + export VITE_INSTANCE_DOMAIN_PLACEHOLDER=VITE_INSTANCE_DOMAIN_PLACEHOLDER + export VITE_HTTPS_PLACEHOLDER=VITE_HTTPS_PLACEHOLDER +fi + +echo $VITE_BACKEND_DOMAIN_PLACEHOLDER # Replace env vars in files served by NGINX for file in $ROOT_DIR/assets/*.js $ROOT_DIR/index.html; do - sed -i 's|VITE_BACKEND_DOMAIN_PLACEHOLDER|'${VITE_BACKEND_DOMAIN}'|g' $file - sed -i 's|VITE_INSTANCE_DOMAIN_PLACEHOLDER|'${VITE_INSTANCE_DOMAIN}'|g' $file - sed -i 's|VITE_HTTPS_PLACEHOLDER|'${VITE_HTTPS}'|g' $file + sed -i 's|'${VITE_BACKEND_DOMAIN_PLACEHOLDER}'|'${VITE_BACKEND_DOMAIN}'|g' $file + sed -i 's|'${VITE_INSTANCE_DOMAIN_PLACEHOLDER}'|'${VITE_INSTANCE_DOMAIN}'|g' $file + sed -i 's|'${VITE_HTTPS_PLACEHOLDER}'|'${VITE_HTTPS}'|g' $file # Your other variables here... done +echo ${VITE_BACKEND_DOMAIN_PLACEHOLDER} + +# Save old variables +echo -e "VITE_BACKEND_DOMAIN_PLACEHOLDER=${VITE_BACKEND_DOMAIN_PLACEHOLDER}" > .env.old +echo -e "VITE_INSTANCE_DOMAIN_PLACEHOLDER=${VITE_INSTANCE_DOMAIN_PLACEHOLDER}" >> .env.old +echo -e "VITE_HTTPS_PLACEHOLDER=${VITE_HTTPS_PLACEHOLDER}" >> .env.old + # Starting NGINX nginx -g 'daemon off;' \ No newline at end of file