-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDockerfile
455 lines (425 loc) · 16.6 KB
/
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
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# syntax=docker/dockerfile:labs
FROM --platform=$TARGETPLATFORM alpine:3.20 as php
LABEL maintainer="khs1994-docker/lnmp <[email protected]>"
ARG PHP_VCS_REF="master"
LABEL com.github.php.php-src.revision=$PHP_VCS_REF
ENV TZ=Asia/Shanghai \
APP_ENV=development
ARG PHP_VERSION=nightly
ARG ALPINE_URL=dl-cdn.alpinelinux.org
ARG PHP_EXTENSION_EXTRA
ARG PECL_EXTENSION_EXTRA
ARG APK_EXTRA
ARG APK_DEV_EXTRA
# dependencies required for running "phpize"
# these get automatically installed and removed by "docker-php-ext-*" (unless they're already installed)
ENV PHPIZE_DEPS \
autoconf \
dpkg-dev dpkg \
file \
g++ \
gcc \
make \
pkgconf \
re2c
# persistent / runtime deps
RUN set -ex \
&& sed -i "s/dl-cdn.alpinelinux.org/${ALPINE_URL}/g" /etc/apk/repositories \
&& apk add --no-cache \
ca-certificates \
curl \
tar \
xz \
# https://github.com/docker-library/php/issues/494
openssl \
bash \
tzdata \
# ensure www-data user exists
# RUN set -x \
&& adduser -u 82 -D -S -G www-data www-data
# 82 is the standard uid/gid for "www-data" in Alpine
# http://git.alpinelinux.org/cgit/aports/tree/main/apache2/apache2.pre-install?h=v3.3.2
# http://git.alpinelinux.org/cgit/aports/tree/main/lighttpd/lighttpd.pre-install?h=v3.3.2
# http://git.alpinelinux.org/cgit/aports/tree/main/nginx-initscripts/nginx-initscripts.pre-install?h=v3.3.2
ENV PHP_INI_DIR /usr/local/etc/php
# RUN mkdir -p $PHP_INI_DIR/conf.d
##<autogenerated>##
ENV PHP_EXTRA_CONFIGURE_ARGS \
--disable-phpdbg \
# https://github.com/docker-library/php/issues/510
# --enable-embed=shared \
--enable-fpm \
--with-fpm-user=www-data \
--with-fpm-group=www-data \
--disable-cgi \
--with-gettext=shared \
--enable-gd=shared \
--with-freetype \
--disable-gd-jis-conv \
--with-jpeg \
--with-webp \
--with-xpm \
--with-avif \
--enable-pdo=shared \
--with-pdo-sqlite=shared,/usr \
--with-pdo-mysql=shared \
--with-pdo-pgsql=shared \
# --with-xsl=shared \
--enable-bcmath=shared \
--enable-pcntl=shared \
--with-external-pcre \
--enable-shmop=shared \
# --enable-soap=shared \
--enable-sockets=shared \
--enable-sysvmsg=shared \
--enable-sysvsem=shared \
--enable-sysvshm=shared \
--with-zip=shared \
--enable-calendar=shared \
--enable-intl=shared \
--enable-exif=shared \
--with-bz2=shared \
# --with-tidy=shared \
--with-gmp=shared \
# --with-imap=shared \ # 8.4 removed # https://hub.nuaa.cf/php/php-src/commit/f62f6a6d4b9567530775d684db55e9990952c737
# --with-imap-ssl \
# --with-kerberos \
--with-pic \
--with-enchant=shared \
--enable-fileinfo=shared \
--with-ldap=shared \
--with-ldap-sasl \
# --with-pspell=shared \ # 8.4 removed # https://hub.nuaa.cf/php/php-src/commit/b035cb6c8e31bea351f169b3e9f34fdc562e77e1
--enable-shmop=shared \
# --with-snmp=shared \
--with-mysqli=shared \
--with-pgsql=shared \
--with-ffi=shared \
--with-iconv=/usr
##</autogenerated>##
# Apply stack smash protection to functions using local buffers and alloca()
# Make PHP's main executable position-independent (improves ASLR security mechanism, and has no performance impact on x86_64)
# Enable optimization (-O2)
# Enable linker optimization (this sorts the hash buckets to improve cache locality, and is non-default)
# Adds GNU HASH segments to generated executables (this is used if present, and is much faster than sysv hash; in this configuration, sysv hash is also generated)
# https://github.com/docker-library/php/issues/272
ENV PHP_CFLAGS="-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
ENV PHP_CPPFLAGS="$PHP_CFLAGS"
ENV PHP_LDFLAGS="-Wl,-O1 -pie"
# ENV GPG_KEYS CBAF69F173A0FEA4B537F470D66C9593118BCCB6 F38252826ACD957EF380D39F2F7956BC5DA04B5D
# ENV PHP_VERSION 7.3.0beta2
# ENV PHP_URL="https://downloads.php.net/~cmb/php-7.3.0beta2.tar.xz" PHP_ASC_URL="https://downloads.php.net/~cmb/php-7.3.0beta2.tar.xz.asc"
# ENV PHP_SHA256="32670f40aecce130727d841e3191d30237caff643a239d3c16cd579e762bc4c6" PHP_MD5=""
# COPY --from=php:alpine /usr/local/bin/docker-php-* /usr/local/bin/
# COPY --from=php:alpine /usr/local/bin/docker-php-source /usr/local/bin/
# COPY --from=php:alpine /usr/local/bin/docker-php-entrypoint /usr/local/bin/
# COPY --from=php:alpine /usr/local/bin/docker-php-ext-configure /usr/local/bin/
# COPY --from=php:alpine /usr/local/bin/docker-php-ext-enable /usr/local/bin/
# COPY --from=php:alpine /usr/local/bin/docker-php-ext-install /usr/local/bin/
ARG PHP_GIT=https://github.com/php/php-src.git
# ARG PHP_GIT=https://suiyiyu.us.kg.cnpmjs.org/php/php-src
RUN --mount=type=bind,from=php:fpm-alpine,source=/usr/local/bin,target=/opt/bin,rw \
set -xe \
\
&& export PATH=$PATH:/opt/bin \
; cp /opt/bin/docker-php-entrypoint /usr/local/bin \
\
; mkdir -p $PHP_INI_DIR/conf.d \
# && apk add --no-cache --virtual .fetch-deps gnupg \
&& mkdir -p /usr/src \
&& cd /usr/src \
&& apk add --no-cache git openssh-client \
&& if ! [ -z "${PHP_VCS_REF}" -o "${PHP_VCS_REF}" = 'master' ];then \
export FETCH_DEPTH=100; \
fi \
\
&& git clone --depth=${FETCH_DEPTH:-15} ${PHP_GIT} php \
&& git -C php reset --hard ${PHP_VCS_REF} \
\
&& apk del --no-network git openssh-client \
# wget -O php.tar.xz "$PHP_URL"; \
# if [ -n "$PHP_SHA256" ]; then \
# echo "$PHP_SHA256 *php.tar.xz" | sha256sum -c -; \
# fi; \
# if [ -n "$PHP_MD5" ]; then \
# echo "$PHP_MD5 *php.tar.xz" | md5sum -c -; \
# fi; \
# \
# if [ -n "$PHP_ASC_URL" ]; then \
# wget -O php.tar.xz.asc "$PHP_ASC_URL"; \
# export GNUPGHOME="$(mktemp -d)"; \
# for key in $GPG_KEYS; do \
# gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
# done; \
# gpg --batch --verify php.tar.xz.asc php.tar.xz; \
# command -v gpgconf > /dev/null && gpgconf --kill all; \
# rm -rf "$GNUPGHOME"; \
# fi; \
# && apk del --no-network .fetch-deps \
&& apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
argon2-dev \
coreutils \
curl-dev \
libsodium-dev \
libxml2-dev \
linux-headers \
oniguruma-dev \
openssl-dev \
readline-dev \
sqlite-dev \
cyrus-sasl-dev \
postgresql-dev \
libzip-dev \
zlib-dev \
libpng-dev \
freetype-dev \
libjpeg-turbo-dev \
libwebp-dev \
libxpm-dev \
libexif-dev \
# libxslt-dev \
gmp-dev \
bzip2-dev \
enchant2-dev \
# imap-dev \ # 8.4 removed # https://hub.nuaa.cf/php/php-src/commit/f62f6a6d4b9567530775d684db55e9990952c737
gettext-dev \
icu-dev \
krb5-dev \
aspell-dev \
openldap-dev \
pcre2-dev \
# tidyhtml-dev \
# net-snmp-dev \
openldap-dev \
libavif-dev \
\
bison \
gnu-libiconv-dev \
${APK_DEV_EXTRA:-} \
\
&& rm -vf /usr/include/iconv.h \
&& export CFLAGS="$PHP_CFLAGS" \
CPPFLAGS="$PHP_CPPFLAGS" \
LDFLAGS="$PHP_LDFLAGS" \
PHP_BUILD_PROVIDER='https://github.com/khs1994-docker/php' \
PHP_UNAME='Linux - Docker' \
ARGON2_LIBS="-largon2" \
ARGON2_CFLAGS="-I/usr/include" \
# && docker-php-source extract \
&& cd /usr/src/php \
&& make clean || true \
&& gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \
&& ./buildconf --force \
&& ./configure \
--build="$gnuArch" \
--with-config-file-path="$PHP_INI_DIR" \
--with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
\
# make sure invalid --configure-flags are fatal errors instead of just warnings
--enable-option-checking=fatal \
\
# https://github.com/docker-library/php/issues/439
--with-mhash \
\
# --enable-ftp is included here because ftp_ssl_connect() needs ftp to be compiled statically (see https://github.com/docker-library/php/issues/236)
--enable-ftp \
# --enable-mbstring is included here because otherwise there's no way to get pecl to use it properly (see https://github.com/docker-library/php/issues/195)
--enable-mbstring \
# --enable-mysqlnd is included here because it's harder to compile after the fact than extensions are (since it's a plugin for several extensions, not an extension in itself)
--enable-mysqlnd=shared \
# https://wiki.php.net/rfc/libsodium
--with-sodium=shared \
\
--with-curl \
--with-openssl=shared \
--with-system-ciphers \
--with-readline \
--with-zlib \
# https://wiki.php.net/rfc/argon2_password_hash (7.2+)
--with-password-argon2 \
\
# bundled pcre does not support JIT on s390x
# https://manpages.debian.org/stretch/libpcre3-dev/pcrejit.3.en.html#AVAILABILITY_OF_JIT_SUPPORT
$(test "$gnuArch" = 's390x-linux-musl' && echo '--without-pcre-jit') \
\
$PHP_EXTRA_CONFIGURE_ARGS \
&& make -j "$(nproc)" \
&& find -type f -name '*.a' -delete \
&& make install \
&& { find /usr/local/bin /usr/local/sbin -type f -perm +0111 -exec strip --strip-all '{}' + || true; } \
&& make clean \
&& cp -v php.ini-* "$PHP_INI_DIR/" \
&& cd / \
# && docker-php-source delete \
# && rm -rf /usr/src/php \
&& docker-php-ext-enable bcmath \
bz2 \
calendar \
enchant \
# exif \
fileinfo \
# gd \
gettext \
gmp \
# imap \ # 8.4 removed # https://hub.nuaa.cf/php/php-src/commit/f62f6a6d4b9567530775d684db55e9990952c737
intl \
pcntl \
openssl \
mysqlnd \
# mysqli \
pdo \
pdo_sqlite \
pdo_mysql \
pdo_pgsql \
pgsql \
# pspell \ # 8.4 removed # https://hub.nuaa.cf/php/php-src/commit/b035cb6c8e31bea351f169b3e9f34fdc562e77e1
shmop \
# snmp \
# soap \
sodium \
sockets \
sysvmsg \
sysvsem \
sysvshm \
# tidy \
# xsl \
# opcache 已默认安装,需要自行载入
opcache \
zip \
ffi \
${PHP_EXTENSION_EXTRA:-} \
&& echo "extension=exif" > $PHP_INI_DIR/conf.d/docker-php-ext-z-exif.ini \
&& echo "extension=gd" > $PHP_INI_DIR/conf.d/docker-php-ext-z-gd.ini \
&& echo "extension=mysqli" > $PHP_INI_DIR/conf.d/docker-php-ext-z-mysqli.ini \
&& runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)" \
&& apk add --no-cache $runDeps \
\
# && { find $(php-config --extension-dir) -type f -perm +0111 -exec strip --strip-all '{}' + || true; } \
&& apk del --no-network .build-deps \
&& rm -rf /usr/local/include/php/TSRM/tsrm_win32.h \
/usr/local/include/php/TSRM/tsrm_config.w32.h \
/usr/local/include/php/Zend/zend_config.w32.h \
/usr/local/include/php/ext/mysqlnd/config-win.h \
/usr/local/include/php/ext/standard/winver.h \
/usr/local/php/man \
\
# sodium was built as a shared module (so that it can be replaced later if so desired), so let's enable it too (https://github.com/docker-library/php/issues/598)
# RUN docker-php-ext-enable sodium
\
# ENTRYPOINT ["docker-php-entrypoint"]
\
# RUN set -ex \
&& cd /usr/local/etc \
&& if [ -d php-fpm.d ]; then \
# for some reason, upstream's php-fpm.conf.default has "include=NONE/etc/php-fpm.d/*.conf"
sed 's!=NONE/!=!g' php-fpm.conf.default | tee php-fpm.conf > /dev/null; \
cp php-fpm.d/www.conf.default php-fpm.d/www.conf; \
else \
# PHP 5.x doesn't use "include=" by default, so we'll create our own simple config that mimics PHP 7+ for consistency
mkdir php-fpm.d; \
cp php-fpm.conf.default php-fpm.d/www.conf; \
{ \
echo '[global]'; \
echo 'include=etc/php-fpm.d/*.conf'; \
} | tee php-fpm.conf; \
fi \
&& { \
echo '[global]'; \
echo 'error_log = /proc/self/fd/2'; \
echo; echo '; https://github.com/docker-library/php/pull/725#issuecomment-443540114'; echo 'log_limit = 8192'; \
echo; \
echo '[www]'; \
echo '; if we send this to /proc/self/fd/1, it never appears'; \
echo 'access.log = /proc/self/fd/2'; \
echo; \
echo 'clear_env = no'; \
echo; \
echo '; Ensure worker stdout and stderr are sent to the main error log.'; \
echo 'catch_workers_output = yes'; \
echo 'decorate_workers_output = no'; \
} | tee php-fpm.d/docker.conf \
&& { \
echo '[global]'; \
echo 'daemonize = no'; \
echo; \
echo '[www]'; \
echo 'listen = 9000'; \
} | tee php-fpm.d/zz-docker.conf \
# 创建日志文件夹
&& mkdir -p /var/log/php-fpm \
&& ln -sf /dev/stdout /var/log/php-fpm/access.log \
&& ln -sf /dev/stderr /var/log/php-fpm/error.log \
&& ln -sf /dev/stderr /var/log/php-fpm/xdebug-remote.log \
&& chmod -R 777 /var/log/php-fpm \
&& rm -rf /usr/src/php \
&& curl -fsSL -o /usr/local/bin/pickle \
https://github.com/khs1994-php/pickle/releases/download/nightly/pickle-debug.phar \
&& chmod +x /usr/local/bin/pickle
ENTRYPOINT ["docker-php-entrypoint"]
ENV PECL_BUILD_DEPS \
libmemcached-dev \
# yaml-dev \
pcre2-dev \
zlib-dev \
zstd-dev \
# https://github.com/xdebug/xdebug/pull/835
linux-headers
ENV PECL_RUN_DEPS \
libmemcached-libs \
# yaml \
zlib \
zstd-libs
ENV PECL_EXTENSION \
# mongodb \
# https://github.com/mongodb/mongo-php-driver/archive/master.tar.gz \
# igbinary \
https://github.com/igbinary/igbinary/archive/master.tar.gz \
# redis \
https://github.com/phpredis/phpredis/archive/develop.tar.gz \
memcached \
# xdebug-beta \
# yaml \
# https://github.com/php/pecl-file_formats-yaml/archive/php7.tar.gz \
https://github.com/kjdev/php-ext-zstd/archive/0.11.0.tar.gz \
${PECL_EXTENSION_EXTRA:-}
RUN --mount=type=bind,from=php:alpine,source=/usr/local/bin,target=/opt/bin,rw \
--mount=type=cache,target=/usr/local/lib/php/test \
--mount=type=cache,target=/usr/local/lib/php/doc \
set -x \
&& export PATH=$PATH:/opt/bin \
&& apk add --no-cache --virtual .pecl_build_deps $PECL_BUILD_DEPS $PHPIZE_DEPS \
&& apk add --no-cache --virtual .pecl_run_deps $PECL_RUN_DEPS \
&& echo "--enable-redis-igbinary --enable-redis-zstd" > /tmp/redis.configure.options \
&& echo "--enable-memcached-igbinary" > /tmp/memcached.configure.options \
&& echo "--with-libzstd" > /tmp/zstd.configure.options \
&& pickle install $PECL_EXTENSION -n --defaults --strip --cleanup --continue-on-error \
&& pickle install \
https://github.com/xdebug/xdebug/archive/master.tar.gz \
# https://github.com/tideways/php-xhprof-extension.git
https://github.com/tideways/php-xhprof-extension/archive/master.tar.gz \
-n --defaults --no-write --strip --cleanup --continue-on-error \
# && phpize \
# && ./configure --enable-xdebug-dev \
# && make all -j "$(nproc)"\
# && make install \
&& rm -rf /tmp/* \
&& apk del --no-network .pecl_build_deps \
&& rm -rf /usr/local/lib/php/.registry/.channel.pecl.php.net/* \
&& php -m \
&& ls -la $(php-config --extension-dir) \
&& php -d error_reporting=22527 -d display_errors=1 -r 'var_dump(iconv("UTF-8", "UTF-8//IGNORE", "This is the Euro symbol '\''€'\''."));' \
# smoke test
&& php --version
STOPSIGNAL SIGQUIT
EXPOSE 9000
CMD ["php-fpm"]
WORKDIR /app
ARG VCS_REF="unknow"
LABEL org.opencontainers.image.revision=$VCS_REF \
org.opencontainers.image.source="https://github.com/khs1994-docker/php"