-
Notifications
You must be signed in to change notification settings - Fork 1
/
DockerfileProduction
103 lines (77 loc) · 3.12 KB
/
DockerfileProduction
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
FROM php:8.1-rc-fpm-alpine AS php_fpm
#
## Stage: All basic dependencies and settings used accross workers and apis (fpm)
##
RUN apk add --no-cache \
libxml2-dev \
# for gd:
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
# for pdo_pgsql:
postgresql-dev
# `mbstring` is not needed, already configured in base image for php-alpine
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install opcache \
gd xml \
pdo pdo_pgsql pcntl \
bcmath \
intl \
&& docker-php-source delete
RUN mkdir /tmp/php-opcache && chown -R www-data /tmp/php-opcache
# todo: add supervisor only to worker, but currently this then gets reinstalled every build
RUN apk add --no-cache supervisor
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN sed -i '/^;pm.status_path/s/^;//' /usr/local/etc/php-fpm.d/www.conf
#RUN sed -i '/^;clear_env/s/^;//' /usr/local/etc/php-fpm.d/www.conf
RUN sed -i -e 's/expose_php = On/expose_php = Off/' "$PHP_INI_DIR/php.ini"
RUN sed -i 's/^max_execution_time .*$/max_execution_time = 60/' "$PHP_INI_DIR/php.ini"
RUN sed -i 's/^max_input_time .*$/max_input_time = 60/' "$PHP_INI_DIR/php.ini"
RUN sed -i 's/^memory_limit .*$/memory_limit = 512M/' "$PHP_INI_DIR/php.ini"
RUN sed -i 's/^upload_max_filesize .*$/upload_max_filesize = 256M/' "$PHP_INI_DIR/php.ini"
RUN sed -i 's/^max_file_uploads .*$/max_file_uploads = 20/' "$PHP_INI_DIR/php.ini"
RUN sed -i 's/^variables_order .*$/variables_order = "EGPCS"/' "$PHP_INI_DIR/php.ini"
COPY ./_docker/docker-opcache--prod.ini /usr/local/etc/php/conf.d/custom-opcache.ini
COPY ./composer.json /var/www/html/composer.json
COPY ./composer.lock /var/www/html/composer.lock
#
## Stage: composer dependencies
##
FROM composer as php_vendor
# this copies only `composer.json` and `.lock`
COPY --from=php_fpm /var/www/html /app
RUN composer install --no-ansi --no-dev --no-interaction --no-plugins --no-progress --no-scripts --optimize-autoloader --ignore-platform-reqs
#
## Stage: Make Bundled App
##
FROM php_fpm as php_build
# build:
COPY ./ /var/www/html
RUN rm -rf /var/www/html/vendor
COPY --from=php_vendor /app/vendor /var/www/html/vendor
RUN rm -rf /var/www/html/tmp
RUN chown -R www-data:www-data /var/www/html
RUN find /var/www/html -type f -exec chmod 660 {} + -o -type d -exec chmod 770 {} +
RUN cd /var/www/html && \
php cli demo && \
rm -rf tmp
# :build
RUN mkdir /var/www/html/tmp && chown -R www-data:www-data /var/www/html/tmp
#
## Stage: Crontab Worker Image - Final
##
FROM php_fpm as php_worker
COPY --from=php_build /var/www/html /var/www/html
RUN rm /usr/local/etc/php-fpm.conf && rm /usr/local/etc/php-fpm.conf.default \
&& rm -rf /usr/local/etc/php-fpm.d
COPY ./_docker/docker_supervisor.conf /etc/supervisor.conf
WORKDIR /var/www/html
ENTRYPOINT ["docker-php-entrypoint"]
CMD ["supervisord", "-c", "/etc/supervisor.conf"]
#
## Stage: PHP-FPM Image - Final
##
FROM php_fpm as php_api
COPY --from=php_build /var/www/html /var/www/html
RUN set -ex && apk --no-cache add sudo
CMD ["sh", "-c", "cd /var/www/html && sudo -E -u www-data php cli warmup ; php-fpm"]