-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.alpine
More file actions
273 lines (258 loc) · 12 KB
/
Copy pathDockerfile.alpine
File metadata and controls
273 lines (258 loc) · 12 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
FROM registry.cn-hangzhou.aliyuncs.com/mj520/alpine:3.12
ENV TZ=Asia/Shanghai
ENV IMAGICK_VERSION=3.4.4
ENV PHALCON_VERSION=3.4.5
ARG MAKEFLAGS=-j8
RUN echo "https://mirrors.aliyun.com/alpine/v3.12/main" > /etc/apk/repositories && \
echo "https://mirrors.aliyun.com/alpine/v3.12/community" >> /etc/apk/repositories && \
apk --update add --no-cache && apk add -U tzdata bash && \
apk add --no-cache nginx nginx-mod-stream shadow inotify-tools procps && \
groupmod --gid 81 cdrw && groupmod --gid 80 --new-name www nginx && \
usermod --uid 80 --home /data/www --gid 80 --login www --shell /sbin/nologin --comment www nginx && \
chown www:www -R /var/lib/nginx && \
echo 'nginx installed.' && nginx -v && apk del shadow
# 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 libc-dev make pkgconf re2c
# persistent / runtime deps
RUN apk add --no-cache ca-certificates curl tar xz openssl bind-tools
# https://github.com/docker-library/php/issues/494
ENV PHP_INI_DIR /usr/local/etc/php
RUN set -eux; \
mkdir -p "$PHP_INI_DIR/conf.d"; \
# allow running as an arbitrary user (https://github.com/docker-library/php/issues/743)
[ ! -d /data ]; \
mkdir -p /data; \
chown www:www /data; \
chmod 777 /data
##<autogenerated>##
ENV PHP_EXTRA_CONFIGURE_ARGS --enable-fpm --with-fpm-user=www --with-fpm-group=www --disable-cgi
##</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)
# https://github.com/docker-library/php/issues/272
# -D_LARGEFILE_SOURCE and -D_FILE_OFFSET_BITS=64 (https://www.php.net/manual/en/intro.filesystem.php)
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.29
ENV PHP_URL="https://www.php.net/distributions/php-7.3.29.tar.xz" PHP_ASC_URL="https://www.php.net/distributions/php-7.3.29.tar.xz.asc"
ENV PHP_SHA256="7db2834511f3d86272dca3daee3f395a5a4afce359b8342aa6edad80e12eb4d0"
RUN set -eux; \
\
apk add --no-cache --virtual .fetch-deps gnupg; \
\
mkdir -p /usr/src; \
cd /usr/src; \
\
curl -fsSL -o php.tar.xz "$PHP_URL"; \
\
if [ -n "$PHP_SHA256" ]; then \
echo "$PHP_SHA256 *php.tar.xz" | sha256sum -c -; \
fi; \
\
if [ -n "$PHP_ASC_URL" ]; then \
curl -fsSL -o php.tar.xz.asc "$PHP_ASC_URL"; \
export GNUPGHOME="$(mktemp -d)"; \
for key in $GPG_KEYS; do \
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key"; \
done; \
gpg --batch --verify php.tar.xz.asc php.tar.xz; \
gpgconf --kill all; \
rm -rf "$GNUPGHOME"; \
fi; \
\
apk del --no-network .fetch-deps
COPY docker-php-* /usr/local/bin/
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
RUN apk add --no-cache --repository https://mirrors.aliyun.com/alpine/latest-stable/community gnu-libiconv
RUN set -eux; \
apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
argon2-dev \
coreutils \
curl-dev \
libedit-dev \
libsodium-dev \
libxml2-dev \
linux-headers \
oniguruma-dev \
openssl-dev \
sqlite-dev \
zlib-dev libwebp-dev libjpeg-turbo-dev libpng-dev libzip-dev \
librdkafka-dev imagemagick-dev pcre-dev gettext-dev freetype-dev; \
export CFLAGS="$PHP_CFLAGS" \
CPPFLAGS="$PHP_CPPFLAGS" \
LDFLAGS="$PHP_LDFLAGS" \
; \
docker-php-source extract; \
cd /usr/src/php; \
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
./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 intead 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 \
# https://wiki.php.net/rfc/argon2_password_hash (7.2+)
--with-password-argon2 \
# https://wiki.php.net/rfc/libsodium
--with-sodium=shared \
# always build against system sqlite3 (https://github.com/php/php-src/commit/6083a387a81dbbd66d6316a3a12a63f06d5f7109)
--with-pdo-sqlite=/usr \
--with-sqlite3=/usr \
\
--with-curl \
--with-libedit \
--with-openssl \
--with-zlib \
\
# 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; \
\
# https://github.com/docker-library/php/issues/692 (copy default example "php.ini" files somewhere easily discoverable)
cp -v php.ini-* "$PHP_INI_DIR/"; \
\
cd /; \
# update pecl channel definitions https://github.com/docker-library/php/issues/443
pecl update-channels; \
\
cp ${PHP_INI_DIR}/php.ini-production ${PHP_INI_DIR}/php.ini && \
# gd libwebp-dev libjpeg-turbo-dev libpng-dev gettext-dev freetype-dev
docker-php-ext-configure gd --with-freetype-dir=/usr/lib --with-jpeg-dir=/usr/local/lib && \
docker-php-ext-install -j8 iconv gd pdo_mysql mysqli bcmath exif gettext pcntl sockets zip && \
docker-php-ext-enable iconv gd pdo_mysql mysqli bcmath exif gettext pcntl sockets zip&& \
# redis igbinary
pecl install -o -f igbinary-3.2.14 && docker-php-ext-enable igbinary && \
pecl install -o -f redis-5.3.7 && docker-php-ext-enable redis && \
pecl install -o -f swoole-4.8.11 && docker-php-ext-enable swoole && \
pecl install -o -f mongodb-1.16.2 && docker-php-ext-enable mongodb && \
pecl install -o -f xdebug-3.1.6 && docker-php-ext-enable xdebug && \
pecl install -o -f xlswriter-1.5.5 && docker-php-ext-enable xlswriter && \
#rdkafka librdkafka librdkafka-dev
pecl install -o -f rdkafka-6.0.3 && docker-php-ext-enable rdkafka && \
#grpc protobuf zlib-dev linux-headers https://www.testdoc.cn/grpc-1.27.0.tgz
pecl install -o -f protobuf-3.22.0 && docker-php-ext-enable protobuf && \
pecl install -o -f grpc-1.49.3 && docker-php-ext-enable grpc && \
# phalcon4 pcre-dev php7.4 isn't supported for Phalcon 3.4
# pecl install -o -f psr phalcon && docker-php-ext-enable psr phalcon && \
cd /tmp && \
curl -SL "https://codeload.github.com/phalcon/cphalcon/tar.gz/v${PHALCON_VERSION}" \
-o /tmp/phalcon.tar.gz && \
tar xvf phalcon.tar.gz -C /tmp && \
cd "/tmp/cphalcon-${PHALCON_VERSION}/build" && \
./install && \
echo 'extension="phalcon.so"' > "${PHP_INI_DIR}/conf.d/phalcon.ini" && \
#imagick imagemagick-libs imagemagick-c++ imagemagick-dev;pecl install not fount;
cd /tmp && \
curl -SL "https://codeload.github.com/Imagick/imagick/tar.gz/${IMAGICK_VERSION}" \
-o "/tmp/imagick.tar.gz" && \
tar xvf imagick.tar.gz -C /tmp && \
cd "/tmp/imagick-${IMAGICK_VERSION}" && \
phpize && \
./configure --with-php-config=`which php-config` && \
make && make install && make clean && \
docker-php-ext-enable imagick; \
\
docker-php-source delete; \
cd /usr/local/ && { find . -type f -exec strip --strip-all {} + || true; }; \
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; \
\
apk del --no-network .build-deps; \
\
rm -rf /tmp/* ~/.pearrc /usr/local/lib/php/test /usr/local/lib/php/doc /usr/src/*; \
# smoke test
php --version && php -m
# composer
RUN curl -SL "https://mirrors.aliyun.com/composer/composer.phar" -o /usr/local/bin/composer && \
chmod a+x /usr/local/bin/composer && \
echo 'composer installed.' && composer --version && \
composer config -g repo.packagist composer "https://mirrors.aliyun.com/composer/"
# 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
RUN set -eux; \
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
# Override stop signal to stop process gracefully
# https://github.com/php/php-src/blob/17baa87faddc2550def3ae7314236826bc1b1398/sapi/fpm/php-fpm.8.in#L163
STOPSIGNAL SIGQUIT
ADD container-files /
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
ln -s ${PHP_INI_DIR}/php.ini /etc/php.ini && mv /etc/php.d/z-php.ini ${PHP_INI_DIR}/conf.d/ && \
rm -rf /etc/php.d && ln -s ${PHP_INI_DIR}/conf.d /etc/php.d && \
mkdir -p /data/conf && touch php.ini && ln -s /data/conf/php.ini /etc/php.d/zz.php.ini && \
echo -e "[inet_http_server]\nport=127.0.0.1:9001\n[include]\nfiles = /etc/supervisord.conf.d/*.conf /data/conf/supervisord.conf.d/*.conf" \
>> /etc/supervisord.conf && \
chmod +x /docker-entrypoint.sh /supervisor* && mv /supervisor* /usr/bin/ && \
echo "ls -l \$*" > /usr/bin/ll && chmod +x /usr/bin/ll && \
/docker-entrypoint.sh && \
sed -i "1iload_module /usr/lib/nginx/modules/ngx_stream_module.so;" /etc/nginx/nginx.conf
WORKDIR /data
VOLUME [ "/data" ]
ENTRYPOINT [ "/docker-entrypoint.sh" ]
EXPOSE 80 443 9000
CMD /usr/bin/supervisord -c /etc/supervisord.conf