-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathDockerfile
More file actions
367 lines (334 loc) · 10.9 KB
/
Copy pathDockerfile
File metadata and controls
367 lines (334 loc) · 10.9 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# Pin php:8.5-alpine by multi-arch index digest. Bump with:
# docker buildx imagetools inspect php:8.5-alpine | head -2
ARG BASE_IMAGE="php:8.5-alpine@sha256:763e2dc50d4b0cf8d02a1d8fbeedd43f9be879c0be928b1d6f247d45c81fa28f"
FROM $BASE_IMAGE AS compile
# Every source is fetched by immutable reference — a commit SHA for git, a
# tarball checksum for PECL — because a tag can be repointed at any time. The
# version beside each reference is the release it was resolved from; the
# weekly updater rewrites both together.
ENV \
PHP_BROTLI_VERSION="0.21.0" \
PHP_BROTLI_COMMIT="ced23f5b6f52ef58a3a96d4731db4bee40a82736" \
PHP_IMAGICK_VERSION="3.8.1" \
PHP_IMAGICK_COMMIT="70087bab33eab913e99ac77d64d04d1a2fd0b7b0" \
PHP_LZ4_VERSION="0.7.1" \
PHP_LZ4_COMMIT="065a57d8fe237924d74efa3baedf231b7f837c3a" \
PHP_MAXMINDDB_VERSION="v1.13.1" \
PHP_MAXMINDDB_COMMIT="2194f58d0f024ce923e685cdf92af3daf9951908" \
PHP_MONGODB_VERSION="2.4.1" \
PHP_MONGODB_COMMIT="3d7e69fd9ed9ed3893b5a3fcdc204c6864ef2241" \
PHP_PROTOBUF_VERSION="5.36.0" \
PHP_PROTOBUF_CHECKSUM="bbf710ddc3b7ff53acfc327a7c0644d3632590c152567ff57e5d23f11bb8eba7" \
PHP_REDIS_VERSION="6.3.0" \
PHP_REDIS_COMMIT="df4fab2de7fc327c54c94a13af2b9542e4fbd720" \
PHP_SCRYPT_VERSION="2.0.2" \
PHP_SCRYPT_COMMIT="5a14bc766423dac3f868792fa8c41f85f47263ec" \
PHP_SNAPPY_VERSION="0.2.3" \
PHP_SNAPPY_COMMIT="d31b77d63955dbbf1a302ca13c4795292f91d140" \
PHP_SWOOLE_VERSION="v6.2.2" \
PHP_SWOOLE_COMMIT="8e8c49915ca5f9dcb9ee654f9e336a9c88dd375e" \
PHP_YAML_VERSION="2.3.0" \
PHP_YAML_COMMIT="c1f0d8ba5ef3884846261bbdb91c2ab0b07db44c" \
PHP_ZSTD_VERSION="0.18.0" \
PHP_ZSTD_COMMIT="c2593a4ce2457b23e7fa7f81ddf0dd9bbdd89b47"
# libcurl 8.22.0 fixes retained TLS shutdown sockets in the socket-action API
# used by Swoole's curl hook (curl/curl#22282). Require it here and at runtime.
RUN \
apk update && \
apk upgrade --no-cache && \
apk add --no-cache \
autoconf \
automake \
brotli-dev \
c-ares-dev \
curl \
'curl-dev>=8.22.0' \
g++ \
gcc \
git \
freetype-dev \
imagemagick-dev \
icu-dev \
libavif-dev \
libjpeg-turbo-dev \
libjxl-dev \
libwebp-dev \
libmaxminddb-dev \
libpng-dev \
linux-headers \
lz4-dev \
make \
openssl-dev \
postgresql-dev \
yaml-dev \
zlib-dev \
zstd-dev && \
mkdir -p /artifacts && \
docker-php-ext-install -j"$(nproc)" sockets
# Each builder stage emits a stripped .so to /artifacts/<name>.so so the
# final image doesn't need to know PHP's module-API date directory.
FROM compile AS redis
RUN \
git init redis && \
cd redis && \
git fetch --depth 1 https://github.com/phpredis/phpredis.git $PHP_REDIS_COMMIT && \
git checkout FETCH_HEAD && \
phpize && \
./configure && \
make -j"$(nproc)" && make install && \
cp $(php-config --extension-dir)/redis.so /artifacts/ && \
strip /artifacts/redis.so
FROM compile AS imagick
RUN \
git init imagick && \
cd imagick && \
git fetch --depth 1 https://github.com/imagick/imagick $PHP_IMAGICK_COMMIT && \
git checkout FETCH_HEAD && \
phpize && \
./configure && \
make -j"$(nproc)" && make install && \
cp $(php-config --extension-dir)/imagick.so /artifacts/ && \
strip /artifacts/imagick.so
FROM compile AS yaml
RUN \
git init yaml && \
cd yaml && \
git fetch --depth 1 https://github.com/php/pecl-file_formats-yaml $PHP_YAML_COMMIT && \
git checkout FETCH_HEAD && \
phpize && \
./configure && \
make -j"$(nproc)" && make install && \
cp $(php-config --extension-dir)/yaml.so /artifacts/ && \
strip /artifacts/yaml.so
FROM compile AS maxmind
RUN \
git init maxminddb && \
cd maxminddb && \
git fetch --depth 1 https://github.com/maxmind/MaxMind-DB-Reader-php.git $PHP_MAXMINDDB_COMMIT && \
git checkout FETCH_HEAD && \
cd ext && \
phpize && \
./configure && \
make -j"$(nproc)" && make install && \
cp $(php-config --extension-dir)/maxminddb.so /artifacts/ && \
strip /artifacts/maxminddb.so
FROM compile AS mongodb
RUN \
git init mongodb && \
cd mongodb && \
git fetch --depth 1 https://github.com/mongodb/mongo-php-driver.git $PHP_MONGODB_COMMIT && \
git checkout FETCH_HEAD && \
git submodule update --init && \
phpize && \
./configure && \
make -j"$(nproc)" && make install && \
cp $(php-config --extension-dir)/mongodb.so /artifacts/ && \
strip /artifacts/mongodb.so
FROM compile AS zstd
RUN \
git init zstd && \
cd zstd && \
git fetch --depth 1 https://github.com/kjdev/php-ext-zstd.git $PHP_ZSTD_COMMIT && \
git checkout FETCH_HEAD && \
git submodule update --init --recursive && \
phpize && \
./configure --with-libzstd && \
make -j"$(nproc)" && make install && \
cp $(php-config --extension-dir)/zstd.so /artifacts/ && \
strip /artifacts/zstd.so
FROM compile AS brotli
RUN \
git init brotli && \
cd brotli && \
git fetch --depth 1 https://github.com/kjdev/php-ext-brotli.git $PHP_BROTLI_COMMIT && \
git checkout FETCH_HEAD && \
phpize && \
./configure --with-libbrotli && \
make -j"$(nproc)" && make install && \
cp $(php-config --extension-dir)/brotli.so /artifacts/ && \
strip /artifacts/brotli.so
FROM compile AS lz4
RUN \
git init lz4 && \
cd lz4 && \
git fetch --depth 1 https://github.com/kjdev/php-ext-lz4.git $PHP_LZ4_COMMIT && \
git checkout FETCH_HEAD && \
git submodule update --init --recursive && \
phpize && \
./configure --with-lz4-includedir=/usr && \
make -j"$(nproc)" && make install && \
cp $(php-config --extension-dir)/lz4.so /artifacts/ && \
strip /artifacts/lz4.so
FROM compile AS snappy
RUN \
git init snappy && \
cd snappy && \
git fetch --depth 1 https://github.com/kjdev/php-ext-snappy.git $PHP_SNAPPY_COMMIT && \
git checkout FETCH_HEAD && \
git submodule update --init --recursive && \
phpize && \
./configure && \
make -j"$(nproc)" && make install && \
cp $(php-config --extension-dir)/snappy.so /artifacts/ && \
strip /artifacts/snappy.so
FROM compile AS scrypt
RUN \
git init scrypt && \
cd scrypt && \
git fetch --depth 1 https://github.com/DomBlack/php-scrypt.git $PHP_SCRYPT_COMMIT && \
git checkout FETCH_HEAD && \
phpize && \
./configure --enable-scrypt && \
make -j"$(nproc)" && make install && \
cp $(php-config --extension-dir)/scrypt.so /artifacts/ && \
strip /artifacts/scrypt.so
FROM compile AS protobuf
RUN curl -fsSL -o protobuf.tgz \
https://pecl.php.net/get/protobuf-${PHP_PROTOBUF_VERSION}.tgz && \
echo "${PHP_PROTOBUF_CHECKSUM} protobuf.tgz" | sha256sum -c - && \
MAKEFLAGS="-j$(nproc)" pecl install protobuf.tgz && \
cp $(php-config --extension-dir)/protobuf.so /artifacts/ && \
strip /artifacts/protobuf.so
FROM compile AS core-extensions
RUN docker-php-ext-configure gd \
--with-avif \
--with-freetype \
--with-jpeg \
--with-webp && \
docker-php-ext-install -j"$(nproc)" gd intl pdo_mysql pdo_pgsql && \
cp \
$(php-config --extension-dir)/gd.so \
$(php-config --extension-dir)/intl.so \
$(php-config --extension-dir)/pdo_mysql.so \
$(php-config --extension-dir)/pdo_pgsql.so \
$(php-config --extension-dir)/sockets.so \
/artifacts/ && \
strip \
/artifacts/gd.so \
/artifacts/intl.so \
/artifacts/pdo_mysql.so \
/artifacts/pdo_pgsql.so \
/artifacts/sockets.so
# Built without --enable-swoole-stdext: stdext registers user opcode
# handlers, which makes opcache's JIT refuse to enable in downstream images.
FROM compile AS swoole
RUN \
git init swoole && \
cd swoole && \
git fetch --depth 1 https://github.com/swoole/swoole-src.git $PHP_SWOOLE_COMMIT && \
git checkout FETCH_HEAD && \
phpize && \
./configure \
--enable-brotli \
--enable-cares \
--enable-mysqlnd \
--enable-openssl \
--enable-sockets \
--enable-swoole-curl \
--enable-swoole-pgsql \
--enable-zstd \
--with-openssl-dir=/usr && \
make -j"$(nproc)" && make install && \
cp $(php-config --extension-dir)/swoole.so /artifacts/ && \
strip /artifacts/swoole.so
FROM $BASE_IMAGE AS final
ARG BASE_IMAGE
LABEL base_image=$BASE_IMAGE
LABEL maintainer="team@appwrite.io"
RUN apk update && \
apk upgrade --no-cache && \
apk add --no-cache \
brotli \
c-ares \
certbot \
freetype \
docker-cli \
docker-cli-compose \
git \
icu-libs \
imagemagick \
imagemagick-heic \
libavif \
'libcurl>=8.22.0' \
libgomp \
libheif \
libjpeg-turbo \
libjxl \
libmaxminddb \
libpng \
libpq \
libstdc++ \
libwebp \
lz4-libs \
rsync \
yaml \
zip \
zstd-libs \
&& rm -rf /var/cache/apk/*
# Hardened ImageMagick policy — bounds per-decode width/height/disk so a crafted
# "image bomb" (small on disk, enormous when decoded) cannot exhaust memory or
# fill the disk and take down the container or its neighbours. Installed into
# ImageMagick's configure dir, discovered at build time so it survives package
# path changes; the build fails loudly if the policy does not load.
COPY policy.xml /tmp/policy.xml
RUN set -eux; \
POLICY_DIR="$(identify -list configure | awk '/^CONFIGURE_PATH/ {print $2}' | cut -d: -f1)"; \
cp /tmp/policy.xml "${POLICY_DIR%/}/policy.xml"; \
rm /tmp/policy.xml; \
identify -list policy | grep -q '50KP'
WORKDIR /usr/src/code
COPY --from=core-extensions /artifacts/ /tmp/exts/
COPY --from=brotli /artifacts/ /tmp/exts/
COPY --from=imagick /artifacts/ /tmp/exts/
COPY --from=lz4 /artifacts/ /tmp/exts/
COPY --from=maxmind /artifacts/ /tmp/exts/
COPY --from=mongodb /artifacts/ /tmp/exts/
COPY --from=protobuf /artifacts/ /tmp/exts/
COPY --from=redis /artifacts/ /tmp/exts/
COPY --from=scrypt /artifacts/ /tmp/exts/
COPY --from=snappy /artifacts/ /tmp/exts/
COPY --from=swoole /artifacts/ /tmp/exts/
COPY --from=yaml /artifacts/ /tmp/exts/
COPY --from=zstd /artifacts/ /tmp/exts/
RUN cp /tmp/exts/*.so $(php-config --extension-dir)/ && \
rm -rf /tmp/exts && \
docker-php-ext-enable \
brotli \
gd \
imagick \
intl \
lz4 \
maxminddb \
mongodb \
pdo_mysql \
pdo_pgsql \
protobuf \
redis \
scrypt \
snappy \
sockets \
swoole \
yaml \
zstd
EXPOSE 80
CMD [ "tail", "-f", "/dev/null" ]
# XDebug variant — build with: docker build --target xdebug -t appwrite/base:XYZ-xdebug .
FROM compile AS xdebug-build
ENV \
PHP_XDEBUG_VERSION="3.5.3" \
PHP_XDEBUG_COMMIT="127bbcb980400752221cfaa54bdc1420e6ef3c12"
RUN \
git init xdebug && \
cd xdebug && \
git fetch --depth 1 https://github.com/xdebug/xdebug $PHP_XDEBUG_COMMIT && \
git checkout FETCH_HEAD && \
phpize && \
./configure && \
make -j"$(nproc)" && make install && \
cp $(php-config --extension-dir)/xdebug.so /artifacts/ && \
strip /artifacts/xdebug.so
FROM final AS xdebug
COPY --from=xdebug-build /artifacts/xdebug.so /tmp/
RUN cp /tmp/xdebug.so $(php-config --extension-dir)/ && \
rm /tmp/xdebug.so && \
docker-php-ext-enable xdebug