-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdocker-entrypoint.sh
69 lines (67 loc) · 1.86 KB
/
docker-entrypoint.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
#!/bin/bash
set -euo pipefail
# 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 DB_PASSWORD
file_env APP_KEY
file_env APP_URL
file_env MAILGUN_DOMAIN
file_env MAILGUN_SECRET
file_env ASSET_URL
file_env PUBKEY
file_env PRIVKEY
file_env NEXMO_API
file_env NEXMO_SECRET
maxTries=60
while [ "$maxTries" -gt 0 ] && ! /usr/bin/mysql -h "$DB_HOST" -u "$DB_USERNAME" -p"$DB_PASSWORD" -e "show databases;"; do
let maxTries--
sleep 1
done
echo
if [ "$maxTries" -le 0 ]; then
echo >&2 "error: unable to contact MariaDB after $maxTries tries"
exit 1
fi
if [ $(/usr/bin/mysql -N -h "$DB_HOST" -u "$DB_USERNAME" -p"$DB_PASSWORD" -e \
"select count(*) from information_schema.tables where \
table_schema='$DB_DATABASE' and table_name='migrations';") -eq 1 ]; then
echo >&2 'migrations database already created'
else
php artisan migrate:install
fi
php artisan migrate
php artisan storage:link
if ! [ -z "$SYNCTHING_HOST" ]; then
maxTries1=60
while [ "$maxTries1" -gt 0 ] && ! [ -f /var/syncthing/config/config.xml ]; do
let maxTries1--
sleep 1
done
echo
if [ "$maxTries1" -le 0 ]; then
echo >&2 "error: unable to contact Syncthing after $maxTries1 tries"
exit 1
fi
SYNCTHING_APIKEY=$(cat /var/syncthing/config/config.xml | awk -F "[><]" '/apikey/{print $3}')
export "SYNCTHING_APIKEY"=$SYNCTHING_APIKEY
fi
exec "$@"