-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.production
136 lines (88 loc) · 4.55 KB
/
Dockerfile.production
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
ARG PHP_EXTS="bcmath pdo_mysql pdo_pgsql pcntl gd zip"
ARG PHP_PECL_EXTS="redis"
ARG MIX_ENCRYPTION_KEY
FROM composer:2.1 as composer_base
ARG PHP_EXTS
ARG PHP_PECL_EXTS
ARG MIX_ENCRYPTION_KEY
RUN mkdir -p /opt/apps/laravel-in-kubernetes /opt/apps/laravel-in-kubernetes/bin /opt/apps/laravel-in-kubernetes/app_versions
WORKDIR /opt/apps/laravel-in-kubernetes
RUN addgroup -S composer \
&& adduser -S composer -G composer \
&& chown -R composer /opt/apps/laravel-in-kubernetes \
&& apk add --virtual build-dependencies --no-cache ${PHPIZE_DEPS} openssl ca-certificates libxml2-dev oniguruma-dev postgresql-dev \
&& apk add --no-cache libpq libjpeg-turbo-dev libpng-dev libwebp-dev freetype-dev libzip-dev zip \
&& docker-php-ext-install -j$(nproc) ${PHP_EXTS} \
&& pecl install -f ${PHP_PECL_EXTS} \
&& docker-php-ext-enable ${PHP_PECL_EXTS} \
&& apk del build-dependencies
USER composer
COPY --chown=composer composer.json composer.lock ./
RUN composer install --no-dev --no-scripts --no-autoloader --prefer-dist
COPY --chown=composer . .
RUN composer install --no-dev --prefer-dist --optimize-autoloader
RUN ./getComposerInfo.sh
FROM node:16 as frontend
ARG MIX_ENCRYPTION_KEY
COPY --from=composer_base /opt/apps/laravel-in-kubernetes /opt/apps/laravel-in-kubernetes
WORKDIR /opt/apps/laravel-in-kubernetes
RUN npm install && \
npm run prod
RUN ./getNodeInfo.sh
FROM php:8-alpine as cli
ARG PHP_EXTS
ARG PHP_PECL_EXTS
ARG MIX_ENCRYPTION_KEY
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
COPY docker/opcache.ini $PHP_INI_DIR/conf.d/opcache.ini
COPY docker/custom_php.ini $PHP_INI_DIR/conf.d/custom_php.ini
WORKDIR /opt/apps/laravel-in-kubernetes
RUN apk add --virtual build-dependencies --no-cache ${PHPIZE_DEPS} openssl ca-certificates libxml2-dev oniguruma-dev postgresql-dev && \
apk add --no-cache libpq libjpeg-turbo-dev libpng-dev libwebp-dev freetype-dev libzip-dev zip && \
docker-php-ext-install -j$(nproc) ${PHP_EXTS} && \
pecl install -f ${PHP_PECL_EXTS} && \
docker-php-ext-enable ${PHP_PECL_EXTS} && \
apk del build-dependencies
COPY --from=composer_base /opt/apps/laravel-in-kubernetes /opt/apps/laravel-in-kubernetes
COPY --from=frontend /opt/apps/laravel-in-kubernetes/public /opt/apps/laravel-in-kubernetes/public
FROM php:8.1-fpm-alpine as fpm_server
ARG PHP_EXTS
ARG PHP_PECL_EXTS
ARG MIX_ENCRYPTION_KEY
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
COPY docker/opcache.ini $PHP_INI_DIR/conf.d/opcache.ini
COPY docker/custom_php.ini $PHP_INI_DIR/conf.d/custom_php.ini
RUN echo "pm = static" >> /usr/local/etc/php-fpm.d/zz-docker.conf
RUN echo "pm.max_children = 20" >> /usr/local/etc/php-fpm.d/zz-docker.conf
RUN echo "pm.max_requests = 1000" >> /usr/local/etc/php-fpm.d/zz-docker.conf
RUN echo "pm.status_path = /status" >> /usr/local/etc/php-fpm.d/zz-docker.conf
WORKDIR /opt/apps/laravel-in-kubernetes
RUN apk add --virtual build-dependencies --no-cache ${PHPIZE_DEPS} openssl ca-certificates libxml2-dev oniguruma-dev postgresql-dev && \
apk add --no-cache libpq libjpeg-turbo-dev libpng-dev libwebp-dev freetype-dev libzip-dev zip && \
docker-php-ext-install -j$(nproc) ${PHP_EXTS} && \
pecl install -f ${PHP_PECL_EXTS} && \
docker-php-ext-enable ${PHP_PECL_EXTS} && \
apk del build-dependencies
USER www-data
COPY --from=composer_base --chown=www-data /opt/apps/laravel-in-kubernetes /opt/apps/laravel-in-kubernetes
COPY --from=frontend --chown=www-data /opt/apps/laravel-in-kubernetes/public /opt/apps/laravel-in-kubernetes/public
COPY --from=frontend --chown=www-data /opt/apps/laravel-in-kubernetes/app_versions/ /opt/apps/laravel-in-kubernetes/app_versions/
RUN php artisan event:cache && \
php artisan route:cache && \
php artisan view:cache
FROM nginx:1.20-alpine as web_server
WORKDIR /opt/apps/laravel-in-kubernetes
COPY docker/nginx.conf.template /etc/nginx/templates/default.conf.template
COPY --from=frontend /opt/apps/laravel-in-kubernetes/public /opt/apps/laravel-in-kubernetes/public
FROM cli as cron
WORKDIR /opt/apps/laravel-in-kubernetes
RUN touch laravel.cron && \
echo "* * * * * cd /opt/apps/laravel-in-kubernetes && php artisan schedule:run" >> laravel.cron && \
echo "@reboot cd /opt/apps/laravel-in-kubernetes && php artisan optimize:clear" >> laravel.cron && \
crontab laravel.cron
CMD ["crond", "-l", "2", "-f"]
FROM cli as horizon
WORKDIR /opt/apps/laravel-in-kubernetes
RUN apk add --no-cache supervisor
COPY docker/supervisord.conf /etc/supervisord.conf
ENTRYPOINT ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]