-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
61 lines (52 loc) · 1.84 KB
/
Copy pathdocker-entrypoint.sh
File metadata and controls
61 lines (52 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
echo `date +%FT%T%Z` "- docker-entrypoint.sh started !"
set -e
list=$(find /usr/share/nginx/html -name 'main.*.js')
# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
file_env 'BASEURL' 'research'
file_env 'RESEARCH_APIURL'
file_env 'HR_APIURL'
file_env 'KEYCLOAK_PUBLIC_JSON'
# Verificando se o arquivo original ja existe e se nao o criando.
if [ -f "${list}.ORIG" ]
then
cp "${list}.ORIG" ${list}
else
cp ${list} "${list}.ORIG"
fi
# Defining environment variables
sed -i "s;<research_apiurl>;$RESEARCH_APIURL;g" ${list}
sed -i "s;<hr_apiurl>;$HR_APIURL;g" ${list}
sed -i "s;\"<keycloak_public_json>\";'$KEYCLOAK_PUBLIC_JSON';g" ${list}
if grep "try_files" ./etc/nginx/conf.d/default.conf;
then
echo "Try file already configured"
else
sed -i "/index index.html index.htm;/a \ try_files \$uri \$uri/ \/$BASEURL\/index.html;" ./etc/nginx/conf.d/default.conf
sed -i "s/location \/ {/location \/$BASEURL {/g" ./etc/nginx/conf.d/default.conf
mv /usr/share/nginx/html/ /usr/share/nginx/html$BASEURL
mkdir /usr/share/nginx/html
mv /usr/share/nginx/html$BASEURL/ /usr/share/nginx/html/$BASEURL
fi
echo `date +%FT%T%Z` "- docker-entrypoint.sh finished..."
exec "$@"