-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-entrypoint.sh
120 lines (91 loc) · 4.25 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env bash
set -euo pipefail
set_permissions(){
chown -R www-data:www-data $PWD;
find var pub/static pub/media app/etc -type f -exec chmod g+w {} \;
find var pub/static pub/media app/etc -type d -exec chmod g+ws {} \;
}
reset_generated(){
rm -rf ../var/page_cache/*;
rm -rf ../var/cache/*;
rm -rf ../var/view_preprocessed/*;
rm -rf ../var/composer_home/*;
rm -rf ../pub/static/*;
rm -rf ../var/generation/*;
}
cron_jobs(){
#write out current crontab
crontab -l > mycron
#echo new cron into cron file
echo "* * * * * /usr/local/bin/php $PWD/bin/magento cron:run | grep -v 'Ran jobs by schedule' >> $PWD/var/log/magento.cron.log" >> mycron
echo "* * * * * /usr/local/bin/php $PWD/update/cron.php >> $PWD/var/log/update.cron.log" >> mycron
echo "* * * * * /usr/local/bin/php $PWD/bin/magento setup:cron:run >> $PWD/var/log/setup.cron.log" >> mycron
#install new cron file
crontab -u www-data mycron
rm mycron
}
if ! [ -e index.php -a -e bin/magento ]; then
echo >&2 "Magento2 not found in $PWD - creating now..."
if [ -z ${MAGENTO_PUBLIC_KEY+x} ] || [ -z ${MAGENTO_PRIVATE_KEY+x} ]; then
echo >&2 "You must set the following environmental variables to get the integrator package MAGENTO_PUBLIC_KEY , MAGENTO_PRIVATE_KEY "
echo >&2 "You may optionally set MAGENTO_VERSION (default 2.2.0) "
echo >&2 "This container will continue to run, you may access it via 'docker exec <this-container> sh' to perform manual installs or backups.."
else
if [ "$(ls -A)" ]; then
echo >&2 "WARNING: $PWD please empty the mounted volume on the host and try again..."
( set -x; ls -A; sleep 10 )
fi
composer global config http-basic.repo.magento.com ${MAGENTO_PUBLIC_KEY} ${MAGENTO_PRIVATE_KEY};
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition:${MAGENTO_VERSION} /var/www/html;
# Set the pre-installation magento folder permissions
find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \; \
&& find var vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} \; \
&& chown -R :www-data . && chmod u+x bin/magento;
fi
fi
if ! [ -e app/etc/env.php ]; then
if [ -z ${ADMIN_FIRSTNAME+x} ] \
|| [ -z ${ADMIN_LASTNAME+x} ] \
|| [ -z ${ADMIN_EMAIL+x} ] \
|| [ -z ${ADMIN_USER+x} ] \
|| [ -z ${ADMIN_PASSWORD+x} ]; then
echo >&2 "Magento package has been downloaded but not installed"
echo >&2 "Please visit your host address in the browser to manually setup your magento 2 installation"
echo >&2 "If you wish to have your magento installation automatically installed please see the README for more details"
else
#http://devdocs.magento.com/guides/v2.1/install-gde/install/cli/install-cli-install.html
./bin/magento setup:install \
--admin-firstname=${ADMIN_FIRSTNAME} \
--admin-lastname=${ADMIN_LASTNAME} \
--admin-email=${ADMIN_EMAIL} \
--admin-user=${ADMIN_USER} \
--admin-password=${ADMIN_PASSWORD} \
--base-url=${BASE_URL} \
--backend-frontname=${BACKEND_FRONTNAME} \
--db-host=${DB_HOST} \
--db-name=${MYSQL_DATABASE} \
--db-user=${MYSQL_USER} \
--db-password=${MYSQL_PASSWORD} \
--language=${LANGUAGE} \
--currency=${CURRENCY} \
--timezone=${TIMEZONE} \
--use-secure=${USE_SECURE} \
--use-secure-admin=${USE_SECURE_ADMIN} \
--use-rewrites=${USE_REWRITES}
./bin/magento deploy:mode:set developer;
set_permissions;
fi
else
echo >&2 "Magento package has been downloaded but not installed"
echo >&2 "Please visit your host address in the browser to manually setup your magento 2 installation"
echo >&2 "If you wish to have your magento installation automatically installed please see the README for more details"
fi
if ! [ -e /var/spool/cron/crontabs/www-data ]; then
touch /var/spool/cron/crontabs/www-data && chown www-data:www-data /var/spool/cron/crontabs/www-data;
cron_jobs;
fi
if ! [ -e magento_umask ] && [ -e index.php -a -e bin/magento ]; then
echo 'magento_umask 002' > magento_umask;
fi
service ssh start;
exec "$@"