Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 140 additions & 48 deletions .github/workflows/docker.build.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Build Docker images
on:
workflow_dispatch:
repository_dispatch:
types: [php-images-built]
push:
Expand All @@ -8,14 +9,17 @@ on:
tags:
- 'v*.*.*'

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
php: [ "8.2", "8.3", "8.4", "8.5" ]
env:
IMAGE_DOCKER_HUB: flownative/beach-php
IMAGE_HARBOR: harbor.flownative.io/docker/beach-php
PHP_IMAGE: harbor.flownative.io/docker/php

jobs:
# The images are always built from the latest release.
prepare:
runs-on: ubuntu-26.04
outputs:
tag: ${{ steps.latest_version.outputs.tag }}
steps:
- uses: actions/checkout@v7
with:
Expand All @@ -26,51 +30,118 @@ jobs:
id: latest_version
uses: flownative/action-git-latest-release@v1

- run: |
sudo chmod -R ugo+rwX . && shopt -s dotglob && rm -rf *

# Every platform is built natively on a runner of its own instead of
# emulating arm64 with QEMU. The images are pushed by digest only and
# tagged in the merge job.
build:
needs: prepare
strategy:
matrix:
php: [ "8.2", "8.3", "8.4", "8.5" ]
platform: [ linux/amd64, linux/arm64 ]
include:
- platform: linux/amd64
runner: ubuntu-26.04
- platform: linux/arm64
runner: ubuntu-26.04-arm
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v7
with:
ref: ${{ steps.latest_version.outputs.tag }}
fetch-depth: 100
ref: ${{ needs.prepare.outputs.tag }}

- name: Determine latest built PHP ${{ matrix.php }} version
id: latest_php_version
uses: flownative/action-docker-get-label@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4

- name: Login to Docker Hub
uses: docker/login-action@v4
with:
image: harbor.flownative.io/docker/php:${{ matrix.php }}
label: org.opencontainers.image.version
registry_endpoint: https://harbor.flownative.io
registry_username: ${{ secrets.HARBOR_DOCKER_USERNAME }}
registry_password: ${{ secrets.HARBOR_DOCKER_PASSWORD }}
username: ${{ secrets.DOCKER_IO_REGISTRY_USER }}
password: ${{ secrets.DOCKER_IO_REGISTRY_PASSWORD }}

- name: Login to Harbor
uses: docker/login-action@v4
with:
registry: harbor.flownative.io
username: ${{ secrets.HARBOR_DOCKER_USERNAME }}
password: ${{ secrets.HARBOR_DOCKER_PASSWORD }}

