Skip to content

Commit 6baa5d7

Browse files
committed
Refactor and cleanup FTL build workflows
- tag nightly builds on both schedule and push to master branch - tag latest on release types - only set up QEMU for relevant platform - No need for QEMU on the merge job - Set riscv64 runner to arm variant - utilise YAML anchors to reduce duplication - separate publish and test jobs to make it easier to follow Signed-off-by: Adam Warner <[email protected]>
1 parent ac06bbe commit 6baa5d7

3 files changed

Lines changed: 200 additions & 217 deletions

File tree

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: ftl-build build and publish
2+
3+
on:
4+
schedule:
5+
# 1:30am UTC every Sunday, has no particular significance
6+
- cron: "30 1 * * 0"
7+
push:
8+
branches:
9+
- 'master'
10+
release:
11+
types: [published]
12+
13+
permissions:
14+
contents: read
15+
packages: write
16+
17+
env:
18+
DOCKER_REGISTRY_IMAGE: ${{ secrets.DOCKERHUB_NAMESPACE }}/ftl-build
19+
GITHUB_REGISTRY_IMAGE: ghcr.io/${{ github.repository_owner }}/ftl-build
20+
21+
jobs:
22+
build:
23+
runs-on: ${{ matrix.runner }}
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
include:
28+
- platform: linux/amd64
29+
runner: ubuntu-24.04
30+
- platform: linux/386
31+
runner: ubuntu-24.04
32+
- platform: linux/arm/v6
33+
runner: ubuntu-24.04-arm
34+
- platform: linux/arm/v7
35+
runner: ubuntu-24.04-arm
36+
- platform: linux/arm64/v8
37+
runner: ubuntu-24.04-arm
38+
- platform: linux/riscv64
39+
runner: ubuntu-24.04-arm
40+
steps:
41+
- name: Prepare name for digest up/download
42+
run: |
43+
platform=${{ matrix.platform }}
44+
echo "PLATFORM_PAIR=${platform//\/,-}" >> $GITHUB_ENV
45+
46+
- &checkout-repo
47+
name: Checkout Repo
48+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 #v6.0.1
49+
50+
- &docker-meta
51+
name: Docker meta
52+
id: meta
53+
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 #v5.10.0
54+
with:
55+
github-token: ${{ secrets.GITHUB_TOKEN }}
56+
images: |
57+
${{ env.DOCKER_REGISTRY_IMAGE }}
58+
${{ env.GITHUB_REGISTRY_IMAGE }}
59+
flavor: |
60+
latest=${{ startsWith(github.ref, 'refs/tags/') }}
61+
tags: |
62+
type=schedule,pattern=nightly
63+
type=raw,value=nightly,enable=${{ github.event_name == 'push' }}
64+
type=ref,event=tag
65+
66+
- &login-dockerhub
67+
name: Login to Docker Hub
68+
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef #v3.6.0
69+
with:
70+
registry: docker.io
71+
username: ${{ secrets.DOCKERHUB_USER }}
72+
password: ${{ secrets.DOCKERHUB_PASS }}
73+
74+
- &login-ghcr
75+
name: Login to GitHub Container Registry
76+
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef #v3.6.0
77+
with:
78+
registry: ghcr.io
79+
username: ${{ github.repository_owner }}
80+
password: ${{ secrets.GITHUB_TOKEN }}
81+
82+
- name: Set up QEMU
83+
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 #v3.7.0
84+
with:
85+
platforms: ${{ matrix.platform }}
86+
87+
- &setup-buildx
88+
name: Set up Docker Buildx
89+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 #v3.11.1
90+
91+
- name: Build and push by digest
92+
id: build
93+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 #v6.18.0
94+
with:
95+
context: ftl-build
96+
platforms: ${{ matrix.platform }}
97+
target: build
98+
labels: ${{ steps.meta.outputs.labels }}
99+
outputs: |
100+
type=image,name=${{ env.DOCKER_REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
101+
102+
- name: Export digests
103+
run: |
104+
mkdir -p /tmp/digests/
105+
digest="${{ steps.build.outputs.digest }}"
106+
touch "/tmp/digests/${digest#sha256:}"
107+
108+
- name: Upload digest
109+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f #v6.0.0
110+
with:
111+
name: digests-${{ env.PLATFORM_PAIR }}
112+
path: /tmp/digests/*
113+
if-no-files-found: error
114+
retention-days: 1
115+
116+
# Merge all the digests into a single file
117+
# If we would push immediately above, the individual runners would overwrite each other's images
118+
# https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners
119+
merge-and-deploy:
120+
runs-on: ubuntu-latest
121+
needs:
122+
- build
123+
steps:
124+
- *checkout-repo
125+
126+
- name: Download digests
127+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 #v7.0.0
128+
with:
129+
path: /tmp/digests
130+
pattern: digests-*
131+
merge-multiple: true
132+
133+
- *setup-buildx
134+
- *docker-meta
135+
- *login-dockerhub
136+
- *login-ghcr
137+
138+
- name: Create manifest list and push (DockerHub and GitHub Container Registry)
139+
working-directory: /tmp/digests
140+
run: |
141+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
142+
$(printf '${{ env.DOCKER_REGISTRY_IMAGE }}@sha256:%s ' *)
143+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
144+
$(printf '${{ env.GITHUB_REGISTRY_IMAGE }}@sha256:%s ' *)
145+
146+
- name: Inspect images
147+
shell: bash
148+
run: |
149+
docker buildx imagetools inspect ${{ env.DOCKER_REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
150+
docker buildx imagetools inspect ${{ env.GITHUB_REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: ftl-build test
2+
3+
on:
4+
pull_request:
5+
6+
permissions:
7+
contents: read
8+
9+
env:
10+
DOCKER_REGISTRY_IMAGE: ${{ secrets.DOCKERHUB_NAMESPACE }}/ftl-build
11+
GITHUB_REGISTRY_IMAGE: ghcr.io/${{ github.repository_owner }}/ftl-build
12+
13+
jobs:
14+
build-and-test:
15+
runs-on: ${{ matrix.runner }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
include:
20+
- platform: linux/amd64
21+
runner: ubuntu-24.04
22+
- platform: linux/386
23+
runner: ubuntu-24.04
24+
- platform: linux/arm/v6
25+
runner: ubuntu-24.04-arm
26+
- platform: linux/arm/v7
27+
runner: ubuntu-24.04-arm
28+
- platform: linux/arm64/v8
29+
runner: ubuntu-24.04-arm
30+
- platform: linux/riscv64
31+
runner: ubuntu-24.04-arm
32+
steps:
33+
- name: Checkout Repo
34+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 #v6.0.1
35+
36+
- name: Set up QEMU
37+
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 #v3.7.0
38+
with:
39+
platforms: ${{ matrix.platform }}
40+
41+
- name: Set up Docker Buildx
42+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 #v3.11.1
43+
44+
- name: Build container and test-compile FTL
45+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 #v6.18.0
46+
with:
47+
context: ftl-build
48+
platforms: ${{ matrix.platform }}
49+
push: false
50+
target: test

0 commit comments

Comments
 (0)