-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
build.Dockerfile
executable file
·108 lines (101 loc) · 3.55 KB
/
build.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
ARG PHP_VERSION=8.1
# -fpm-alpine3.16
FROM php:${PHP_VERSION}-fpm-alpine as build
ARG DOCKER_ENV=dev
ARG APP_DIRECTORY=/var/www/ranky-media-bundle
ARG HOST_UID=1000
ARG HOST_GID=1000
ARG APP_USER=appuser
ARG APP_GROUP=appgroup
ARG INSTALL_PHP_XDEBUG=false
RUN apk add --no-cache --update-cache $PHPIZE_DEPS \
curl \
bash \
git \
### usermod change uid & gid
shadow \
### pdo_pgsql
libpq libpq-dev \
### Intl
icu icu-dev icu-libs icu-data-full \
### Not remember. Encryption maybe
gnupg \
### ZIP
zip unzip libzip-dev \
### ffmpeg
ffmpeg \
### imagick
imagemagick imagemagick-dev \
### GD
freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev \
### Image Optimize
jpegoptim optipng pngquant gifsicle libwebp libwebp-tools \
### Xml
libxml2-dev && \
### php extensions \
#docker-php-ext-install -j$(nproc) iconv && \
docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql && \
docker-php-ext-configure gd --with-jpeg=/usr/include/ --with-freetype=/usr/include/ && \
docker-php-ext-install -j$(nproc) gd && \
docker-php-ext-configure intl && \
docker-php-ext-configure zip && \
docker-php-ext-install zip intl xml opcache pdo pdo_mysql pgsql pdo_pgsql && \
### enable imagick
pecl install imagick && \
docker-php-ext-enable imagick && \
### enable apcu
pecl install apcu-5.1.21 && \
docker-php-ext-enable apcu
RUN if [ "$DOCKER_ENV" = "dev" ] && [ "$INSTALL_PHP_XDEBUG" = "true" ]; then \
pecl install xdebug-3.1.3 && \
docker-php-ext-enable xdebug; \
fi
### Clean ###
RUN apk del $PHPIZE_DEPS && \
apk del --no-cache icu-dev libxml2-dev libpq-dev freetype-dev libpng-dev libjpeg-turbo-dev imagemagick-dev && \
rm -rf /var/cache/apk/* /tmp/* /var/tmp/* /usr/share/doc/*
### composer ###
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
## Create user & group ###
## -D - no password ###
ARG HOME_DIR=/home/${APP_USER}
RUN addgroup -g ${HOST_GID} ${APP_GROUP} && \
adduser -G ${APP_GROUP} -u ${HOST_UID} ${APP_USER} -D --shell /bin/bash --home ${HOME_DIR} && \
## Add user current user to www-data group
usermod -a -G www-data `whoami` && \
## Add user appuser to www-data group
usermod -a -G www-data ${APP_USER} && \
chmod +x /usr/bin/composer && \
mkdir -p ${APP_DIRECTORY} && \
chown -R ${HOST_UID}:${HOST_GID} ${APP_DIRECTORY}
### php-fpm config ###
RUN rm /usr/local/etc/php-fpm.d/* && \
rm -f $PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini && \
touch /var/log/php-fpm.log && \
touch /var/log/php-errors.log && \
chown -R www-data:www-data /var/log/php-*.log
COPY ./tools/docker/php-fpm/www.conf /usr/local/etc/php-fpm.d/www.conf
WORKDIR ${APP_DIRECTORY}
### development ###
FROM build as final
ARG DOCKER_ENV=dev
ARG APP_DIRECTORY=/var/www/ranky-media-bundle
ARG HOST_UID=1000
ARG HOST_GID=1000
ARG APP_USER=appuser
ARG APP_GROUP=appgroup
ARG INSTALL_PHP_XDEBUG=false
COPY ./composer.* ${APP_DIRECTORY}/
COPY ./tools ${APP_DIRECTORY}/tools
# $PHP_INI_DIR => /usr/local/etc/php
RUN mv $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini && \
rm -f $PHP_INI_DIR/php.ini-production && \
chown -R ${HOST_UID}:${HOST_GID} /var/www
COPY ./tools/docker/php-fpm/app.ini $PHP_INI_DIR/conf.d/php.ini
RUN if [ "$DOCKER_ENV" = "dev" ] && [ "$INSTALL_PHP_XDEBUG" = "true" ]; then \
echo 'zend_extension=xdebug' >> $PHP_INI_DIR/conf.d/php.ini; \
fi
COPY --chmod=+x ./tools/docker/php-fpm/entrypoint.sh /entrypoint.sh
USER ${APP_USER}
ENTRYPOINT ["/entrypoint.sh"]
CMD ["php-fpm"]