Skip to content

Commit db954f4

Browse files
authored
Merge pull request #224 from stellarwp/2.1.2
2.1.2: Further Dockerfile/Workflow image building optimizations
2 parents ec240d0 + 1552e4b commit db954f4

File tree

6 files changed

+236
-71
lines changed

6 files changed

+236
-71
lines changed

.github/workflows/publish-slic-docker-image.yml

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,23 @@ on:
1010

1111
jobs:
1212
publish-slic-image:
13-
runs-on: ubuntu-latest
13+
runs-on: ${{ matrix.runner }}
1414
permissions:
1515
contents: read
1616
packages: write
1717
strategy:
1818
matrix:
1919
# The php_version is the docker tag from https://hub.docker.com/_/php/tags
2020
php_version: [ '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
21+
arch: [ 'amd64', 'arm64' ]
22+
# Add runner and platform info for each architecture
23+
include:
24+
- arch: amd64
25+
runner: ubuntu-latest
26+
platform: linux/amd64
27+
- arch: arm64
28+
runner: ubuntu-24.04-arm
29+
platform: linux/arm64
2130

2231
steps:
2332
- name: Checkout repository
@@ -46,9 +55,8 @@ jobs:
4655
type=ref,event=branch
4756
type=ref,event=tag
4857
type=semver,pattern={{raw}}
49-
50-
- name: Set up QEMU for multi-platform builds
51-
uses: docker/setup-qemu-action@v3
58+
flavor: |
59+
suffix=-${{ matrix.arch }},onlatest=true
5260
5361
- name: Set up Docker Buildx
5462
uses: docker/setup-buildx-action@v3
@@ -61,11 +69,46 @@ jobs:
6169
push: true
6270
tags: ${{ steps.meta.outputs.tags }}
6371
labels: ${{ steps.meta.outputs.labels }}
64-
# Use the faster registry cache.
65-
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}/cache/slic-php${{ matrix.php_version }}
66-
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}/cache/slic-php${{ matrix.php_version }},mode=max
72+
# Use the faster registry cache with platform-specific caching
73+
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}/cache/slic-php${{ matrix.php_version }}-${{ matrix.arch }}
74+
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}/cache/slic-php${{ matrix.php_version }}-${{ matrix.arch }},mode=max
6775
build-args: |
6876
PHP_VERSION=${{ matrix.php_version }}
6977
NODE_VERSION=18.17.0
7078
NVM_VERSION=v0.40.1
71-
platforms: linux/amd64,linux/arm64
79+
platforms: ${{ matrix.platform }}
80+
81+
create-slic-manifest:
82+
needs: publish-slic-image
83+
runs-on: ubuntu-latest
84+
permissions:
85+
contents: read
86+
packages: write
87+
strategy:
88+
matrix:
89+
php_version: [ '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
90+
steps:
91+
- name: Log in to the Container registry
92+
uses: docker/login-action@v3
93+
with:
94+
registry: ghcr.io
95+
username: ${{ github.actor }}
96+
password: ${{ secrets.GITHUB_TOKEN }}
97+
98+
- name: Create and push multi-arch manifest
99+
run: |
100+
# Determine the tag based on the event type
101+
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
102+
TAG="edge"
103+
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
104+
TAG="${GITHUB_REF#refs/tags/}"
105+
else
106+
TAG="${GITHUB_REF#refs/heads/}"
107+
fi
108+
109+
IMAGE_BASE="ghcr.io/${{ github.repository }}-php${{ matrix.php_version }}"
110+
111+
# Create multi-arch manifest
112+
docker buildx imagetools create -t "${IMAGE_BASE}:${TAG}" \
113+
"${IMAGE_BASE}:${TAG}-amd64" \
114+
"${IMAGE_BASE}:${TAG}-arm64"

.github/workflows/publish-wordpress-docker-image.yml

Lines changed: 107 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,77 @@ on:
1010

1111
jobs:
1212
publish-wordpress-image:
13-
runs-on: ubuntu-latest
13+
runs-on: ${{ matrix.runner }}
1414
permissions:
1515
contents: read
1616
packages: write
1717
strategy:
1818
matrix:
19-
wp_version: [ '6.2' ]
20-
php_version: [ '8.0', '8.1', '8.2' ]
2119
include:
22-
# No WordPress image for version 6.2+ and PHP 7.3: use the latest 5.9 version.
23-
# This version is NOT updated in the containers/wordpress/Dockerfile for back-compatibility.
20+
# WordPress 6.2 with PHP 8.0, 8.1, 8.2 - both architectures
21+
- wp_version: '6.2'
22+
php_version: '8.0'
23+
runner: ubuntu-latest
24+
platform: linux/amd64
25+
arch: amd64
26+
- wp_version: '6.2'
27+
php_version: '8.0'
28+
runner: ubuntu-24.04-arm
29+
platform: linux/arm64
30+
arch: arm64
31+
- wp_version: '6.2'
32+
php_version: '8.1'
33+
runner: ubuntu-latest
34+
platform: linux/amd64
35+
arch: amd64
36+
- wp_version: '6.2'
37+
php_version: '8.1'
38+
runner: ubuntu-24.04-arm
39+
platform: linux/arm64
40+
arch: arm64
41+
- wp_version: '6.2'
42+
php_version: '8.2'
43+
runner: ubuntu-latest
44+
platform: linux/amd64
45+
arch: amd64
46+
- wp_version: '6.2'
47+
php_version: '8.2'
48+
runner: ubuntu-24.04-arm
49+
platform: linux/arm64
50+
arch: arm64
51+
# WordPress 5.9 with PHP 7.3 - both architectures
52+
- wp_version: '5.9'
53+
php_version: '7.3'
54+
runner: ubuntu-latest
55+
platform: linux/amd64
56+
arch: amd64
2457
- wp_version: '5.9'
2558
php_version: '7.3'
26-
# No WordPress image for version 6.2+ and PHP 7.4: use the latest 6.1.1 version.
27-
# See containers/wordpress/Dockerfile for the wp-cli update to version 6.2.
59+
runner: ubuntu-24.04-arm
60+
platform: linux/arm64
61+
arch: arm64
62+
# WordPress 6.1.1 with PHP 7.4 - both architectures
2863
- wp_version: '6.1.1'
2964
php_version: '7.4'
30-
# Use the latest 6.5 WordPress version for PHP 8.3.
65+
runner: ubuntu-latest
66+
platform: linux/amd64
67+
arch: amd64
68+
- wp_version: '6.1.1'
69+
php_version: '7.4'
70+
runner: ubuntu-24.04-arm
71+
platform: linux/arm64
72+
arch: arm64
73+
# WordPress 6.5 with PHP 8.3 - both architectures
74+
- wp_version: '6.5'
75+
php_version: '8.3'
76+
runner: ubuntu-latest
77+
platform: linux/amd64
78+
arch: amd64
3179
- wp_version: '6.5'
3280
php_version: '8.3'
81+
runner: ubuntu-24.04-arm
82+
platform: linux/arm64
83+
arch: arm64
3384

3485
steps:
3586
- name: Checkout repository
@@ -58,9 +109,8 @@ jobs:
58109
type=ref,event=branch
59110
type=ref,event=tag
60111
type=semver,pattern={{raw}}
61-
62-
- name: Set up QEMU
63-
uses: docker/setup-qemu-action@v3
112+
flavor: |
113+
suffix=-${{ matrix.arch }},onlatest=true
64114
65115
- name: Set up Docker Buildx
66116
uses: docker/setup-buildx-action@v3
@@ -73,10 +123,52 @@ jobs:
73123
push: true
74124
tags: ${{ steps.meta.outputs.tags }}
75125
labels: ${{ steps.meta.outputs.labels }}
76-
# Use the faster registry cache.
77-
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}/cache/slic-wp-${{ matrix.wp_version }}-${{ matrix.php_version }}
78-
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}/cache/slic-wp-${{ matrix.wp_version }}-${{ matrix.php_version }},mode=max
126+
# Use the faster registry cache with platform-specific caching
127+
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}/cache/slic-wp-${{ matrix.wp_version }}-${{ matrix.php_version }}-${{ matrix.arch }}
128+
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}/cache/slic-wp-${{ matrix.wp_version }}-${{ matrix.php_version }}-${{ matrix.arch }},mode=max
79129
build-args: |
80130
PHP_VERSION=${{ matrix.php_version }}
81131
WP_VERSION=${{ matrix.wp_version }}
82-
platforms: linux/amd64,linux/arm64
132+
platforms: ${{ matrix.platform }}
133+
134+
create-wordpress-manifest:
135+
needs: publish-wordpress-image
136+
runs-on: ubuntu-latest
137+
permissions:
138+
contents: read
139+
packages: write
140+
strategy:
141+
matrix:
142+
# Match the unique combinations from the build matrix
143+
include:
144+
- php_version: '8.0'
145+
- php_version: '8.1'
146+
- php_version: '8.2'
147+
- php_version: '7.3'
148+
- php_version: '7.4'
149+
- php_version: '8.3'
150+
steps:
151+
- name: Log in to the Container registry
152+
uses: docker/login-action@v3
153+
with:
154+
registry: ghcr.io
155+
username: ${{ github.actor }}
156+
password: ${{ secrets.GITHUB_TOKEN }}
157+
158+
- name: Create and push multi-arch manifest
159+
run: |
160+
# Determine the tag based on the event type
161+
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
162+
TAG="edge"
163+
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
164+
TAG="${GITHUB_REF#refs/tags/}"
165+
else
166+
TAG="${GITHUB_REF#refs/heads/}"
167+
fi
168+
169+
IMAGE_BASE="ghcr.io/${{ github.repository }}-wordpress-php${{ matrix.php_version }}"
170+
171+
# Create multi-arch manifest
172+
docker buildx imagetools create -t "${IMAGE_BASE}:${TAG}" \
173+
"${IMAGE_BASE}:${TAG}-amd64" \
174+
"${IMAGE_BASE}:${TAG}-arm64"

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
# [2.1.2] - 2025-11-13
8+
- Change - GitHub Actions workflows now use native ARM64 runners (`ubuntu-24.04-arm`) instead of QEMU emulation for multi-platform builds, to reduce build times.
9+
- Change - Optimized Dockerfile layer ordering to improve cache hit rates - local config files moved to end to prevent invalidating heavy system installation layers.
10+
- Change - Added BuildKit cache mounts for apt package installation and PHP extension compilation, to reduce subsequent build times.
11+
- Change - Added `IPE_CACHE_DIR` environment variable to cache PHP extension downloads and compiled artifacts across builds.
12+
- Change - Implemented platform-specific registry caching (separate caches for amd64/arm64) to prevent cache conflicts and maximize reuse.
13+
714
# [2.1.1] - 2025-11-04
815
- Change - Optimize docker builds and workflows for slic and WordPress containers.
916