# The digest artifact is named after the PHP version found here. Should
# docker-php publish a new version between the jobs of the two
# platforms, the merge job finds only one digest per version and fails
# instead of combining images of different PHP versions.
- name: Determine latest built PHP ${{ matrix.php }} version
id: php
env:
PHP_BRANCH: ${{ matrix.php }}
PLATFORM: ${{ matrix.platform }}
run: |
set -euo pipefail
version="$(docker buildx imagetools inspect "${PHP_IMAGE}:${PHP_BRANCH}" \
--format '{{ index (index .Image "linux/amd64").Config.Labels "org.opencontainers.image.version" }}')"
if ! [[ "${version}" =~ ^${PHP_BRANCH//./\\.}\.[0-9]+$ ]]; then
echo "::error::${PHP_IMAGE}:${PHP_BRANCH} has an unexpected version label: '${version}'"
exit 1
fi
echo "version=${version}" >> "${GITHUB_OUTPUT}"
echo "artifact=digest-${version}-${PLATFORM#linux/}" >> "${GITHUB_OUTPUT}"

- name: Docker meta
id: meta
uses: docker/metadata-action@v6
with:
flavor: |
latest=false
images: |
flownative/beach-php
harbor.flownative.io/docker/beach-php
${{ env.IMAGE_DOCKER_HUB }}
${{ env.IMAGE_HARBOR }}
labels: |
org.opencontainers.image.title=Beach PHP
org.opencontainers.image.description=Docker image providing PHP for Beach and Local Beach
org.opencontainers.image.licenses=MIT
org.opencontainers.image.vendor=Flownative GmbH
org.opencontainers.image.authors=Robert Lemke <robert@flownative.com>
org.opencontainers.image.version=${{ steps.latest_php_version.outputs.value }}
tags: |
type=semver,pattern={{major}}.{{minor}},value=${{ steps.latest_php_version.outputs.value }}
type=semver,pattern={{version}},value=${{ steps.latest_php_version.outputs.value }}

- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v4

-
name: Set up Docker Buildx
id: buildx
org.opencontainers.image.version=${{ steps.php.outputs.version }}

- name: Build Docker image
id: build
uses: docker/build-push-action@v7
with:
context: .
platforms: ${{ matrix.platform }}
pull: true
build-args: |
PHP_BASE_IMAGE=${{ env.PHP_IMAGE }}:${{ steps.php.outputs.version }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,"name=${{ env.IMAGE_DOCKER_HUB }},${{ env.IMAGE_HARBOR }}",push-by-digest=true,name-canonical=true,push=true

- name: Export digest
env:
DIGEST: ${{ steps.build.outputs.digest }}
run: |
mkdir -p "${RUNNER_TEMP}/digests"
touch "${RUNNER_TEMP}/digests/${DIGEST#sha256:}"

- name: Upload digest
uses: actions/upload-artifact@v7
with:
name: ${{ steps.php.outputs.artifact }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1

# Combines the images of all platforms into one manifest list per PHP
# version and tags it in both registries. The PHP versions are taken from
# the names of the digest artifacts, so they are listed only once above.
merge:
needs: build
runs-on: ubuntu-26.04
steps:
- name: Download digests
uses: actions/download-artifact@v8
with:
path: ${{ runner.temp }}/digests
pattern: digest-*

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4

- name: Login to Docker Hub
Expand All @@ -86,20 +157,41 @@ jobs:
username: ${{ secrets.HARBOR_DOCKER_USERNAME }}
password: ${{ secrets.HARBOR_DOCKER_PASSWORD }}

- name: Build Docker image
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
build-args: |
PHP_BASE_IMAGE=harbor.flownative.io/docker/php:${{ steps.latest_php_version.outputs.value }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# Each registry gets its manifest list from the images pushed to that
# same registry, so no blobs have to be copied between registries.
- name: Create manifest lists
working-directory: ${{ runner.temp }}/digests
run: |
set -euo pipefail
versions="$(find . -mindepth 1 -maxdepth 1 -type d -name 'digest-*' | sed -n 's|^\./digest-\([0-9.]*\)-[a-z0-9]*$|\1|p' | sort -u)"
[ -n "${versions}" ] || { echo "::error::No digests found"; exit 1; }
for version in ${versions}; do
# Each artifact is a directory holding one empty file named
# after the digest.
digests="$(find . -mindepth 2 -path "./digest-${version}-*/*" -type f -exec basename {} \;)"
count="$(echo "${digests}" | wc -w | tr -d ' ')"
if [ "${count}" -ne 2 ]; then
echo "::error::PHP ${version}: expected 2 digests, found ${count}"
exit 1
fi
for image in "${IMAGE_DOCKER_HUB}" "${IMAGE_HARBOR}"; do
sources=()
for digest in ${digests}; do
sources+=("${image}@sha256:${digest}")
done
echo "::group::${image}:${version}"
docker buildx imagetools create \
--tag "${image}:${version%.*}" \
--tag "${image}:${version}" \
"${sources[@]}"
docker buildx imagetools inspect "${image}:${version}"
echo "::endgroup::"
done
done

announce:
runs-on: ubuntu-latest
needs: build
runs-on: ubuntu-26.04
needs: merge
steps:
- name: Dispatch to beach-php-k8s
uses: peter-evans/repository-dispatch@v4
Expand Down
Loading