-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-compose.yml
254 lines (244 loc) · 10.4 KB
/
docker-compose.yml
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
version: '3.7'
services:
phalcon:
depends_on:
- database
build: ./docker/8.1
#image: 'damalis/phalcon/8.1-fpm'
working_dir: /srv
container_name: phalcon
networks:
- backend
volumes:
- 'html:${WEBSERVER_DOC_ROOT}'
- 'srv:/srv'
- type: bind
source: ./php-fpm/php/conf.d/security.ini
target: '${PHP_INI_DIR_PREFIX}/php/conf.d/security.ini'
- type: bind
source: ./php-fpm/php-fpm.d/z-www.conf
target: '${PHP_INI_DIR_PREFIX}/php-fpm.d/z-www.conf'
hostname: phalcon
restart: unless-stopped
ports:
- '9000:80'
links:
- database
- redis
#healthcheck:
# test: ["CMD-SHELL", "curl -fk https://${DOMAIN_NAME} || exit 1"]
# interval: 10s
# timeout: 5s
# retries: 6
# start_period: 600s
environment:
TZ: '${LOCAL_TIMEZONE}'
labels:
- 'docker-volume-backup.stop-during-backup=true'
command: >
bash -c "if [ -z \"$(php -m | grep 'phalcon')\" ] && [ -z \"$(php -m | grep 'psr')\" ]; then chmod +x /srv/build/install && cd /srv/build/ && ./install && echo 'extension=phalcon.so' > ${PHP_INI_DIR_PREFIX}/php/conf.d/phalcon.ini;
rm -fr php-psr > /dev/null 2>&1 && git clone https://github.com/jbboehr/php-psr.git && cd php-psr && /usr/local/bin/phpize && ./configure && make && make test && sudo make install && echo 'extension=psr.so' > ${PHP_INI_DIR_PREFIX}/php/conf.d/psr.ini; fi;
grep -qe 'date.timezone = ${LOCAL_TIMEZONE}' ${PHP_INI_DIR_PREFIX}/php/conf.d/security.ini || echo 'date.timezone = ${LOCAL_TIMEZONE}' >> ${PHP_INI_DIR_PREFIX}/php/conf.d/security.ini; php-fpm"
webserver:
depends_on:
- phalcon
image: nginx:stable
container_name: webserver
networks:
- backend
- frontend
volumes:
- 'html:${WEBSERVER_DOC_ROOT}'
- type: bind
source: ./webserver/nginx.conf
target: '${NGINX_PREFIX}/nginx.conf'
- type: bind
source: ./webserver/templates/nginx.conf.template
target: '${NGINX_PREFIX}/templates/default.conf.template'
- type: bind
source: ./webserver/ssl-option/options-ssl-nginx.conf
target: '${LETSENCRYPT_CONF_PREFIX}/options-ssl-nginx.conf'
- type: bind
source: ./ssl-conf.sh
target: '/tmp/ssl-conf.sh'
- 'certbot-etc:${LETSENCRYPT_CONF_PREFIX}'
- '/tmp/acme-challenge:/tmp/acme-challenge'
hostname: webserver
restart: unless-stopped
ports:
- '80:80'
- '443:443'
links:
- phalcon
environment:
NGINX_HOST: ${DOMAIN_NAME}
NGINX_PORT: 80
TZ: '${LOCAL_TIMEZONE}'
command: bash -c "/docker-entrypoint.sh nginx -v; sh /tmp/ssl-conf.sh '${DOMAIN_NAME}' '${LETSENCRYPT_CONF_PREFIX}' '${NGINX_PREFIX}'"
certbot:
depends_on:
- webserver
image: certbot/certbot
container_name: certbot
networks:
- backend
volumes:
- 'certbot-etc:${LETSENCRYPT_CONF_PREFIX}'
- 'certbot-var:/var/lib/letsencrypt'
- '/tmp/acme-challenge:/tmp/acme-challenge'
restart: unless-stopped
environment:
TZ: '${LOCAL_TIMEZONE}'
entrypoint: /bin/sh -c "certbot certonly --webroot --webroot-path /tmp/acme-challenge --rsa-key-size 4096 --non-interactive --agree-tos --no-eff-email --force-renewal --email ${LETSENCRYPT_EMAIL} -d ${DOMAIN_NAME} -d www.${DOMAIN_NAME};
trap exit TERM; while :; do certbot renew --dry-run; sleep 12h & wait $${!}; done;"
phpmyadmin:
depends_on:
- certbot
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
networks:
- backend
- frontend
volumes:
- type: bind
source: ./phpmyadmin/apache2/sites-available/default-ssl.conf
target: '${APACHE_CONFDIR_PREFIX}/sites-available/default-ssl.conf'
- type: bind
source: ./phpmyadmin/apache2/ports.conf
target: '${APACHE_CONFDIR_PREFIX}/ports.conf'
- type: bind
source: ./phpmyadmin/ssl-option/options-ssl-apache.conf
target: '${LETSENCRYPT_CONF_PREFIX}/options-ssl-apache.conf'
- type: bind
source: ./phpmyadmin/config.user.inc.php
target: '${PMA_CONF_FOLDER}/config.user.inc.php'
- type: bind
source: ./phpmyadmin/php/conf.d/security.ini
target: '${PHP_INI_DIR_PREFIX}/php/conf.d/security.ini'
- 'certbot-etc:${LETSENCRYPT_CONF_PREFIX}'
hostname: phpmyadmin
restart: unless-stopped
ports:
- '9090:443'
links:
- database
environment:
PMA_HOST: 'database'
PMA_PMADB: 'phpmyadmin'
PMA_CONTROLUSER: '${PMA_CONTROLUSER}'
PMA_CONTROLPASS: '${PMA_CONTROLPASS}'
MYSQL_ROOT_PASSWORD: '${MYSQL_ROOT_PASSWORD}'
UPLOAD_LIMIT: '${PMA_UPLOAD_LIMIT}'
MEMORY_LIMIT: '${PMA_MEMORY_LIMIT}'
TZ: '${LOCAL_TIMEZONE}'
command: >
bash -c "echo ${PMA_HTPASSWD_USERNAME}:phpmyadmin:$$( printf \"%s:%s:%s\" \"${PMA_HTPASSWD_USERNAME}\" \"phpmyadmin\" \"${PMA_HTPASSWD_PASSWORD}\" | md5sum | awk '{print $$1}' ) > ${PMA_CONF_FOLDER}/.htpasswd
&& printf 'AuthType Digest\\nAuthName \"phpmyadmin\"\\nAuthDigestProvider file\\nAuthUserFile ${PMA_CONF_FOLDER}/.htpasswd\\nRequire valid-user\\n' > ${WEBSERVER_DOC_ROOT}/.htaccess && a2enmod auth_digest;
mkdir -p ${WEBSERVER_DOC_ROOT}/../upload && chown www-data:www-data ${WEBSERVER_DOC_ROOT}/../upload && chmod a+w ${WEBSERVER_DOC_ROOT}/../upload; mkdir -p ${WEBSERVER_DOC_ROOT}/../save && chown www-data:www-data ${WEBSERVER_DOC_ROOT}/../save && chmod a+w ${WEBSERVER_DOC_ROOT}/../save;
grep -qxF 'ServerName 127.0.0.1' ${APACHE_CONFDIR_PREFIX}/apache2.conf || echo -e '\\nServerName 127.0.0.1' >> ${APACHE_CONFDIR_PREFIX}/apache2.conf; grep -qe 'date.timezone = ${LOCAL_TIMEZONE}' ${PHP_INI_DIR_PREFIX}/php/conf.d/security.ini || echo 'date.timezone = ${LOCAL_TIMEZONE}' >> ${PHP_INI_DIR_PREFIX}/php/conf.d/security.ini;
a2enmod ssl && a2ensite default-ssl && a2dissite 000-default && /docker-entrypoint.sh 'apache2-foreground'"
database:
image: '${DATABASE_IMAGE_NAME}:${DATABASE_VERSION}'
container_name: database
networks:
- backend
volumes:
- 'db:/var/lib/mysql'
- 'db-backup-data:/tmp/backup'
- type: bind
source: ./database/conf.d/z-mysql.cnf
target: '${MYSQL_CONF_PREFIX}/z-mysql.cnf'
- 'phpmyadmin-sql:/docker-entrypoint-initdb.d'
hostname: database
restart: unless-stopped
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: '${MYSQL_ROOT_PASSWORD}'
MYSQL_DATABASE: '${DB_NAME}'
MYSQL_USER: '${DB_USER}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'No'
MYSQL_ROOT_HOST: '${MYSQL_ROOT_HOST}'
TZ: '${LOCAL_TIMEZONE}'
labels:
- "docker-volume-backup.stop-during-backup=true"
- "docker-volume-backup.archive-pre=/bin/sh -c 'mysqldump -uroot -p${MYSQL_ROOT_PASSWORD} --all-databases > /tmp/backup/db_backup_data.sql'"
- "docker-volume-backup.exec-label=database"
command: bash -c "apt-get -y update && apt-get install -y gettext-base && export PMA_CONTROLUSER=${PMA_CONTROLUSER} export PMA_CONTROLPASS=${PMA_CONTROLPASS} && envsubst '$$PMA_CONTROLUSER,$$PMA_CONTROLPASS' < /docker-entrypoint-initdb.d/create_tables.sql.template > /docker-entrypoint-initdb.d/create_tables.sql && docker-entrypoint.sh --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --default-authentication-plugin=mysql_native_password"
redis:
image: 'redis:latest'
container_name: redis
networks:
- backend
volumes:
- 'dtredis:/data'
- type: bind
source: ./redis
target: '${REDIS_CONF_PREFIX}/redis'
hostname: redis
sysctls:
- net.core.somaxconn=512
restart: unless-stopped
ports:
- '6379:6379'
environment:
ALLOW_EMPTY_PASSWORD: 'yes'
TZ: '${LOCAL_TIMEZONE}'
command: "redis-server ${REDIS_CONF_PREFIX}/redis/redis.conf"
backup:
image: offen/docker-volume-backup:latest
container_name: backup
networks:
- backend
volumes:
- 'html:/backup/html:ro'
- 'db:/backup/db:ro'
- 'db-backup-data:/backup/db-backup-data:ro'
- '/var/run/docker.sock:/var/run/docker.sock:ro'
- type: bind
source: ./backups
target: /archive
hostname: backup
restart: unless-stopped
environment:
BACKUP_CRON_EXPRESSION: '20 01 * * *'
BACKUP_FILENAME: 'backup-%Y-%m-%dT%H-%M-%S.tar.gz'
BACKUP_RETENTION_DAYS: '7'
EXEC_LABEL: 'database'
BACKUP_EXCLUDE_REGEXP: 'srv|\\.log$$'
networks:
backend: null
frontend: null
volumes:
html:
name: phalcon-html
driver: local
driver_opts:
type: none
device: ${DIRECTORY_PATH}/phalcon/html
o: bind
srv:
name: phalcon-srv
driver: local
driver_opts:
type: none
device: ${DIRECTORY_PATH}/phalcon/srv
o: bind
db:
name: ${DATABASE_CONT_NAME}-data
db-backup-data:
name: ${DATABASE_CONT_NAME}-backup-data
phpmyadmin-sql:
name: phpmyadmin-sql
driver: local
driver_opts:
type: none
device: ${DIRECTORY_PATH}/database/phpmyadmin/sql
o: bind
dtredis:
name: redis-data
certbot-etc:
external: true
certbot-var:
name: certbot-var