Skip to content

Commit 236f8a7

Browse files
committed
feat: chialab/php-compat images
1 parent 565e057 commit 236f8a7

File tree

9 files changed

+1148
-3
lines changed

9 files changed

+1148
-3
lines changed

.github/workflows/compat.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Build, test and publish compatibility images
2+
3+
on:
4+
schedule:
5+
# chosen by fair dice roll
6+
- cron: '42 18 * * 3'
7+
push:
8+
branches:
9+
- main
10+
pull_request:
11+
types: [opened, synchronize]
12+
13+
jobs:
14+
test:
15+
name: Build and test images
16+
runs-on: ubuntu-latest
17+
if: ${{ !contains(github.event.commits[0].message, '[skip ci]') && !contains(github.event.commits[0].message, '[ci skip]') }}
18+
strategy:
19+
matrix:
20+
version: [ '5.6' ]
21+
flavor: [ '', '-apache', '-fpm' ]
22+
services:
23+
registry:
24+
image: registry:2
25+
ports:
26+
- 5000:5000
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
31+
- name: Build image for testing
32+
uses: docker/build-push-action@v5
33+
with:
34+
cache-from: type=registry,ref=chialab/php-compat:${{ matrix.version }}${{ matrix.flavor }}
35+
cache-to: type=inline
36+
context: ./compat
37+
file: ${{ format('compat/{0}.{1}{2}', 'Dockerfile', matrix.version, matrix.flavor) }}
38+
tags: localhost:5000/chialab/php-compat:${{ matrix.version }}${{ matrix.flavor }}
39+
push: true
40+
41+
- name: Test image
42+
env:
43+
REGISTRY: localhost:5000/
44+
VERSION: ${{ matrix.version }}${{ matrix.flavor }}
45+
run: 'docker pull localhost:5000/chialab/php-compat:${{ matrix.version }}${{ matrix.flavor }} && make -C compat test'
46+
47+
publish:
48+
name: Build and publish multi-architecture images
49+
runs-on: ubuntu-latest
50+
needs: test
51+
if: ${{ github.event_name != 'pull_request' && !contains(github.event.commits[0].message, '[skip ci]') && !contains(github.event.commits[0].message, '[ci skip]') }}
52+
strategy:
53+
matrix:
54+
version: [ '5.6' ]
55+
flavor: [ '', '-apache', '-fpm' ]
56+
steps:
57+
- name: Checkout
58+
uses: actions/checkout@v4
59+
60+
- name: Set up QEMU
61+
run: |
62+
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
63+
64+
- name: Set up Docker Buildx
65+
uses: docker/setup-buildx-action@v3
66+
with:
67+
driver-opts: network=host
68+
69+
- name: Login to DockerHub
70+
uses: docker/login-action@v3
71+
with:
72+
username: ${{ secrets.DOCKER_USERNAME }}
73+
password: ${{ secrets.DOCKER_PASSWORD }}
74+
75+
- name: Login to GitHub Container Registry
76+
uses: docker/login-action@v3
77+
with:
78+
registry: ghcr.io
79+
username: ${{ github.repository_owner }}
80+
password: ${{ secrets.GITHUB_TOKEN }}
81+
82+
- name: Build image and push to registry
83+
uses: docker/build-push-action@v5
84+
with:
85+
platforms: linux/amd64,linux/arm64
86+
cache-from: type=registry,ref=chialab/php-compat:${{ matrix.version }}${{ matrix.flavor }}
87+
cache-to: type=inline
88+
context: ./compat
89+
file: ${{ format('compat/{0}.{1}{2}', 'Dockerfile', matrix.version, matrix.flavor) }}
90+
tags: |
91+
chialab/php-compat:${{ matrix.version }}${{ matrix.flavor }}
92+
ghcr.io/chialab/php-compat:${{ matrix.version }}${{ matrix.flavor }}
93+
push: true

