-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
151 lines (144 loc) · 3.51 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
FROM alpine:3.20
ARG PHP_VERSION=8.3.9
ARG PHP_URL="https://www.php.net/distributions/php-${PHP_VERSION}.tar.xz"
ENV PHPIZE_DEPS \
autoconf \
dpkg dpkg-dev \
file \
clang \
llvm \
libc-dev \
make \
pkgconf \
re2c
ENV PHP_SHA256=""
ENV PHP_INI_DIR="/usr/local/etc/php"
ENV PHP_SCAN_DIR="$PHP_INI_DIR/conf.d"
ENV PHP_LDFLAGS="-Wl,-O3 -pie"
ENV PHP_CPPFLAGS="$PHP_CFLAGS"
ENV PHP_CFLAGS="-fstack-protector-strong -fpic -fpie -O3 \
-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 \
-march=native \
-funroll-loops \
-ffast-math \
-finline-functions \
"
COPY docker-entrypoint docker-php-* /usr/local/bin/
RUN set -eux; \
\
# install build tools
apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
argon2-dev \
coreutils \
curl-dev \
gnu-libiconv-dev \
libsodium-dev \
libxml2-dev \
linux-headers \
oniguruma-dev \
openssl-dev \
readline-dev \
sqlite-dev \
curl \
make; \
\
# export required environment variables
export \
CFLAGS="$PHP_CFLAGS" \
CPPFLAGS="$PHP_CPPFLAGS" \
LDFLAGS="$PHP_LDFLAGS" \
PHP_BUILD_PROVIDER='https://github.com/sxbrsky/docker-php-cli' \
PHP_UNAME='Linux - Docker' \
; \
\
# gets php sources \
mkdir -p /usr/src; \
cd /usr/src; \
\
# download sources
curl -fsSL -o php.tar.xz "$PHP_URL"; \
\
# generate checksum if not exists
if [-n "$PHP_SHA256"]; then \
echo "$PHP_SHA256 *php.tar.xz" | sha256sum -c -; \
fi; \
\
# extract sources
docker-php-source extract; \
cd /usr/src/php; \
\
# configure the build
./configure CC=clang CXX=clang++ \
--build="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \
--prefix="/usr/local/" \
--sbin="/usr/local/sbin" \
--sysconfdir="$PHP_INI_DIR" \
--localstatedir=/var \
--mandir=/usr/share/man \
--with-layout=GNU \
--with-config-file-path="$PHP_INI_DIR" \
--with-config-file-scan-dir="$PHP_SCAN_DIR" \
--config-cache \
--enable-option-checking=fatal \
--disable-gcc-global-regs \
--disable-rpath \
--without-sqlite3 \
--without-cdb \
--with-pear \
# it's cli image so disable fpm & and cgi
--disable-cgi \
--disable-fpm \
--disable-phpdbg; \
\
# compile and install php
make -j $(nproc); \
make install; \
\
find /usr/local \
-type f \
-perm '/0111' \
-exec sh -euxc ' \
strip --strip-all "$@" || : \
' -- '{}' + \
; \
\
# cleaning up after compilation
make clean; \
make distclean; \
\
# copy php.ini into $PHP_INIT_DIR
cp php.ini-production "$PHP_INI_DIR/php.ini"; \
\
# remove sources
cd /; \
rm -rf /usr/src/php; \
\
# remove build deps, install runtime deps
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; \
\
# update pecl
pecl update-channels; \
rm -rf /tmp/pear ~/.pearrc; \
\
# smoke test
php --version; \
\
# delete all *.default conf
cd "$PHP_INI_DIR"; \
find "$PHP_INI_DIR" \
-type f \
-name '*.default' \
-exec rm {} + ; \
\
# clear apk cache
rm -rf /var/cache/apk/*
ENTRYPOINT [ "docker-entrypoint" ]
CMD [ "php", "-a" ]