containers/slic/Dockerfile

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ ARG TARGETPLATFORM
1313

1414
SHELL ["/bin/bash", "-eou", "pipefail", "-c"]
1515

16+
# -------------------------------
17+
# Environment variables
18+
# -------------------------------
19+
# Disable AVIF for GD https://github.com/mlocati/docker-php-extension-installer#configuration
20+
ENV IPE_GD_WITHOUTAVIF=${IPE_GD_WITHOUTAVIF}
21+
ENV NVM_VERSION=${NVM_VERSION}
22+
ENV NVM_DIR=/usr/local/bin/.nvm
23+
ENV IPE_CACHE_DIR=/tmp/ipe-cache
24+
1625
# -------------------------------
1726
# WP-CLI & PHP extension installer
1827
# -------------------------------
@@ -21,20 +30,19 @@ ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/do
2130

2231
RUN chmod a+rx /usr/local/bin/wp /usr/local/bin/install-php-extensions
2332

24-
# Disable AVIF for GD https://github.com/mlocati/docker-php-extension-installer#configuration
25-
ENV IPE_GD_WITHOUTAVIF=${IPE_GD_WITHOUTAVIF}
26-
RUN install-php-extensions xdebug pdo pdo_mysql mysqli zip uopz pcntl sockets intl exif gd
27-
2833
# -------------------------------
29-
# NVM environment variables
34+
# PHP extensions (heavy compilation step with cache mount)
3035
# -------------------------------
31-
ENV NVM_VERSION=${NVM_VERSION}
32-
ENV NVM_DIR=/usr/local/bin/.nvm
36+
RUN --mount=type=cache,target=/tmp/ipe-cache,sharing=locked \
37+
install-php-extensions xdebug pdo pdo_mysql mysqli zip uopz pcntl sockets intl exif gd
3338

