Skip to content

Commit 7914e68

Browse files
committed
Add CI to build base images
1 parent 333e356 commit 7914e68

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

.github/workflows/buildx.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Build & Push Docker image (GHCR)
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
tags: [ "v*", "release-*" ]
7+
pull_request:
8+
branches: [ "main" ]
9+
10+
permissions:
11+
contents: read
12+
packages: write
13+
attestations: write
14+
id-token: write
15+
16+
env:
17+
REGISTRY: ghcr.io
18+
IMAGE_NAME: ${{ github.repository }}
19+
PLATFORMS: linux/arm64
20+
DOCKERFILE: dockerfiles/Dockerfile.base
21+
TARGET: archarm
22+
TAG_SUFFIX: minimal-aarch64
23+
24+
jobs:
25+
build:
26+
name: Build${{ github.event_name == 'pull_request' && ' (no push)' || '' }}
27+
runs-on: ubuntu-latest
28+
29+
concurrency:
30+
group: docker-${{ github.ref }}
31+
cancel-in-progress: true
32+
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v4
36+
37+
- name: Set up QEMU (for cross-compiling images)
38+
uses: docker/setup-qemu-action@v3
39+
40+
- name: Set up Docker Buildx
41+
uses: docker/setup-buildx-action@v3
42+
43+
- name: Log in to GHCR
44+
if: github.event_name != 'pull_request'
45+
uses: docker/login-action@v3
46+
with:
47+
registry: ${{ env.REGISTRY }}
48+
username: ${{ github.actor }}
49+
password: ${{ secrets.CI_TOKEN }}
50+
51+
- name: Derive image name
52+
id: img
53+
run: |
54+
echo "IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" >> $GITHUB_OUTPUT
55+
56+
- name: Extract Docker metadata (tags, labels)
57+
id: meta
58+
uses: docker/metadata-action@v5
59+
with:
60+
images: ${{ steps.img.outputs.IMAGE }}
61+
flavor: |
62+
suffix=-${{ env.TAG_SUFFIX }},onlatest=true
63+
# Tag strategy:
64+
# - main branch -> :latest and :sha
65+
# - tags like v1.2.3 -> :1.2.3 and :1.2 and :1
66+
# - PRs -> :pr-<num>-<sha>
67+
tags: |
68+
type=raw,value=latest,enable={{is_default_branch}}
69+
type=sha,format=short,prefix=,suffix=,enable={{is_default_branch}}
70+
type=ref,event=tag
71+
type=ref,event=pr
72+
73+
- name: Build (and push when not a PR)
74+
id: buildx
75+
uses: docker/build-push-action@v6
76+
with:
77+
context: .
78+
file: ${{ env.DOCKERFILE }}
79+
target: ${{ env.TARGET }}
80+
platforms: ${{ env.PLATFORMS }}
81+
push: ${{ github.event_name != 'pull_request' }}
82+
tags: ${{ steps.meta.outputs.tags }} # mirrors: -t $(IMAGE):minimal-aarch64 (+ semver / sha variants)
83+
labels: ${{ steps.meta.outputs.labels }}
84+
# Your local command used --load; in CI we push instead. (--load is single-arch only and not suited for multi-arch CI.)
85+
cache-from: type=gha
86+
cache-to: type=gha,mode=max
87+
provenance: true
88+
sbom: true
89+
90+
# Optional: attest the pushed image (supply chain)
91+
- name: Attest image (SLSA-style)
92+
if: github.event_name != 'pull_request'
93+
uses: actions/attest-build-provenance@v1
94+
with:
95+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
96+
subject-digest: ${{ steps.buildx.outputs.digest }}
97+
push-to-registry: true

0 commit comments

Comments
 (0)