-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathDockerfile
More file actions
executable file
·142 lines (125 loc) · 3.85 KB
/
Dockerfile
File metadata and controls
executable file
·142 lines (125 loc) · 3.85 KB
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
# syntax=docker/dockerfile:1.4
# Stage 1: Builder Stage
FROM php:8.4.4-fpm-alpine AS builder
LABEL maintainer="Thomas Spicer (thomas@openbridge.com)"
# Set build arguments with default values
ARG IMAGICK_VERSION=3.7.0
# Install build dependencies more efficiently
RUN --mount=type=cache,target=/var/cache/apk \
apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
icu-dev \
freetype-dev \
imagemagick-dev \
ghostscript-dev \
libzip-dev \
libavif-dev \
libpng-dev \
libjpeg-turbo-dev \
libwebp-dev \
mariadb-dev \
gcc \
musl-dev \
make \
msgpack-c-dev \
&& apk add --no-cache \
icu-libs \
libzip \
imagemagick \
libjpeg-turbo \
libpng \
freetype \
libwebp \
bash \
openssl \
mariadb-client \
ca-certificates \
file
# Configure and install PHP extensions in a single layer
RUN --mount=type=cache,target=/tmp \
docker-php-ext-configure gd \
--with-freetype \
--with-avif \
--with-jpeg \
--with-webp \
&& docker-php-ext-install -j"$(nproc)" \
bcmath \
exif \
gd \
intl \
pdo_mysql \
mysqli \
zip \
# Install Imagick
&& curl -L -o /tmp/imagick.tar.gz https://github.com/Imagick/imagick/archive/tags/${IMAGICK_VERSION}.tar.gz \
&& tar --strip-components=1 -xf /tmp/imagick.tar.gz \
&& sed -i 's/php_strtolower/zend_str_tolower/g' imagick.c \
&& phpize \
&& ./configure \
&& make \
&& make install \
&& echo "extension=imagick.so" > /usr/local/etc/php/conf.d/ext-imagick.ini \
# Install Redis
&& pecl install redis msgpack \
&& docker-php-ext-enable redis msgpack mysqli pdo_mysql
# Install WP-CLI
RUN curl -o /usr/local/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
&& chmod +x /usr/local/bin/wp
# Clean up build dependencies
RUN apk del .build-deps \
&& rm -rf /tmp/* /var/cache/apk/*
# Stage 2: Final Image
FROM php:8.4.4-fpm-alpine
# Set environment variables
ENV LOG_PREFIX=/var/log/php-fpm \
TEMP_PREFIX=/tmp \
APP_DOCROOT=/usr/share/nginx/html \
CACHE_PREFIX=/var/cache
# Set working directory to NGINX_DOCROOT
WORKDIR ${APP_DOCROOT}
# Install runtime dependencies efficiently
RUN --mount=type=cache,target=/var/cache/apk \
apk add --no-cache \
bash \
autoconf \
ck \
hiredis \
hiredis-ssl \
lz4-libs \
zstd-libs \
icu-libs \
libzip \
imagemagick \
ghostscript \
openssl \
ca-certificates \
libjpeg-turbo \
libpng \
libavif \
libgomp \
freetype \
libwebp \
mariadb-client \
file \
tini \
msgpack-c
# Copy built extensions and tools from builder
COPY --from=builder /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/
COPY --from=builder /usr/local/etc/php/conf.d/ /usr/local/etc/php/conf.d/
COPY --from=builder /usr/local/bin/wp /usr/local/bin/wp
# Create necessary directories and configure logging
RUN mkdir -p /var/run/php-fpm "${LOG_PREFIX}" \
&& touch "${LOG_PREFIX}/access.log" "${LOG_PREFIX}/error.log" \
&& ln -sf /dev/stdout "${LOG_PREFIX}/access.log" \
&& ln -sf /dev/stderr "${LOG_PREFIX}/error.log"
# Copy configuration files and scripts
COPY --chmod=755 docker-entrypoint.sh /docker-entrypoint.sh
COPY --chmod=755 scripts/ /usr/src/plugins/
# Ensure www-data is the working user and owns the necessary directories
RUN set -ex \
&& id -u www-data || adduser -u 82 -D -S -G www-data www-data \
&& mkdir -p /usr/share/nginx/html \
&& chown -R www-data:www-data /usr/share/nginx/html
EXPOSE 9000
ENTRYPOINT ["/sbin/tini", "--", "/docker-entrypoint.sh"]
CMD ["php-fpm"]