-
Notifications
You must be signed in to change notification settings - Fork 0
/
geoimagenet-compose.sh
executable file
·72 lines (61 loc) · 1.66 KB
/
geoimagenet-compose.sh
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
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
YELLOW=$(tput setaf 3)
RED=$(tput setaf 1)
NORMAL=$(tput sgr0)
# list of all variables to be substituted in templates
VARS='
$USING_GEOIMAGENET_COMPOSE
$HOST_FQDN
$POSTGIS_DB
$POSTGIS_PORT
$POSTGIS_USER
$POSTGIS_PASSWORD
$SSL_CERTIFICATE
$MAGPIE_ADMIN_USER
$MAGPIE_ADMIN_PW
$MAGPIE_SECRET
$MAGPIE_LOG_LEVEL
$SUPPORT_EMAIL
$CONTACT_EMAIL
'
# we switch to the real directory of the script, so it still works when used from $PATH
# tip: ln -s /path/to/geoimagenet-compose.sh ~/bin/
cd $(dirname $(readlink -f $0 || realpath $0))
# we source local configs, if present
# we don't use usual .env filename, because docker-compose uses it
[[ -f env.local ]] && source env.local
for i in ${VARS}
do
v="${i#$}"
if [[ -z "${!v}" ]]
then
echo "${RED}Error${NORMAL}: Required variable ${v} is not set. Check env.local file."
exit
fi
done
if [[ ! -f docker-compose.yml ]]
then
echo "Error, this script must be ran from the folder containing the docker-compose.yml file"
exit 1
fi
## check fails when root access is required to access this file.. workaround possible by going through docker daemon...
# but will add delay
# if [[ ! -f $SSL_CERTIFICATE ]]
# then
# echo "Error, SSL certificate file $SSL_CERTIFICATE is missing"
# exit 1
# fi
# we apply all the templates
git ls-files -z \*.template |
while IFS= read -r -d $'\0' FILE
do
DEST=${FILE%.template}
cat ${FILE} | envsubst "${VARS}" > ${DEST}
done
docker-compose $*
# we restart the proxy after an up to make sure nginx continue to work if any container IP address changes
while [[ $# -gt 0 ]]
do
[[ $1 == "up" ]] && { docker-compose restart nginx; }
shift
done