3439
# -------------------------------
35-
# Dependencies for NVM & general builds
40+
# System dependencies (with cache mount for speed)
3641
# -------------------------------
37-
RUN apt-get update && \
42+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
43+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
44+
rm -f /etc/apt/apt.conf.d/docker-clean && \
45+
apt-get update && \
3846
apt-get install -yqq --no-install-recommends \
3947
ca-certificates curl git zip unzip iproute2 \
4048
libnss3 libnspr4 libdbus-1-3 libatk1.0-0 libatk-bridge2.0-0 \
@@ -66,25 +74,7 @@ RUN set -eux; \
6674
node -v; npm -v
6775

6876
# -------------------------------
69-
# PHP uopz extension & XDebug
70-
# -------------------------------
71-
COPY ./docker-php-ext-uopz.ini /usr/local/etc/php/conf.d/docker-php-ext-uopz.ini
72-
COPY ./xdebug-on.sh /usr/local/bin/xdebug-on
73-
COPY ./xdebug-off.sh /usr/local/bin/xdebug-off
74-
75-
RUN chmod a+x /usr/local/bin/xdebug-on /usr/local/bin/xdebug-off && \
76-
chmod -R a+rwx /usr/local/etc/php/conf.d && xdebug-off
77-
78-
# -------------------------------
79-
# Composer 1 & 2
80-
# -------------------------------
81-
COPY --from=composer1 /usr/bin/composer /usr/local/bin/composer1
82-
COPY --from=composer2 /usr/bin/composer /usr/local/bin/composer
83-
84-
RUN chmod a+x /usr/local/bin/composer /usr/local/bin/composer1
85-
86-
# -------------------------------
87-
# Slic user & fixuid
77+
# Slic user & fixuid setup
8878
# -------------------------------
8979
RUN groupadd -g 1000 slic 2>/dev/null || true && \
9080
useradd -u 1000 -g 1000 -m -s /bin/bash slic 2>/dev/null || true && \
@@ -95,22 +85,37 @@ RUN groupadd -g 1000 slic 2>/dev/null || true && \
9585
esac && \
9686
curl -SsL https://github.com/boxboat/fixuid/releases/download/v0.6.0/fixuid-0.6.0-linux-$FIXUID_ARCH.tar.gz \
9787
| tar -C /usr/local/bin -xzf - && \
98-
chown root:root /usr/local/bin/fixuid && chmod 4755 /usr/local/bin/fixuid && \
88+
chown root:root /usr/local/bin/fixuid && \
89+
chmod 4755 /usr/local/bin/fixuid && \
9990
mkdir -p /etc/fixuid
10091

