-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdhi.alpine.fpm.wsc.Dockerfile
More file actions
209 lines (186 loc) · 6.75 KB
/
dhi.alpine.fpm.wsc.Dockerfile
File metadata and controls
209 lines (186 loc) · 6.75 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
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
# build: docker build --no-cache --progress=plain --build-arg PHP_VERSION=8.4 -t docker.io/tobi312/php:8.4-dhi-fpm-alpine-wsc -f dhi.alpine.fpm.wsc.Dockerfile .
# check: docker run --rm --name phpcheck -it docker.io/tobi312/php:8.4-dhi-fpm-alpine-wsc -m
# https://github.com/Tob1as/docker-php
#
# https://hub.docker.com/hardened-images/catalog/dhi/php | short: https://dhi.io/catalog/php
# https://github.com/docker-hardened-images/catalog
#
# WSC = WoltLab Suite Core <https://www.woltlab.com/en/>
# PHP Extensions Requirements:
# - https://manual.woltlab.com/en/requirements/#php-extensions
# - https://manual.woltlab.com/en/elasticsearch/#system-requirements
# - https://manual.woltlab.com/en/ldap/#system-requirements
# Note: Some PHP Extensions/Modules are installed by default:
# ctype curl dom intl libxml mbstring openssl opcache PDO zlib
# These are still needed: exif gd gmp imagick ldap pdo_mysql redis
#
ARG PHP_VERSION=8.4
ARG BUILD_PHP_VERSION=${PHP_VERSION}
ARG BUILD_OS=alpine3.22
# =========================
# Stage 0: Build Base Image
# =========================
FROM dhi.io/php:${BUILD_PHP_VERSION}${BUILD_OS:+-${BUILD_OS}}-dev AS dev
ARG BUILD_PHP_VERSION
# =========================
# Stage 1: Build Extensions
# =========================
FROM dev AS builder
ARG BUILD_PHP_VERSION
WORKDIR /tmp
# Install required system libraries for building PHP extensions
RUN apk add --no-cache \
git \
unzip \
autoconf \
build-base \
linux-headers \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
libxpm-dev \
freetype-dev \
icu-dev \
openldap-dev \
gmp-dev \
imagemagick-dev
# =========================
# Preparation:
# - remove existing extensions, such as opcache, so that
# they are not copied into the final image (again).
# =========================
RUN echo "" \
#&& ls ${PHP_PREFIX}/etc/php/conf.d/ \
&& rm -f ${PHP_PREFIX}/etc/php/conf.d/* \
&& VAR_PHP_EXTENSION_DIR=$(php -r "echo ini_get('extension_dir');") \
#&& ls ${VAR_PHP_EXTENSION_DIR} \
&& rm -f ${VAR_PHP_EXTENSION_DIR}/* \
&& echo ""
# =========================
# Core PHP Extensions
# =========================
# exif
RUN cd $PHP_SRC_DIR/ext/exif \
&& phpize \
&& ./configure \
&& make -j$(nproc) \
&& make install
# gd
RUN cd $PHP_SRC_DIR/ext/gd \
&& phpize \
&& ./configure \
#--with-avif \
--with-freetype \
--with-jpeg \
--with-webp \
#--with-xpm \
&& make -j$(nproc) \
&& make install
# gmp
RUN cd $PHP_SRC_DIR/ext/gmp \
&& phpize \
&& ./configure \
&& make -j$(nproc) \
&& make install
# ldap
RUN cd $PHP_SRC_DIR/ext/ldap \
&& phpize \
&& ./configure \
&& make -j$(nproc) \
&& make install
# pdo_mysql
RUN cd $PHP_SRC_DIR/ext/pdo_mysql \
&& phpize \
&& ./configure \
&& make -j$(nproc) \
&& make install
# =========================
# PECL Extensions
# =========================
WORKDIR /tmp
# Imagick <https://github.com/Imagick/imagick>
RUN pecl download imagick \
&& tar xzf imagick-*.tgz \
&& rm imagick-*.tgz \
&& cd imagick-* \
&& phpize \
&& ./configure \
&& make -j$(nproc) \
&& make install \
&& cd ..
# Redis <https://github.com/phpredis/phpredis/>
RUN pecl download redis \
&& tar xzf redis-*.tgz \
&& rm redis-*.tgz \
&& cd redis-* \
&& phpize \
&& ./configure \
&& make -j$(nproc) \
&& make install \
&& cd ..
# =========================
# Enable all extensions
# =========================
RUN echo "" \
&& echo "extension=exif.so" > $PHP_INI_DIR/conf.d/docker-php-ext-exif.ini \
&& echo "extension=gd.so" > $PHP_INI_DIR/conf.d/docker-php-ext-gd.ini \
&& echo "extension=gmp.so" > $PHP_INI_DIR/conf.d/docker-php-ext-gmp.ini \
&& echo "extension=ldap.so" > $PHP_INI_DIR/conf.d/docker-php-ext-ldap.ini \
&& echo "extension=pdo_mysql.so" > $PHP_INI_DIR/conf.d/docker-php-ext-pdo_mysql.ini \
&& echo "extension=imagick.so" > $PHP_INI_DIR/conf.d/docker-php-ext-imagick.ini \
&& echo "extension=redis.so" > $PHP_INI_DIR/conf.d/docker-php-ext-redis.ini \
&& echo ""
# =========================
# Stage 2: Package extractor
# =========================
# Inspired by: https://github.com/GoogleContainerTools/distroless/issues/863#issuecomment-986062361
# more see: https://github.com/Tob1as/docker-build-example/blob/main/distroless.debian.Dockerfile#L54-L100
FROM dev AS apk-extractor
WORKDIR /tmp
SHELL ["/bin/sh", "-o", "pipefail", "-c"]
# List of packages for download separated by spaces. (Helpful: https://pkgs.alpinelinux.org/contents)
ENV PACKAGE_LIST_LDAP='libldap libsasl'
ENV PACKAGE_LIST_GD="gmp libpng libwebp libjpeg-turbo freetype libsharpyuv libxpm libx11 libbz2 libxcb libxau libxdmcp libbsd libmd"
ENV PACKAGE_LIST_IMAGICK="libgomp imagemagick-libs lcms2 fftw-double-libs fontconfig libxext libltdl libexpat"
ENV PACKAGE_LIST="${PACKAGE_LIST_LDAP} ${PACKAGE_LIST_GD} ${PACKAGE_LIST_IMAGICK}"
# hadolint ignore=DL3008,DL3015,SC2086
RUN \
#apk fetch --no-cache --recursive $PACKAGE_LIST && \
apk fetch --no-cache $PACKAGE_LIST && \
mkdir -p /apkroot && \
for pkg in *.apk; do \
tar -xzf "$pkg" -C /apkroot; \
done && \
echo "Packages have been processed !"
# List directory and file structure
#RUN tree /apkroot
# Delete everything except libraries (*.so) that are required for PHP extensions
RUN find /apkroot -mindepth 1 \
! -path '/apkroot/usr' \
! -path '/apkroot/usr/lib' \
! -path '/apkroot/usr/lib/*' \
-exec rm -rf {} + \
&& find /apkroot -type f \( -name '*.a' -o -name '*.la' \) -exec rm -f {} +
# List directory and file structure
RUN tree /apkroot
# =========================
# Stage 3: DHI FPM Image
# =========================
FROM dhi.io/php:${BUILD_PHP_VERSION}${BUILD_OS:+-${BUILD_OS}}-fpm AS production
ARG BUILD_PHP_VERSION
#ARG BUILD_OS
ARG VCS_REF
ARG BUILD_DATE
LABEL org.opencontainers.image.authors="Tobias Hargesheimer <docker@ison.ws>" \
org.opencontainers.image.title="DHI PHP-FPM for WSC" \
org.opencontainers.image.description="DHI (Docker Hardened Images): Alpine with PHP-FPM ${BUILD_PHP_VERSION} for WSC (WoltLab Suite Core)" \
org.opencontainers.image.created="${BUILD_DATE}" \
org.opencontainers.image.revision="${VCS_REF}" \
org.opencontainers.image.licenses="Apache-2.0" \
org.opencontainers.image.url="https://hub.docker.com/r/tobi312/php" \
org.opencontainers.image.source="https://github.com/Tob1as/docker-php"
# Copy php extensions
COPY --from=builder ${PHP_PREFIX}/lib/php/extensions/ ${PHP_PREFIX}/lib/php/extensions/
COPY --from=builder ${PHP_PREFIX}/etc/php/conf.d/ ${PHP_PREFIX}/etc/php/conf.d/
# Copy the libraries from the extractor stage into root
COPY --from=apk-extractor /apkroot /