compat/Dockerfile.5.6

Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
#
2+
# This is taken from the official PHP image's Dockerfile (https://github.com/docker-library/php/tree/783878384a8f3953ed571e5a34ba0fe546726c85)
3+
# and slightly fixed to work in this day and age.
4+
#
5+
6+
FROM debian:stretch-slim
7+
8+
LABEL maintainer="[email protected]"
9+
10+
# Fix Debian 9 (Stretch) source list, because it has been moved to archive, and update packages.
11+
RUN sed -i -e 's/deb.debian.org/archive.debian.org/g' \
12+
-e 's/security.debian.org/archive.debian.org/g' \
13+
-e '/stretch-updates/d' /etc/apt/sources.list \
14+
&& apt-get update && apt-get upgrade -y
15+
16+
# prevent Debian's PHP packages from being installed
17+
# https://github.com/docker-library/php/pull/542
18+
RUN set -eux; \
19+
{ \
20+
echo 'Package: php*'; \
21+
echo 'Pin: release *'; \
22+
echo 'Pin-Priority: -1'; \
23+
} > /etc/apt/preferences.d/no-debian-php
24+
25+
# dependencies required for running "phpize"
26+
# (see persistent deps below)
27+
ENV PHPIZE_DEPS \
28+
autoconf \
29+
dpkg-dev \
30+
file \
31+
g++ \
32+
gcc \
33+
libc-dev \
34+
make \
35+
pkg-config \
36+
re2c
37+
38+
# persistent / runtime deps
39+
RUN apt-get update && apt-get install -y \
40+
$PHPIZE_DEPS \
41+
ca-certificates \
42+
curl \
43+
xz-utils \
44+
--no-install-recommends && rm -r /var/lib/apt/lists/*
45+
46+
ENV PHP_INI_DIR /usr/local/etc/php
47+
RUN mkdir -p $PHP_INI_DIR/conf.d
48+
49+
##<autogenerated>##
50+
##</autogenerated>##
51+
52+
# Apply stack smash protection to functions using local buffers and alloca()
53+
# Make PHP's main executable position-independent (improves ASLR security mechanism, and has no performance impact on x86_64)
54+
# Enable optimization (-O2)
55+
# Enable linker optimization (this sorts the hash buckets to improve cache locality, and is non-default)
56+
# 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)
57+
# https://github.com/docker-library/php/issues/272
58+
ENV PHP_CFLAGS="-fstack-protector-strong -fpic -fpie -O2"
59+
ENV PHP_CPPFLAGS="$PHP_CFLAGS"
60+
ENV PHP_LDFLAGS="-Wl,-O1 -Wl,--hash-style=both -pie"
61+
62+
ENV GPG_KEYS 0BD78B5F97500D450838F95DFE857D9A90D90EC1 6E4F6AB321FDC07F2C332E3AC2BF0BC433CFC8B3
63+
64+
ENV PHP_VERSION 5.6.40
65+
ENV PHP_URL="https://secure.php.net/get/php-5.6.40.tar.xz/from/this/mirror" PHP_ASC_URL="https://secure.php.net/get/php-5.6.40.tar.xz.asc/from/this/mirror"
66+
ENV PHP_SHA256="1369a51eee3995d7fbd1c5342e5cc917760e276d561595b6052b21ace2656d1c" PHP_MD5=""
67+
68+
RUN set -xe; \
69+
\
70+
fetchDeps=' \
71+
wget \
72+
'; \
73+
if ! command -v gpg > /dev/null; then \
74+
fetchDeps="$fetchDeps \
75+
dirmngr \
76+
gnupg \
77+
"; \
78+
fi; \
79+
apt-get update; \
80+
apt-get install -y --no-install-recommends $fetchDeps; \
81+
rm -rf /var/lib/apt/lists/*; \
82+
\
83+
mkdir -p /usr/src; \
84+
cd /usr/src; \
85+
\
86+
wget -O php.tar.xz "$PHP_URL"; \
87+
\
88+
if [ -n "$PHP_SHA256" ]; then \
89+
echo "$PHP_SHA256 *php.tar.xz" | sha256sum -c -; \
90+
fi; \
91+
if [ -n "$PHP_MD5" ]; then \
92+
echo "$PHP_MD5 *php.tar.xz" | md5sum -c -; \
93+
fi; \
94+
\
95+
if [ -n "$PHP_ASC_URL" ]; then \
96+
wget -O php.tar.xz.asc "$PHP_ASC_URL"; \
97+
export GNUPGHOME="$(mktemp -d)"; \
98+
for key in $GPG_KEYS; do \
99+
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key"; \
100+
done; \
101+
gpg --batch --verify php.tar.xz.asc php.tar.xz; \
102+
command -v gpgconf > /dev/null && gpgconf --kill all; \
103+
rm -rf "$GNUPGHOME"; \
104+
fi; \
105+
\
106+
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $fetchDeps
107+
108+
COPY --from=php:5.6 /usr/local/bin/docker-php-source /usr/local/bin/
109+
110+
RUN set -eux; \
111+
\
112+
savedAptMark="$(apt-mark showmanual)"; \
113+
apt-get update; \
114+
apt-get install -y --no-install-recommends \
115+
libcurl4-openssl-dev \
116+
libedit-dev \
117+
libsqlite3-dev \
118+
libssl1.0-dev \
119+
libxml2-dev \
120+
zlib1g-dev \
121+
libmariadb2 libmariadbclient-dev-compat \
122+
${PHP_EXTRA_BUILD_DEPS:-} \
123+
; \
124+
rm -rf /var/lib/apt/lists/*; \
125+
\
126+
export \
127+
CFLAGS="$PHP_CFLAGS" \
128+
CPPFLAGS="$PHP_CPPFLAGS" \
129+
LDFLAGS="$PHP_LDFLAGS" \
130+
; \
131+
docker-php-source extract; \
132+
cd /usr/src/php; \
133+
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
134+
debMultiarch="$(dpkg-architecture --query DEB_BUILD_MULTIARCH)"; \
135+
# https://bugs.php.net/bug.php?id=74125
136+
if [ ! -d /usr/include/curl ]; then \
137+
ln -sT "/usr/include/$debMultiarch/curl" /usr/local/include/curl; \
138+
fi; \
139+
./configure \
140+
--build="$gnuArch" \
141+
--with-config-file-path="$PHP_INI_DIR" \
142+
--with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
143+
\
144+
# make sure invalid --configure-flags are fatal errors intead of just warnings
145+
--enable-option-checking=fatal \
146+
\
147+
# https://github.com/docker-library/php/issues/439
148+
--with-mhash \
149+
\
150+
# --enable-ftp is included here because ftp_ssl_connect() needs ftp to be compiled statically (see https://github.com/docker-library/php/issues/236)
151+
--enable-ftp \
152+
# --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)
153+
--enable-mbstring \
154+
# Use MariaDB's libmysqlclient library instead of mysqlnd to be able to communicate with MySQL 8+, which uses new locales of the utf8mb4 family that are unknown to old mysqlnd
155+
--disable-mysqlnd \
156+
--with-mysql="/usr" \
157+
--with-mysqli="/usr/bin/mysql_config" \
158+
--with-pdo-mysql="/usr" \
159+
\
160+
--with-curl \
161+
--with-libedit \
162+
--with-openssl \
163+
--with-zlib \
164+
\
165+
# bundled pcre does not support JIT on s390x
166+
# https://manpages.debian.org/stretch/libpcre3-dev/pcrejit.3.en.html#AVAILABILITY_OF_JIT_SUPPORT
167+
$(test "$gnuArch" = 's390x-linux-gnu' && echo '--without-pcre-jit') \
168+
--with-libdir="lib/$debMultiarch" \
169+
\
170+
${PHP_EXTRA_CONFIGURE_ARGS:-} \
171+
; \
172+
make -j "$(nproc)"; \
173+
make install; \
174+
find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true; \
175+
make clean; \
176+
\
177+
# https://github.com/docker-library/php/issues/692 (copy default example "php.ini" files somewhere easily discoverable)
178+
cp -v php.ini-* "$PHP_INI_DIR/"; \
179+
\
180+
cd /; \
181+
docker-php-source delete; \
182+
\
183+
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
184+
apt-mark auto '.*' > /dev/null; \
185+
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \
186+
find /usr/local -type f -executable -exec ldd '{}' ';' \
187+
| awk '/=>/ { print $(NF-1) }' \
188+
| sort -u \
189+
| xargs -r dpkg-query --search \
190+
| cut -d: -f1 \
191+
| sort -u \
192+
| xargs -r apt-mark manual \
193+
; \
194+
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
195+
\
196+
php --version; \
197+
\
198+
# https://github.com/docker-library/php/issues/443
199+
pecl update-channels; \
200+
rm -rf /tmp/pear ~/.pearrc
201+
202+
COPY --from=php:5.6 /usr/local/bin/docker-php-ext-* /usr/local/bin/docker-php-entrypoint /usr/local/bin/
203+
204+
ENTRYPOINT ["docker-php-entrypoint"]
205+
##<autogenerated>##
206+
CMD ["php", "-a"]
207+
##</autogenerated>##
208+
209+
# Download script to install PHP extensions and dependencies
210+
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
211+
212+
RUN chmod +x /usr/local/bin/install-php-extensions
213+
214+
RUN DEBIAN_FRONTEND=noninteractive apt-get update -q \
215+
&& DEBIAN_FRONTEND=noninteractive apt-get install -qq -y \
216+
curl \
217+
git \
218+
zip unzip \
219+
# iconv, mbstring and pdo_sqlite are omitted as they are already installed
220+
&& PHP_EXTENSIONS=" \
221+
amqp \
222+
bcmath \
223+
bz2 \
224+
calendar \
225+
event \
226+
exif \
227+
gd \
228+
gettext \
229+
imagick \
230+
intl \
231+
ldap \
232+
mcrypt \
233+
memcached \
234+
mysql \
235+
mysqli \
236+
opcache \
237+
pdo_mysql \
238+
pdo_pgsql \
239+
pgsql \
240+
redis \
241+
soap \
242+
sockets \
243+
xsl \
244+
zip \
245+
" \
246+
&& install-php-extensions $PHP_EXTENSIONS
247+
248+
# Install Composer.
249+
ENV PATH=$PATH:/root/composer/vendor/bin \
250+
COMPOSER_ALLOW_SUPERUSER=1 \
251+
COMPOSER_HOME=/root/composer
252+
RUN cd /opt \
253+
# Download installer and check for its integrity.
254+
&& curl -sSL https://getcomposer.org/installer > composer-setup.php \
255+
&& curl -sSL https://composer.github.io/installer.sha384sum > composer-setup.sha384sum \
256+
&& sha384sum --check composer-setup.sha384sum \
257+
# Install Composer 2.
258+
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer --2 \
259+
# Remove installer files.
260+
&& rm /opt/composer-setup.php /opt/composer-setup.sha384sum

0 commit comments

Comments
 (0)