92+
# -------------------------------
93+
# Composer 1 & 2 from multi-stage builds
94+
# -------------------------------
95+
COPY --from=composer1 /usr/bin/composer /usr/local/bin/composer1
96+
COPY --from=composer2 /usr/bin/composer /usr/local/bin/composer
97+
98+
# -------------------------------
99+
# Local config files (moved late for better caching)
100+
# -------------------------------
101+
COPY ./docker-php-ext-uopz.ini /usr/local/etc/php/conf.d/docker-php-ext-uopz.ini
102+
COPY ./xdebug-on.sh /usr/local/bin/xdebug-on
103+
COPY ./xdebug-off.sh /usr/local/bin/xdebug-off
101104
COPY ./fixuid.yml /etc/fixuid/config.yml
102105
COPY ./.bashrc /home/slic/.bashrc
103106
COPY ./.bashrc /root/.bashrc
104107
COPY ./bashrc_scripts.sh /home/slic/bashrc_scripts.sh
105-
106-
# Ensure NVM directory is owned by slic
107-
RUN chown -R slic:slic $NVM_DIR
108+
COPY ./slic-entrypoint.sh /usr/local/bin/slic-entrypoint.sh
108109

109110
# -------------------------------
110-
# Entrypoint
111+
# Final permissions & setup
111112
# -------------------------------
112-
COPY ./slic-entrypoint.sh /usr/local/bin/slic-entrypoint.sh
113-
RUN chmod a+x /usr/local/bin/slic-entrypoint.sh
113+
RUN chmod a+x /usr/local/bin/xdebug-on /usr/local/bin/xdebug-off \
114+
/usr/local/bin/composer /usr/local/bin/composer1 \
115+
/usr/local/bin/slic-entrypoint.sh && \
116+
chmod -R a+rwx /usr/local/etc/php/conf.d && \
117+
chown -R slic:slic $NVM_DIR && \
118+
xdebug-off
114119

115120
ENTRYPOINT ["/usr/local/bin/slic-entrypoint.sh"]
116121

0 commit comments

Comments
 (0)