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
119 changes: 102 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,26 @@ on:
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: whilesmartphp/frankenphp

jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write

strategy:
matrix:
php: ['8.2', '8.3', '8.4']
platform: ['linux/amd64', 'linux/arm64']
include:
- platform: linux/amd64
runner: ubuntu-latest
- platform: linux/arm64
runner: ubuntu-24.04-arm

steps:
- name: Checkout code
Expand All @@ -25,38 +39,109 @@ jobs:
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platform }}
build-args: PHP_VERSION=${{ matrix.php }}
push: ${{ github.event_name != 'pull_request' }}
tags: ghcr.io/whilesmartphp/frankenphp:${{ matrix.php }}
cache-from: type=gha,scope=php${{ matrix.php }}
cache-to: type=gha,mode=max,scope=php${{ matrix.php }}
cache-from: type=gha,scope=php${{ matrix.php }}-${{ matrix.platform }}
cache-to: type=gha,mode=max,scope=php${{ matrix.php }}-${{ matrix.platform }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}

tag-latest:
- name: Export digest
if: github.event_name != 'pull_request'
run: |
mkdir -p /tmp/digests/${{ matrix.php }}
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${{ matrix.php }}/${digest#sha256:}"

- name: Upload digest
if: github.event_name != 'pull_request'
uses: actions/upload-artifact@v4
with:
name: digest-${{ matrix.php }}-${{ matrix.runner }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using matrix.platform instead of matrix.runner in the artifact name is more descriptive of the actual payload, though the current implementation works.

Suggested change
name: digest-${{ matrix.php }}-${{ matrix.runner }}
name: digest-${{ matrix.php }}-${{ matrix.platform }}

path: /tmp/digests/${{ matrix.php }}
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
needs: build
permissions:
contents: read
packages: write

strategy:
matrix:
php: ['8.2', '8.3', '8.4']

steps:
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Download digests
uses: actions/download-artifact@v4
with:
pattern: digest-${{ matrix.php }}-*
merge-multiple: true
path: /tmp/digests

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

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ matrix.php }}
type=raw,value=${{ matrix.php }}-{{sha}}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)

- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.php }}

tag-latest:
needs: merge
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
permissions:
contents: read
packages: write

steps:
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Tag latest
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Tag 8.4 as latest
run: |
docker pull ghcr.io/whilesmartphp/frankenphp:8.4
docker tag ghcr.io/whilesmartphp/frankenphp:8.4 ghcr.io/whilesmartphp/frankenphp:latest
docker push ghcr.io/whilesmartphp/frankenphp:latest
docker buildx imagetools create \
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:8.4
Loading