Skip to content

Commit 9ff4836

Browse files
committed
Fixed Dockerfiles to ensure library dependencies stay installed in the image
Signed-off-by: Moritz Mazetti <moritz@matchory.com>
1 parent 24f093e commit 9ff4836

File tree

2 files changed

+104
-69
lines changed

2 files changed

+104
-69
lines changed

Dockerfile

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,52 @@
11
# syntax=docker/dockerfile:1
22
FROM php:8.4-cli AS upstream
3-
FROM upstream AS base
4-
ARG APCU_VERSION="5.1.27"
5-
ARG REDIS_VERSION="6.2.0"
6-
ARG OPENSWOOLE_VERSION="25.2.0"
7-
ARG user="php"
8-
ARG uid="5000"
9-
103
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
114
--mount=type=cache,target=/var/lib/apt,sharing=locked <<EOF
125
set -eux
136

14-
# region Install Dependencies
15-
export RUNTIME_DEPENDENCIES="\
7+
apt-get update
8+
apt-get install \
9+
--yes \
10+
--no-install-recommends \
1611
postgresql-client \
17-
libmemcached-dev \
12+
libmemcached11t64 \
1813
ca-certificates \
19-
libyaml-dev \
20-
libzip-dev \
21-
zlib1g-dev \
14+
libyaml-0-2 \
15+
libicu76 \
16+
libzip5 \
2217
gettext \
2318
openssl \
19+
zlib1g \
2420
file \
25-
"
26-
export BUILD_DEPENDENCIES="\
21+
;
22+
EOF
23+
24+
FROM upstream AS builder
25+
ARG APCU_VERSION="5.1.27"
26+
ARG REDIS_VERSION="6.2.0"
27+
ARG OPENSWOOLE_VERSION="25.2.0"
28+
29+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
30+
--mount=type=cache,target=/var/lib/apt,sharing=locked <<EOF
31+
set -eux
32+
33+
# region Install Dependencies
34+
apt-get update
35+
apt-get install \
36+
--yes \
37+
--no-install-recommends \
2738
${PHPIZE_DEPS} \
2839
linux-headers-generic \
2940
libcurl4-openssl-dev \
41+
libmemcached-dev \
3042
libonig-dev \
43+
libyaml-dev \
3144
libssl-dev \
3245
libicu-dev \
46+
libzip-dev \
47+
zlib1g-dev \
3348
libpq-dev \
34-
"
35-
36-
apt-get update
37-
apt-get install \
38-
--yes \
39-
--no-install-recommends \
40-
${BUILD_DEPENDENCIES} \
41-
${RUNTIME_DEPENDENCIES}
49+
;
4250
# endregion
4351

4452
# region Install redis extension
@@ -84,30 +92,37 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
8492
apcu \
8593
yaml \
8694
;
87-
docker-php-source delete
8895
# endregion
8996

