-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdocker-entrypoint.sh
101 lines (83 loc) · 2.97 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
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
#!/bin/bash
set -e
if [ -z "$ROOT_PASSWORD" ]; then
echo >&2 'error: set ROOT_PASSWORD please'
exit 1
fi
# set root password and make root loginable
echo "root:$ROOT_PASSWORD" | chpasswd
mkdir -p /var/run/sshd
sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
echo "export VISIBLE=now" >> /etc/profile
if [ -z "$FRAMEWORK" ]; then
export FRAMEWORK=laravel
fi
if [ "$FRAMEWORK" = "reverse_proxy" ]; then
cat /root/server_config/reverse_proxy/nginx.conf > /etc/nginx/conf.d/default.conf
else
# git clone
if [ -n "$REPOSITORY_URL" ]; then
# todo: check repository url start with https
cd /var/www && git clone "$REPOSITORY_URL" web
# to slow and tend to fail in alauda, so let user install dependency manually
# if [ -e "/var/www/web/composer.json" ]; then
# # install project dependency
# cd /var/www/web && composer install --no-scripts --no-interaction && composer run-script --no-interaction post-create-project-cmd
# fi
chown -R www-data:www-data /var/www/web
fi
case "${FRAMEWORK,,}" in
'laravel')
echo 'use laravel config'
cat /root/server_config/laravel/nginx.conf > /etc/nginx/conf.d/default.conf
;;
'thinkphp')
echo 'use thinkphp config'
cat /root/server_config/thinkphp/nginx.conf > /etc/nginx/conf.d/default.conf
;;
*)
echo 'maybe you need to refine /etc/nginx/conf.d/default.conf'
cat /root/server_config/laravel/nginx.conf > /etc/nginx/conf.d/default.conf
;;
esac
fi
if [ -n "$MYSQL_ROOT_PASSWORD" ] || [ -n "$MYSQL_ALLOW_EMPTY_PASSWORD" ]; then
if [ -z "$DB_HOST" ]; then
DB_HOST='mysql'
DB_PORT='3306'
DB_USER='root'
if [ -n "$MYSQL_ROOT_PASSWORD" ]; then
DB_PASSWORD="$MYSQL_ROOT_PASSWORD"
else
DB_PASSWORD=''
fi
else
echo >&2 'warning: both DB_HOST and linked mysql container found'
echo >&2 " Remove one please"
exit 1
fi
fi
if [ -z "$DB_HOST" ]; then
echo >&2 'error: missing DB_HOST environment variables'
echo >&2 ' Did you forget to --link some_mysql_container:mysql or set an external db'
echo >&2 ' with -e DB_HOST=hostname -e DB_PORT=port?'
# to do remove redir and socat command in supervisord.conf
else
if [ -z "$DB_PORT" ]; then
DB_PORT='3306'
fi
sed -i "s/DB_PORT/$DB_PORT/" /etc/supervisor/conf.d/supervisord.conf
sed -i "s/DB_HOST/$DB_HOST/" /etc/supervisor/conf.d/supervisord.conf
if [ -z "$DB_USER" ]; then
DB_PORT='root'
fi
if [ -z "$DB_PASSWORD" ]; then
DB_PASSWORD=''
fi
# create initial database
if [ -n "$DB_NAME" ]; then
alauda db:create -p $DB_PORT $DB_NAME $DB_HOST $DB_USER $DB_PASSWORD
fi
fi
exec "$@"