Resolve entrypoint file bug

This commit is contained in:
Daniel Weissmall 2022-10-12 16:44:41 +03:00
parent 9a3e545cf0
commit 85f227f7d9

View File

@ -1,35 +1,35 @@
#!/bin/bash #! /bin/bash
# no verbose # no verbose
set +x set +x
# config # config
envFilename='.env.production' envFilename='.env.production'
resolvingPath='/usr/share/nginx/html' resolvingPath='/usr/share/nginx/html'
function apply_path { function apply_path {
# read all config file # read all config file
while read line; do while read line; do
# no comment or not empty # no comment or not empty
if [ "${line:0:1}" == "#" ] || [ "${line}" == "" ]; then if [ "${line:0:1}" == "#" ] || [ "${line}" == "" ]; then
echo "Skiped line $line" echo "Skiped line $line"
continue continue
fi fi
# split # split
configName="$(cut -d'=' -f1 <<<"$line")" configName="$(cut -d'=' -f1 <<<"$line")"
configValue="$(cut -d'=' -f2 <<<"$line")" configValue="$(cut -d'=' -f2 <<<"$line")"
# get system env # get system env
envValue=$(env | grep "^$configName=" | grep -oP '(?!=)(?<==).*$'); envValue=$(env | grep "^$configName=" | grep -oP '(?!=)(?<==).*$');
if [ -z "$configValue" ]; then if [ -z "$configValue" ]; then
echo "Empty env value met: $configName:$configValue" echo "Empty env value met: $configName:$configValue"
fi fi
# if config found # if config found
if [ -n "$configValue" ] && [ -n "$envValue" ]; then if [ -n "$configValue" ] && [ -n "$envValue" ]; then
# replace all # replace all
echo "Replace: ${configValue} with: ${envValue}" echo "Replace: ${configValue} with: ${envValue}"
find $resolvingPath \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#$configValue#$envValue#g" find $resolvingPath \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#$configValue#$envValue#g"
fi fi
done < $envFilename done < $envFilename
} }
apply_path apply_path
echo "Starting React Application" echo "Starting React Application"
exec "$@" exec "$@"