Skip to content

Commit f6afff4

Browse files
authored
Merge pull request #516 from rinkp/fix/build-stability
Fix: Improve build stability and reproducibility
2 parents 1c30e59 + 0df7813 commit f6afff4

File tree

2 files changed

+76
-56
lines changed

2 files changed

+76
-56
lines changed

docker/web/development/Dockerfile

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
ARG BASE="alpine:latest"
2-
ARG PHPVERSION="php83"
1+
ARG ALPINE_VERSION="3.23"
2+
ARG BASE="alpine:$ALPINE_VERSION"
3+
4+
ARG PHP_MAJOR="8"
5+
ARG PHP_MINOR="3"
6+
ARG PHP_VERSION=$PHP_MAJOR$PHP_MINOR
7+
8+
ARG COMPOSER_VERSION="2.9"
9+
310
ARG BUILDTYPE="development"
411

512
# Compile the language files (shared between dev and prod)
@@ -16,9 +23,11 @@ COPY ./module/Application/language/*.po ./
1623
RUN msgfmt en.po -o en -c --strict -v \
1724
&& msgfmt nl.po -o nl -c --strict -v
1825

26+
FROM composer:${COMPOSER_VERSION} AS gewisdb_composer
27+
1928
# Install dependencies
2029
FROM ${BASE} AS gewisdb_web_development_base
21-
ARG PHPVERSION
30+
ARG PHP_VERSION
2231

2332
WORKDIR /code
2433

@@ -30,25 +39,25 @@ RUN --mount=type=cache,target=/var/cache/apk,sharing=locked \
3039
icu-data-full \
3140
git \
3241
nano \
33-
${PHPVERSION} \
34-
${PHPVERSION}-calendar \
35-
${PHPVERSION}-curl \
36-
${PHPVERSION}-dom \
37-
${PHPVERSION}-fpm \
38-
${PHPVERSION}-iconv \
39-
${PHPVERSION}-intl \
40-
${PHPVERSION}-ldap \
41-
${PHPVERSION}-mbstring \
42-
${PHPVERSION}-opcache \
43-
${PHPVERSION}-openssl \
44-
${PHPVERSION}-pdo_pgsql \
45-
${PHPVERSION}-pecl-xdebug \
46-
${PHPVERSION}-phar \
47-
${PHPVERSION}-session \
48-
${PHPVERSION}-simplexml \
49-
${PHPVERSION}-tokenizer \
50-
${PHPVERSION}-xml \
51-
${PHPVERSION}-xmlwriter \
42+
php${PHP_VERSION} \
43+
php${PHP_VERSION}-calendar \
44+
php${PHP_VERSION}-curl \
45+
php${PHP_VERSION}-dom \
46+
php${PHP_VERSION}-fpm \
47+
php${PHP_VERSION}-iconv \
48+
php${PHP_VERSION}-intl \
49+
php${PHP_VERSION}-ldap \
50+
php${PHP_VERSION}-mbstring \
51+
php${PHP_VERSION}-opcache \
52+
php${PHP_VERSION}-openssl \
53+
php${PHP_VERSION}-pdo_pgsql \
54+
php${PHP_VERSION}-pecl-xdebug \
55+
php${PHP_VERSION}-phar \
56+
php${PHP_VERSION}-session \
57+
php${PHP_VERSION}-simplexml \
58+
php${PHP_VERSION}-tokenizer \
59+
php${PHP_VERSION}-xml \
60+
php${PHP_VERSION}-xmlwriter \
5261
&& runtimeDeps="$( \
5362
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
5463
| tr ',' '\n' \
@@ -59,19 +68,20 @@ RUN --mount=type=cache,target=/var/cache/apk,sharing=locked \
5968
&& cp /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime \
6069
&& echo 'Europe/Amsterdam' > /etc/timezone \
6170
&& apk del .build-deps \
62-
&& ln -s /usr/sbin/php-fpm83 /usr/sbin/php-fpm \
63-
&& rm /etc/${PHPVERSION}/php-fpm.d/www.conf \
71+
&& ln -s ./php-fpm${PHP_VERSION} /usr/sbin/php-fpm \
72+
&& ln -s ./php${PHP_VERSION} /usr/bin/php \
73+
&& rm /etc/php${PHP_VERSION}/php-fpm.d/www.conf \
6474
&& rm /etc/crontabs/root
6575

6676
RUN adduser -S --uid 82 -D -H www-data -G www-data
6777

6878
# Copy composer over (needed for replenish)
69-
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
79+
COPY --from=gewisdb_composer /usr/bin/composer /usr/bin/composer
7080

7181
ENV COMPOSER_ALLOW_SUPERUSER=1
7282

7383
RUN --mount=type=cache,target=/root/.composer,sharing=locked \
74-
--mount=from=composer:latest,source=/usr/bin/composer,target=/usr/bin/composer \
84+
--mount=from=gewisdb_composer,source=/usr/bin/composer,target=/usr/bin/composer \
7585
--mount=source=./composer.json,target=/code/composer.json \
7686
--mount=source=./composer.lock,target=/code/composer.lock \
7787
composer install
@@ -80,8 +90,8 @@ RUN --mount=type=cache,target=/root/.composer,sharing=locked \
8090
FROM gewisdb_web_development_base AS gewisdb_web_development
8191
ARG BUILDTYPE
8292

83-
COPY ./docker/web/${BUILDTYPE}/php.ini /etc/${PHPVERSION}/php.ini
84-
COPY ./docker/web/${BUILDTYPE}/php-fpm.conf /etc/${PHPVERSION}/php-fpm.d/zz-gewisdb.conf
93+
COPY ./docker/web/${BUILDTYPE}/php.ini /etc/php${PHP_VERSION}/php.ini
94+
COPY ./docker/web/${BUILDTYPE}/php-fpm.conf /etc/php${PHP_VERSION}/php-fpm.d/zz-gewisdb.conf
8595
COPY ./config/autoload/local.${BUILDTYPE}.php.dist ./config/autoload/local.php
8696
COPY ./config/autoload/doctrine.local.${BUILDTYPE}.php.dist ./config/autoload/doctrine.local.php
8797
COPY ./config/autoload/laminas-developer-tools.local.php.dist ./config/autoload/laminas-developer-tools.local.php
@@ -99,7 +109,7 @@ RUN chmod +x ./orm ./web
99109

100110
ENV PHP_IDE_CONFIG="serverName=database.gewis.nl"
101111

102-
RUN --mount=from=composer:latest,source=/usr/bin/composer,target=/usr/bin/composer \
112+
RUN --mount=from=gewisdb_composer,source=/usr/bin/composer,target=/usr/bin/composer \
103113
composer dump-autoload
104114

105115
# Set up a persistent data volumes

docker/web/production/Dockerfile

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
ARG BASE="alpine:latest"
2-
ARG PHPVERSION="php83"
1+
ARG ALPINE_VERSION="3.23"
2+
ARG BASE="alpine:$ALPINE_VERSION"
3+
4+
ARG PHP_MAJOR="8"
5+
ARG PHP_MINOR="3"
6+
ARG PHP_VERSION=$PHP_MAJOR$PHP_MINOR
7+
8+
ARG COMPOSER_VERSION="2.9"
9+
310
ARG BUILDTYPE="production"
411

512
# Compile the language files (shared between dev and prod)
@@ -16,9 +23,11 @@ COPY ./module/Application/language/*.po ./
1623
RUN msgfmt en.po -o en -c --strict -v \
1724
&& msgfmt nl.po -o nl -c --strict -v
1825

26+
FROM composer:${COMPOSER_VERSION} AS gewisdb_composer
27+
1928
# Install dependencies
2029
FROM ${BASE} AS gewisdb_web_production_base
21-
ARG PHPVERSION
30+
ARG PHP_VERSION
2231

2332
WORKDIR /code
2433

@@ -29,24 +38,24 @@ RUN --mount=type=cache,target=/var/cache/apk,sharing=locked \
2938
&& apk add --virtual .runtime-programs \
3039
icu-data-full \
3140
git \
32-
${PHPVERSION} \
33-
${PHPVERSION}-calendar \
34-
${PHPVERSION}-curl \
35-
${PHPVERSION}-dom \
36-
${PHPVERSION}-fpm \
37-
${PHPVERSION}-iconv \
38-
${PHPVERSION}-intl \
39-
${PHPVERSION}-ldap \
40-
${PHPVERSION}-mbstring \
41-
${PHPVERSION}-opcache \
42-
${PHPVERSION}-openssl \
43-
${PHPVERSION}-pdo_pgsql \
44-
${PHPVERSION}-phar \
45-
${PHPVERSION}-session \
46-
${PHPVERSION}-simplexml \
47-
${PHPVERSION}-tokenizer \
48-
${PHPVERSION}-xml \
49-
${PHPVERSION}-xmlwriter \
41+
php${PHP_VERSION} \
42+
php${PHP_VERSION}-calendar \
43+
php${PHP_VERSION}-curl \
44+
php${PHP_VERSION}-dom \
45+
php${PHP_VERSION}-fpm \
46+
php${PHP_VERSION}-iconv \
47+
php${PHP_VERSION}-intl \
48+
php${PHP_VERSION}-ldap \
49+
php${PHP_VERSION}-mbstring \
50+
php${PHP_VERSION}-opcache \
51+
php${PHP_VERSION}-openssl \
52+
php${PHP_VERSION}-pdo_pgsql \
53+
php${PHP_VERSION}-phar \
54+
php${PHP_VERSION}-session \
55+
php${PHP_VERSION}-simplexml \
56+
php${PHP_VERSION}-tokenizer \
57+
php${PHP_VERSION}-xml \
58+
php${PHP_VERSION}-xmlwriter \
5059
&& runtimeDeps="$( \
5160
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
5261
| tr ',' '\n' \
@@ -57,16 +66,17 @@ RUN --mount=type=cache,target=/var/cache/apk,sharing=locked \
5766
&& cp /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime \
5867
&& echo 'Europe/Amsterdam' > /etc/timezone \
5968
&& apk del .build-deps \
60-
&& ln -s /usr/sbin/php-fpm83 /usr/sbin/php-fpm \
61-
&& rm /etc/${PHPVERSION}/php-fpm.d/www.conf \
69+
&& ln -s ./php-fpm${PHP_VERSION} /usr/sbin/php-fpm \
70+
&& ln -s ./php${PHP_VERSION} /usr/bin/php \
71+
&& rm /etc/php${PHP_VERSION}/php-fpm.d/www.conf \
6272
&& rm /etc/crontabs/root
6373

6474
RUN adduser -S --uid 82 -D -H www-data -G www-data
6575

6676
ENV COMPOSER_ALLOW_SUPERUSER=1
6777

6878
RUN --mount=type=cache,target=/root/.composer,sharing=locked \
69-
--mount=from=composer:latest,source=/usr/bin/composer,target=/usr/bin/composer \
79+
--mount=from=gewisdb_composer,source=/usr/bin/composer,target=/usr/bin/composer \
7080
--mount=source=./composer.json,target=/code/composer.json \
7181
--mount=source=./composer.lock,target=/code/composer.lock \
7282
composer install -o --no-dev
@@ -75,8 +85,8 @@ RUN --mount=type=cache,target=/root/.composer,sharing=locked \
7585
FROM gewisdb_web_production_base AS gewisdb_web_production
7686
ARG BUILDTYPE
7787

78-
COPY ./docker/web/${BUILDTYPE}/php.ini /etc/${PHPVERSION}/php.ini
79-
COPY ./docker/web/${BUILDTYPE}/php-fpm.conf /etc/${PHPVERSION}/php-fpm.d/zz-gewisdb.conf
88+
COPY ./docker/web/${BUILDTYPE}/php.ini /etc/php${PHP_VERSION}/php.ini
89+
COPY ./docker/web/${BUILDTYPE}/php-fpm.conf /etc/php${PHP_VERSION}/php-fpm.d/zz-gewisdb.conf
8090
COPY ./config/autoload/local.${BUILDTYPE}.php.dist ./config/autoload/local.php
8191
COPY ./config/autoload/doctrine.local.${BUILDTYPE}.php.dist ./config/autoload/doctrine.local.php
8292

@@ -91,7 +101,7 @@ COPY --from=gewisdb_translations /translations/*.mo /code/module/Application/lan
91101

92102
RUN chmod +x ./orm ./web
93103

94-
RUN --mount=from=composer:latest,source=/usr/bin/composer,target=/usr/bin/composer \
104+
RUN --mount=from=gewisdb_composer,source=/usr/bin/composer,target=/usr/bin/composer \
95105
composer dump-autoload -a --no-dev
96106

97107
# Set up a persistent data volumes

0 commit comments

Comments
 (0)