97+
EOF
98+
99+
FROM upstream AS base
100+
ARG user="php"
101+
ARG uid="5000"
102+
103+
RUN <<EOF
90104
# region Remove Build Dependencies
91105
apt-get purge \
92106
--option APT::AutoRemove::RecommendsImportant=false \
93107
--auto-remove \
94108
--yes \
95-
${BUILD_DEPENDENCIES} \
96109
;
110+
97111
rm -rf \
98112
/usr/local/lib/php/test \
99113
/usr/local/bin/phpdbg \
100-
/usr/local/bin/docker-php-ext-* \
101-
/usr/local/bin/docker-php-source \
102114
/usr/local/bin/install-php-extensions \
115+
/usr/local/bin/docker-php-source \
116+
/usr/local/bin/docker-php-ext-* \
117+
/usr/local/bin/phpize \
103118
/usr/local/bin/pear* \
104119
/usr/local/bin/pecl \
105-
/usr/local/bin/phpize \
106120
/usr/src/* \
107-
/tmp/*
121+
/tmp/* \
122+
;
108123
# endregion
109124

110-
# Add a non-root user to run the application
125+
# region Add a non-root user to run the application
111126
addgroup \
112127
--gid "${uid}" \
113128
"${user}"
@@ -119,8 +134,12 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
119134
--gid ${uid} \
120135
--system \
121136
"${user}"
137+
# endregion
122138
EOF
123139

140+
COPY --link --from=builder /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/
141+
COPY --link --from=builder /usr/local/etc/php/conf.d/ /usr/local/etc/php/conf.d/
142+
124143
# Copy custom PHP settings
125144
COPY --link php.ini "${PHP_INI_DIR}/conf.d/99-docker.ini"
126145

@@ -139,7 +158,9 @@ ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="1"
139158
# Enables PHPStorm to apply the correct path mapping on Xdebug breakpoints
140159
ENV PHP_IDE_CONFIG="serverName=Docker"
141160

142-
RUN --mount=type=bind,from=upstream,source=/usr/local/bin,target=/usr/local/bin <<EOF
161+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
162+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
163+
--mount=type=bind,from=upstream,source=/usr/local/bin,target=/usr/local/bin <<EOF
143164
set -eux
144165
ln -sf "${PHP_INI_DIR}/php.ini-development" "${PHP_INI_DIR}/php.ini"
145166

@@ -155,10 +176,7 @@ RUN --mount=type=bind,from=upstream,source=/usr/local/bin,target=/usr/local/bin
155176
--yes \
156177
--auto-remove \
157178
${PHPIZE_DEPS}
158-
rm -rf \
159-
/var/lib/apt/lists/* \
160-
/var/cache/* \
161-
/tmp/*
179+
rm -rf /tmp/*
162180
# endregion
163181

164182
# region Configure XDebug

frankenphp.Dockerfile

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,51 @@
11
# syntax=docker/dockerfile:1
22
FROM dunglas/frankenphp:1.9-php8.4 AS upstream
3-
FROM upstream AS base
4-
ARG APCU_VERSION="5.1.27"
5-
ARG REDIS_VERSION="6.2.0"
6-
ARG user="php"
7-
ARG uid="5000"
8-
93
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
104
--mount=type=cache,target=/var/lib/apt,sharing=locked <<EOF
115
set -eux
126

13-
# region Install Dependencies
14-
export RUNTIME_DEPENDENCIES="\
7+
apt-get update
8+
apt-get install \
9+
--yes \
10+
--no-install-recommends \
1511
postgresql-client \
16-
libmemcached-dev \
12+
libmemcached11t64 \
1713
ca-certificates \
18-
libyaml-dev \
19-
libzip-dev \
20-
zlib1g-dev \
14+
libyaml-0-2 \
15+
libicu76 \
16+
libzip5 \
2117
gettext \
2218
openssl \
19+
zlib1g \
2320
file \
24-
"
25-
export BUILD_DEPENDENCIES="\
21+
;
22+
EOF
23+
24+
FROM upstream AS builder
25+
ARG APCU_VERSION="5.1.27"
26+
ARG REDIS_VERSION="6.2.0"
27+
28+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
29+
--mount=type=cache,target=/var/lib/apt,sharing=locked <<EOF
30+
set -eux
31+
32+
# region Install Dependencies
33+
apt-get update
34+
apt-get install \
35+
--yes \
36+
--no-install-recommends \
2637
${PHPIZE_DEPS} \
2738
linux-headers-generic \
2839
libcurl4-openssl-dev \
40+
libmemcached-dev \
2941
libonig-dev \
42+
libyaml-dev \
3043
libssl-dev \
3144
libicu-dev \
45+
libzip-dev \
46+
zlib1g-dev \
3247
libpq-dev \
33-
"
34-
35-
apt-get update
36-
apt-get install \
37-
--yes \
38-
--no-install-recommends \
39-
${BUILD_DEPENDENCIES} \
40-
${RUNTIME_DEPENDENCIES}
48+
;
4149
# endregion
4250

4351
# region Install Redis extension
@@ -81,30 +89,36 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
8189
apcu \
8290
yaml \
8391
;
84-
docker-php-source delete
8592
# endregion
93+
EOF
94+
95+
FROM upstream AS base
96+
ARG user="php"
97+
ARG uid="5000"
8698

99+
RUN <<EOF
87100
# region Remove Build Dependencies
88101
apt-get purge \
89102
--option APT::AutoRemove::RecommendsImportant=false \
90103
--auto-remove \
91104
--yes \
92-
${BUILD_DEPENDENCIES} \
93105
;
106+
94107
rm -rf \
95108
/usr/local/lib/php/test \
96109
/usr/local/bin/phpdbg \
97-
/usr/local/bin/docker-php-ext-* \
98-
/usr/local/bin/docker-php-source \
99110
/usr/local/bin/install-php-extensions \
111+
/usr/local/bin/docker-php-source \
112+
/usr/local/bin/docker-php-ext-* \
113+
/usr/local/bin/phpize \
100114
/usr/local/bin/pear* \
101115
/usr/local/bin/pecl \
102-
/usr/local/bin/phpize \
103116
/usr/src/* \
104-
/tmp/*
117+
/tmp/* \
118+
;
105119
# endregion
106120

107-
# Add a non-root user to run the application
121+
# region Add a non-root user to run the application
108122
addgroup \
109123
--gid "${uid}" \
110124
"${user}"
@@ -116,6 +130,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
116130
--gid ${uid} \
117131
--system \
118132
"${user}"
133+
# endregion
119134

120135
# Add additional capability to bind to port 80 and 443
121136
setcap CAP_NET_BIND_SERVICE=+eip /usr/local/bin/frankenphp
@@ -129,6 +144,9 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
129144
mkdir -p /app
130145
EOF
131146

147+
COPY --link --from=builder /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/
148+
COPY --link --from=builder /usr/local/etc/php/conf.d/ /usr/local/etc/php/conf.d/
149+
132150
# Copy custom PHP settings
133151
COPY --link ./php.ini "${PHP_INI_DIR}/conf.d/99-docker.ini"
134152
COPY --link ./Caddyfile /etc/caddy/Caddyfile
@@ -153,7 +171,9 @@ ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="1"
153171
# Enables PHPStorm to apply the correct path mapping on Xdebug breakpoints
154172
ENV PHP_IDE_CONFIG="serverName=Docker"
155173

156-
RUN --mount=type=bind,from=upstream,source=/usr/local/bin,target=/usr/local/bin <<EOF
174+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
175+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
176+
--mount=type=bind,from=upstream,source=/usr/local/bin,target=/usr/local/bin <<EOF
157177
set -eux
158178
ln -sf "${PHP_INI_DIR}/php.ini-development" "${PHP_INI_DIR}/php.ini"
159179

@@ -169,10 +189,7 @@ RUN --mount=type=bind,from=upstream,source=/usr/local/bin,target=/usr/local/bin
169189
--yes \
170190
--auto-remove \
171191
${PHPIZE_DEPS}
172-
rm -rf \
173-
/var/lib/apt/lists/* \
174-
/var/cache/* \
175-
/tmp/*
192+
rm -rf /tmp/*
176193
# endregion
177194

178195
# region Configure XDebug

0 commit comments

Comments
 (0)