Skip to content

Merge pull request #30 from patchlevel/fix-docker-build-cache #129

Merge pull request #30 from patchlevel/fix-docker-build-cache

Merge pull request #30 from patchlevel/fix-docker-build-cache #129

Workflow file for this run

# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
name: "Continuous Integration"
on:
pull_request:
push:
branches:
- "main"
- "renovate/*"
schedule:
- cron: "0 0 * * 0"
env:
REGISTRY: ghcr.io
IMAGE_NAME: ghcr.io/${{ github.repository }}
permissions:
contents: read
packages: write
jobs:
build:
name: Build per-arch (push by digest on main)
strategy:
fail-fast: false
matrix:
platform:
- platform: linux/amd64
runner: ubuntu-24.04
id: linux-amd64
- platform: linux/arm64
runner: ubuntu-24.04-arm
id: linux-arm64
version: [ "8.1", "8.2", "8.3", "8.4", "8.5" ]
extensions:
- "pcntl xdebug zip intl bcmath rdkafka pdo_pgsql pdo_mysql gd opentelemetry mongodb"
runs-on: ${{ matrix.platform.runner }}
steps:
- name: Check out the repo
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
if: ${{ github.ref_name == 'main' }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ matrix.version }}
- name: Build (no push)
if: ${{ github.ref_name != 'main' }}
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platform.platform }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=gha,scope=ci-${{ matrix.version }}-${{ matrix.platform.id }}
type=gha,scope=release-${{ matrix.version }}-${{ matrix.platform.id }}
cache-to: |
type=gha,mode=max,scope=ci-${{ matrix.version }}-${{ matrix.platform.id }}
push: false
build-args: |
VERSION=${{ matrix.version }}
EXTENSIONS=${{ matrix.extensions }}
- name: Build and push (main only)
id: build_push
if: ${{ github.ref_name == 'main' }}
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platform.platform }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=gha,scope=ci-${{ matrix.version }}-${{ matrix.platform.id }}
type=gha,scope=release-${{ matrix.version }}-${{ matrix.platform.id }}
cache-to: |
type=gha,mode=max,scope=release-${{ matrix.version }}-${{ matrix.platform.id }}
outputs: |
type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
build-args: |
VERSION=${{ matrix.version }}
EXTENSIONS=${{ matrix.extensions }}
- name: Store digest (main only)
if: ${{ github.ref_name == 'main' }}
run: |
mkdir -p /tmp/digests
echo "${{ steps.build_push.outputs.digest }}" > "/tmp/digests/${{ matrix.version }}-${{ matrix.platform.id }}.txt"
- name: Upload digests (main only)
if: ${{ github.ref_name == 'main' }}
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.version }}-${{ matrix.platform.id }}
path: /tmp/digests/${{ matrix.version }}-${{ matrix.platform.id }}.txt
if-no-files-found: error
retention-days: 1
merge:
name: Create multi-arch manifest (main only)
if: ${{ github.ref_name == 'main' }}
needs: build
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
version: [ "8.1", "8.2", "8.3", "8.4", "8.5" ]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Download digests (amd64)
uses: actions/download-artifact@v4
with:
name: digests-${{ matrix.version }}-linux-amd64
path: /tmp/digests
- name: Download digests (arm64)
uses: actions/download-artifact@v4
with:
name: digests-${{ matrix.version }}-linux-arm64
path: /tmp/digests
- name: Create and push manifest list tag
run: |
set -euo pipefail
AMD_DIGEST="$(cat /tmp/digests/${{ matrix.version }}-linux-amd64.txt)"
ARM_DIGEST="$(cat /tmp/digests/${{ matrix.version }}-linux-arm64.txt)"
# Create a multi-arch manifest for :<version> that points to both per-arch digests
docker buildx imagetools create \
-t "${{ env.IMAGE_NAME }}:${{ matrix.version }}" \
"${{ env.IMAGE_NAME }}@${AMD_DIGEST}" \
"${{ env.IMAGE_NAME }}@${ARM_DIGEST}"
- name: Inspect manifest (debug)
run: |
docker buildx imagetools inspect "${{ env.IMAGE_NAME }}:${{ matrix.version }}"