-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
324 lines (234 loc) · 7.79 KB
/
Dockerfile
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
ARG PHP_VERSION=8.3.14
ARG MYSQL_VERSION=8.0.40
ARG NGINX_VERSION=1.27.2
ARG MARIADB_VERSION=10.11.9
ARG SOLR_VERSION=9
ARG VARNISH_VERSION=7.1
ARG UID=1000
ARG GID=${UID}
#######
# PHP #
#######
FROM php:${PHP_VERSION}-fpm-bookworm AS php
LABEL org.opencontainers.image.authors="[email protected]"
ARG UID
ARG COMPOSER_VERSION=2.8.1
ARG PHP_EXTENSION_INSTALLER_VERSION=2.6.0
ARG PHP_EXTENSION_REDIS_VERSION=6.1.0
SHELL ["/bin/bash", "-e", "-o", "pipefail", "-c"]
ENV APP_FFMPEG_PATH=/usr/bin/ffmpeg
ENV MYSQL_HOST=db
ENV MYSQL_PORT=3306
COPY --link docker/php/crontab.txt /crontab.txt
COPY --link docker/php/wait-for-it.sh /wait-for-it.sh
COPY --link docker/php/fpm.d/www.conf ${PHP_INI_DIR}-fpm.d/zz-www.conf
RUN <<EOF
apt-get --quiet update
apt-get --quiet --yes --purge --autoremove upgrade
# Packages - System
apt-get --quiet --yes --no-install-recommends --verbose-versions install \
less \
sudo \
git \
cron \
ffmpeg
rm -rf /var/lib/apt/lists/*
# User
addgroup --gid ${UID} php
adduser --home /home/php --shell /bin/bash --uid ${UID} --gecos php --ingroup php --disabled-password php
echo "php ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/php
# App
install --verbose --owner php --group php --mode 0755 --directory /app
/usr/bin/crontab -u php /crontab.txt
chmod +x /wait-for-it.sh
chown -R php:php /app
# Php extensions
curl -sSLf https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions \
--output /usr/local/bin/install-php-extensions
chmod +x /usr/local/bin/install-php-extensions
install-php-extensions \
@composer-${COMPOSER_VERSION} \
bcmath \
exif \
fileinfo \
gd \
gmp \
iconv \
intl \
json \
mbstring \
opcache \
openssl \
pcntl \
pdo_mysql \
simplexml \
xsl \
zip \
redis-${PHP_EXTENSION_REDIS_VERSION}
EOF
WORKDIR /app
###################
# PHP Development #
###################
FROM php AS php-dev
# If you depend on private Gitlab repositories, you must use a deploy token and username
# to use composer commands inside you
#ARG COMPOSER_DEPLOY_TOKEN
#ARG COMPOSER_DEPLOY_TOKEN_USER="gitlab+deploy-token-1"
ENV APP_ENV=dev
ENV APP_RUNTIME_ENV=dev
ENV APP_DEBUG=1
# Configs
RUN ln -sf ${PHP_INI_DIR}/php.ini-development ${PHP_INI_DIR}/php.ini
COPY --link docker/php/conf.d/php.dev.ini ${PHP_INI_DIR}/conf.d/zz-app.ini
COPY --link --chmod=755 docker/php/docker-php-entrypoint-dev /usr/local/bin/docker-php-entrypoint
COPY --link --chmod=755 docker/php/docker-cron-entrypoint-dev /usr/local/bin/docker-cron-entrypoint
RUN <<EOF
apt-get --quiet update
apt-get --quiet --yes --purge --autoremove upgrade
# Packages - System
apt-get --quiet --yes --no-install-recommends --verbose-versions install make
rm -rf /var/lib/apt/lists/*
# Prepare folder to install composer credentials
install --owner=php --group=php --mode=755 --directory /home/php/.composer
EOF
VOLUME /app
USER php
# If you depend on private Gitlab repositories, you must use a deploy token and username
#RUN composer config --global gitlab-token.gitlab.rezo-zero.com ${COMPOSER_DEPLOY_TOKEN_USER} ${COMPOSER_DEPLOY_TOKEN}
##################
# PHP Production #
##################
FROM php AS php-prod
# If you depend on private Gitlab repositories, you must use a deploy token and username
#ARG COMPOSER_DEPLOY_TOKEN
#ARG COMPOSER_DEPLOY_TOKEN_USER="gitlab+deploy-token-1"
ENV APP_ENV=prod
ENV APP_RUNTIME_ENV=prod
ENV APP_DEBUG=0
# Use production PHP configuration for maximum performances
# but you won't be able to edit node-type without restarting docker app
## Configs
RUN ln -sf ${PHP_INI_DIR}/php.ini-production ${PHP_INI_DIR}/php.ini
COPY --link docker/php/conf.d/php.prod.ini ${PHP_INI_DIR}/conf.d/zz-app.ini
COPY --link --chmod=755 docker/php/docker-php-entrypoint /usr/local/bin/docker-php-entrypoint
COPY --link --chmod=755 docker/php/docker-cron-entrypoint /usr/local/bin/docker-cron-entrypoint
USER php
# Composer
COPY --link --chown=php:php composer.* symfony.* ./
RUN <<EOF
# If you depend on private Gitlab repositories, you must use a deploy token and username
#composer config gitlab-token.gitlab.rezo-zero.com ${COMPOSER_DEPLOY_TOKEN_USER} ${COMPOSER_DEPLOY_TOKEN}
composer install --no-cache --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress
EOF
COPY --link --chown=php:php . .
RUN <<EOF
composer dump-autoload --classmap-authoritative --no-dev
bin/console cache:warmup --no-optional-warmers
bin/console assets:install
bin/console themes:assets:install Rozier
EOF
HEALTHCHECK --start-period=30s --interval=1m --timeout=6s CMD bin/console monitor:health -q
VOLUME /app/config/jwt \
/app/config/secrets \
/app/public/files \
/app/public/assets \
/app/var/files
#########
# Nginx #
#########
FROM nginx:${NGINX_VERSION}-bookworm AS nginx
LABEL org.opencontainers.image.authors="[email protected]"
ARG UID
SHELL ["/bin/bash", "-e", "-o", "pipefail", "-c"]
RUN <<EOF
# Packages
apt-get --quiet update
apt-get --quiet --yes --purge --autoremove upgrade
apt-get --quiet --yes --no-install-recommends --verbose-versions install \
less \
sudo
rm -rf /var/lib/apt/lists/*
# User
groupmod --gid ${UID} nginx
usermod --uid ${UID} nginx
echo "nginx ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/nginx
# App
install --verbose --owner nginx --group nginx --mode 0755 --directory /app
EOF
ENV NGINX_ENTRYPOINT_QUIET_LOGS=1
# Config
COPY --link docker/nginx/nginx.conf /etc/nginx/nginx.conf
COPY --link docker/nginx/redirections.conf /etc/nginx/redirections.conf
COPY --link docker/nginx/mime.types /etc/nginx/mime.types
COPY --link docker/nginx/conf.d/_gzip.conf /etc/nginx/conf.d/_gzip.conf
COPY --link docker/nginx/conf.d/_security.conf /etc/nginx/conf.d/_security.conf
COPY --link docker/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
WORKDIR /app
##############
# Nginx DEV #
##############
FROM nginx AS nginx-dev
# Silence entrypoint logs
# Declare a volume for development
VOLUME /app
##############
# Nginx PROD #
##############
FROM nginx AS nginx-prod
# Copy public files from API
COPY --link --from=php-prod --chown=${USER_UID}:${USER_UID} /app/public /app/public
# Only enable healthcheck in production when the app is ready to serve requests on root path
# This could prevent Traefik or an ingress controller to route traffic to the app
#HEALTHCHECK --start-period=1m30s --interval=1m --timeout=6s CMD curl --fail -I http://localhost
#########
# MySQL #
#########
FROM mysql:${MYSQL_VERSION} AS mysql
LABEL org.opencontainers.image.authors="[email protected]"
ARG UID
SHELL ["/bin/bash", "-e", "-o", "pipefail", "-c"]
RUN <<EOF
usermod -u ${UID} mysql
groupmod -g ${UID} mysql
echo "UID: ${UID}\n"
EOF
COPY --link docker/mysql/performances.cnf /etc/mysql/conf.d/performances.cnf
#############
# MariaDB #
#############
FROM mariadb:${MARIADB_VERSION} AS mariadb
LABEL org.opencontainers.image.authors="[email protected]"
ARG UID
ARG GID
COPY --link docker/mariadb/performances.cnf /etc/mariadb/conf.d/performances.cnf
RUN <<EOF
usermod -u ${UID} mysql
groupmod -g ${GID} mysql
EOF
########
# Solr #
########
FROM solr:${SOLR_VERSION}-slim AS solr
LABEL org.opencontainers.image.authors="[email protected]"
ARG UID
SHELL ["/bin/bash", "-e", "-o", "pipefail", "-c"]
USER root
RUN <<EOF
set -ex
echo "UID: ${UID}\n"
usermod -u ${UID} "$SOLR_USER"
groupmod -g ${UID} "$SOLR_GROUP"
chown -R ${UID}:${UID} /var/solr
EOF
COPY --link docker/solr/managed-schema.xml /opt/solr/server/solr/configsets/_default/conf/managed-schema
USER $SOLR_USER
# Redeclare VOLUME to change permissions
VOLUME /var/solr
###########
# Varnish #
###########
FROM varnish:${VARNISH_VERSION}-alpine AS varnish
LABEL org.opencontainers.image.authors="[email protected]"
ENV VARNISH_SIZE 256G
COPY --link docker/varnish/default.vcl /etc/varnish/