-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathentrypoint.sh
129 lines (110 loc) · 3.13 KB
/
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
echo "Now in entrypoint.sh for 2FAuth"
echo "Running as '$(whoami)' in group '$(id -g -n)'."
echo "Current working dir is '$(pwd)'"
# https://github.com/docker-library/wordpress/blob/master/docker-entrypoint.sh
# 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"
}
# envs that can be appended with _FILE
envs=(
SITE_OWNER
APP_KEY
DB_CONNECTION
DB_HOST
DB_PORT
DB_DATABASE
DB_USERNAME
DB_PASSWORD
PGSQL_SSL_MODE
PGSQL_SSL_ROOT_CERT
PGSQL_SSL_CERT
PGSQL_SSL_KEY
PGSQL_SSL_CRL_FILE
REDIS_HOST
REDIS_PASSWORD
REDIS_PORT
MAIL_DRIVER
MAIL_HOST
MAIL_PORT
MAIL_FROM
MAIL_USERNAME
MAIL_PASSWORD
MAIL_ENCRYPTION
)
echo "Now parsing _FILE variables."
for e in "${envs[@]}"; do
file_env "$e"
done
echo "done!"
# touch DB file
echo "Touch DB file (if SQLite)..."
if [[ $DB_CONNECTION == "sqlite" ]]; then
touch $TWOFAUTH_PATH/storage/database/database.sqlite
echo "Touched!"
fi
echo "Dump auto load..."
composer dump-autoload > /dev/null 2>&1
echo "Discover packages..."
php artisan package:discover > /dev/null 2>&1
echo "Current working dir is '$(pwd)'"
echo "Wait for the db container."
if [[ -z "$DB_PORT" ]]; then
if [[ $DB_CONNECTION == "mysql" ]]; then
DB_PORT=3306
fi
fi
if [[ -n "$DB_PORT" ]]; then
/usr/local/bin/wait-for-it.sh "${DB_HOST}:${DB_PORT}" -t 60 -- echo "DB container is up."
fi
echo "Wait another 15 seconds in case the DB container needs to boot."
sleep 15
echo "Done waiting for the DB container to boot."
# echo "check for 2fauth database"
# SQL1="CREATE DATABASE IF NOT EXISTS ${DB_DATABASE} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
# SQL2="CREATE USER '${DB_USERNAME}'@'%' IDENTIFIED BY '${DB_PASSWORD}';"
# SQL3="GRANT ALL PRIVILEGES ON ${DB_DATABASE}.* TO '${DB_USERNAME}'@'%';"
# SQL4="FLUSH PRIVILEGES;"
# mysql -h $DB_HOST -u root -p$DB_PASSWORD -e "${SQL1}${SQL2}${SQL3}${SQL4}"
# echo "2FAuth db is ready"
echo "Current working dir is '$(pwd)'"
echo "Run various artisan commands..."
echo "Running migration commands..."
php artisan migrate
php artisan passport:install
php artisan storage:link
php artisan cache:clear > /dev/null 2>&1
php artisan config:cache > /dev/null 2>&1
echo "Current working dir is '$(pwd)'"
# set docker var.
# export IS_DOCKER=true
if [ -z $APACHE_RUN_USER ]
then
APACHE_RUN_USER='www-data'
fi
if [ -z $APACHE_RUN_GROUP ]
then
APACHE_RUN_GROUP='www-data'
fi
chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $TWOFAUTH_PATH/storage
chmod -R 775 $TWOFAUTH_PATH/storage
echo "Go!"
exec apache2-foreground