Skip to content

Commit 0aad780

Browse files
committed
Adjust workflow
* Trigger build for PR, but only when from the same repo * Multi-arch build * Uses "docker/metadata" action to set up labels and tags
1 parent 21ffc79 commit 0aad780

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

.github/workflows/docker-build.yml

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,59 @@ on:
1010
- slides/**
1111
- images/**
1212
- .gitignore
13+
pull_request:
14+
paths-ignore:
15+
- "*.md"
16+
- slides/**
17+
- images/**
18+
- .gitignore
1319
workflow_dispatch:
1420

1521
jobs:
1622
build-and-push:
1723
runs-on: ubuntu-latest
1824
permissions:
1925
packages: write
26+
strategy:
27+
matrix:
28+
arch: [amd64, arm64]
29+
fail-fast: false
2030
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
- name: Set up QEMU
35+
uses: docker/setup-qemu-action@v3
36+
2137
- name: Setup Docker Buildx
2238
uses: docker/setup-buildx-action@v3
2339

2440
- name: Log in to GHCR
41+
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
2542
uses: docker/login-action@v3
2643
with:
2744
registry: ghcr.io
2845
username: ${{ github.actor }}
2946
password: ${{ secrets.GITHUB_TOKEN }}
3047

48+
- name: Docker meta
49+
id: meta
50+
uses: docker/metadata-action@v5
51+
with:
52+
images: ghcr.io/${{ github.repository }}
53+
tags: |
54+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' && matrix.arch == 'amd64' }}
55+
type=ref,event=branch
56+
type=ref,event=pr
57+
type=sha,format=short
58+
flavor: |
59+
suffix=-${{ matrix.arch }}
60+
3161
- name: Build and push
3262
uses: docker/build-push-action@v6
3363
with:
34-
platforms: linux/amd64,linux/arm64
35-
push: true
36-
tags: ghcr.io/${{ github.repository }}:latest
64+
context: .
65+
platforms: linux/${{ matrix.arch }}
66+
push: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
67+
tags: ${{ steps.meta.outputs.tags }}
68+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)