Skip to content

Commit 9df1be1

Browse files
dereknolagountharmmoll
committed
Use go cross compile for all build stages
Signed-off-by: Derek Nola <derek.nola@suse.com> Co-Authored-By: Bruno Verachten <116569+gounthar@users.noreply.github.com> Co-Authored-By: Michael Moll <mmoll@mmoll.at>
1 parent 73a600f commit 9df1be1

3 files changed

Lines changed: 39 additions & 305 deletions

File tree

.github/workflows/pr.yaml

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5,89 +5,22 @@ on:
55
paths-ignore:
66
- "**.md"
77

8-
env:
9-
GHCR_REPO: ghcr.io/${{ github.repository_owner }}/klipper-helm
8+
permissions:
9+
contents: read
1010

1111
jobs:
1212
build:
1313
runs-on: ubuntu-latest
1414

15-
permissions:
16-
contents: read
17-
18-
steps:
19-
- name: Set DOCKERHUB_REPO
20-
run: |
21-
if [ "${{ github.repository_owner }}" == "k3s-io" ]; then
22-
echo "DOCKERHUB_REPO=rancher/klipper-helm" >> $GITHUB_ENV
23-
else
24-
echo "DOCKERHUB_REPO=${{ secrets.DOCKER_USERNAME }}/klipper-helm" >> $GITHUB_ENV
25-
fi
26-
27-
- name: Docker source meta
28-
id: meta
29-
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6
30-
with:
31-
images: |
32-
${{ env.DOCKERHUB_REPO }}
33-
${{ env.GHCR_REPO }}
34-
35-
- name: Set up QEMU
36-
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4
37-
38-
- name: Set up Docker Buildx
39-
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
40-
41-
- name: Build Image
42-
id: build
43-
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7
44-
with:
45-
platforms: linux/amd64
46-
outputs: type=image,"name=${{ env.DOCKERHUB_REPO }},${{ env.GHCR_REPO }}",push-by-digest=true,name-canonical=true,push=false
47-
48-
build-arm:
49-
runs-on: ubuntu-22.04-arm
50-
strategy:
51-
fail-fast: false
52-
matrix:
53-
platform:
54-
- arm64
55-
- arm/v7
56-
57-
permissions:
58-
contents: read
59-
6015
steps:
61-
- name: Replace / with -
62-
run: |
63-
platform=${{ matrix.platform }}
64-
echo "ARCH=${platform//\//-}" >> $GITHUB_ENV
65-
66-
- name: Set DOCKERHUB_REPO
67-
run: |
68-
if [ "${{ github.repository_owner }}" == "k3s-io" ]; then
69-
echo "DOCKERHUB_REPO=rancher/klipper-helm" >> $GITHUB_ENV
70-
else
71-
echo "DOCKERHUB_REPO=${{ secrets.DOCKER_USERNAME }}/klipper-helm" >> $GITHUB_ENV
72-
fi
73-
74-
- name: Docker source meta
75-
id: meta
76-
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6
77-
with:
78-
images: |
79-
${{ env.DOCKERHUB_REPO }}
80-
${{ env.GHCR_REPO }}
81-
8216
- name: Set up QEMU
8317
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4
8418

8519
- name: Set up Docker Buildx
8620
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
8721

8822
- name: Build Image
89-
id: build
9023
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7
9124
with:
92-
platforms: linux/${{ matrix.platform }}
93-
outputs: type=image,"name=${{ env.DOCKERHUB_REPO }},${{ env.GHCR_REPO }}",push-by-digest=true,name-canonical=true,push=false
25+
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/riscv64
26+
push: false

.github/workflows/release.yml

Lines changed: 10 additions & 215 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ env:
99
GHCR_REPO: ghcr.io/${{ github.repository_owner }}/klipper-helm
1010

1111
jobs:
12-
build:
12+
build-and-push:
1313
runs-on: ubuntu-latest
1414

1515
permissions:
@@ -22,7 +22,7 @@ jobs:
2222
steps:
2323
- name: Set DOCKERHUB_REPO
2424
run: |
25-
if [ "${{ github.repository_owner }}" == "k3s-io" ]; then
25+
if [ "${{ github.repository_owner }}" = "k3s-io" ]; then
2626
echo "DOCKERHUB_REPO=rancher/klipper-helm" >> $GITHUB_ENV
2727
else
2828
echo "DOCKERHUB_REPO=${{ secrets.DOCKER_USERNAME }}/klipper-helm" >> $GITHUB_ENV
@@ -36,125 +36,21 @@ jobs:
3636
${{ env.DOCKERHUB_REPO }}
3737
${{ env.GHCR_REPO }}
3838
39-
- name: "Read Vault secrets"
39+
- name: Read Vault secrets
4040
if: github.repository_owner == 'k3s-io'
4141
uses: rancher-eio/read-vault-secrets@0da85151ad1f19ed7986c41587e45aac1ace74b6 # v3
4242
with:
4343
secrets: |
4444
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ;
4545
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_TOKEN ;
46-
47-
- name: Login to DockerHub with Rancher Secrets
48-
if: github.repository_owner == 'k3s-io'
49-
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
50-
with:
51-
username: ${{ env.DOCKER_USERNAME }}
52-
password: ${{ env.DOCKER_TOKEN }}
53-
54-
# For forks, setup DockerHub login with GHA secrets
55-
- name: Login to DockerHub with GHA Secrets
56-
if: github.repository_owner != 'k3s-io'
57-
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
58-
with:
59-
username: ${{ secrets.DOCKER_USERNAME }}
60-
password: ${{ secrets.DOCKER_TOKEN }}
61-
62-
- name: Login to GitHub Container Registry
63-
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
64-
with:
65-
registry: ghcr.io
66-
username: ${{ github.repository_owner }}
67-
password: ${{ secrets.GITHUB_TOKEN }}
68-
69-
- name: Set up QEMU
70-
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4
7146
72-
- name: Set up Docker Buildx
73-
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
74-
75-
- name: Build and push by digest
76-
id: build
77-
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7
78-
with:
79-
platforms: linux/amd64
80-
outputs: type=image,"name=${{ env.DOCKERHUB_REPO }},${{ env.GHCR_REPO }}",push-by-digest=true,name-canonical=true,push=true
81-
82-
- name: Attest
83-
uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # v4
84-
id: attest
85-
with:
86-
subject-name: ${{ env.GHCR_REPO }}
87-
subject-digest: ${{ steps.build.outputs.digest }}
88-
push-to-registry: true
89-
90-
- name: Export digest
91-
run: |
92-
mkdir -p ${{ runner.temp }}/digests
93-
digest="${{ steps.build.outputs.digest }}"
94-
touch "${{ runner.temp }}/digests/${digest#sha256:}"
95-
96-
- name: Upload digest
97-
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
98-
with:
99-
name: digests-amd64
100-
path: ${{ runner.temp }}/digests/*
101-
if-no-files-found: error
102-
retention-days: 1
103-
104-
build-arm:
105-
runs-on: ubuntu-22.04-arm
106-
strategy:
107-
fail-fast: false
108-
matrix:
109-
platform:
110-
- arm64
111-
- arm/v7
112-
113-
permissions:
114-
contents: read
115-
packages: write
116-
id-token: write # needed for the Vault authentication
117-
attestations: write
118-
artifact-metadata: write
119-
120-
steps:
121-
- name: Replace / with -
122-
run: |
123-
platform=${{ matrix.platform }}
124-
echo "ARCH=${platform//\//-}" >> $GITHUB_ENV
125-
126-
- name: Set DOCKERHUB_REPO
127-
run: |
128-
if [ "${{ github.repository_owner }}" == "k3s-io" ]; then
129-
echo "DOCKERHUB_REPO=rancher/klipper-helm" >> $GITHUB_ENV
130-
else
131-
echo "DOCKERHUB_REPO=${{ secrets.DOCKER_USERNAME }}/klipper-helm" >> $GITHUB_ENV
132-
fi
133-
134-
- name: Docker source meta
135-
id: meta
136-
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6
137-
with:
138-
images: |
139-
${{ env.DOCKERHUB_REPO }}
140-
${{ env.GHCR_REPO }}
141-
142-
- name: "Read Vault secrets"
143-
if: github.repository_owner == 'k3s-io'
144-
uses: rancher-eio/read-vault-secrets@0da85151ad1f19ed7986c41587e45aac1ace74b6 # v3
145-
with:
146-
secrets: |
147-
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ;
148-
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_TOKEN ;
149-
15047
- name: Login to DockerHub with Rancher Secrets
15148
if: github.repository_owner == 'k3s-io'
15249
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
15350
with:
15451
username: ${{ env.DOCKER_USERNAME }}
15552
password: ${{ env.DOCKER_TOKEN }}
156-
157-
# For forks, setup DockerHub login with GHA secrets
53+
15854
- name: Login to DockerHub with GHA Secrets
15955
if: github.repository_owner != 'k3s-io'
16056
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
@@ -175,121 +71,20 @@ jobs:
17571
- name: Set up Docker Buildx
17672
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
17773

178-
- name: Build and push by digest
74+
- name: Build and push image
17975
id: build
18076
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7
18177
with:
182-
platforms: linux/${{ matrix.platform }}
183-
outputs: type=image,"name=${{ env.DOCKERHUB_REPO }},${{ env.GHCR_REPO }}",push-by-digest=true,name-canonical=true,push=true
184-
185-
- name: Attest
186-
uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # v4
187-
id: attest
188-
with:
189-
subject-name: ${{ env.GHCR_REPO }}
190-
subject-digest: ${{ steps.build.outputs.digest }}
191-
push-to-registry: true
192-
193-
- name: Export digest
194-
run: |
195-
mkdir -p ${{ runner.temp }}/digests
196-
digest="${{ steps.build.outputs.digest }}"
197-
touch "${{ runner.temp }}/digests/${digest#sha256:}"
198-
199-
- name: Upload digest
200-
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
201-
with:
202-
name: digests-${{ env.ARCH }}
203-
path: ${{ runner.temp }}/digests/*
204-
if-no-files-found: error
205-
retention-days: 1
206-
207-
merge-manifests:
208-
runs-on: ubuntu-latest
209-
needs:
210-
- build
211-
- build-arm
212-
213-
permissions:
214-
contents: read
215-
packages: write
216-
id-token: write # needed for the Vault authentication
217-
attestations: write # needed for actions/attest
218-
artifact-metadata: write # needed to upload the attestations
219-
220-
steps:
221-
- name: Download digests
222-
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
223-
with:
224-
path: ${{ runner.temp }}/digests
225-
pattern: digests-*
226-
merge-multiple: true
227-
228-
- name: Set DOCKERHUB_REPO
229-
run: |
230-
if [ "${{ github.repository_owner }}" == "k3s-io" ]; then
231-
echo "DOCKERHUB_REPO=rancher/klipper-helm" >> $GITHUB_ENV
232-
else
233-
echo "DOCKERHUB_REPO=${{ secrets.DOCKER_USERNAME }}/klipper-helm" >> $GITHUB_ENV
234-
fi
235-
236-
- name: "Read Vault secrets"
237-
if: github.repository_owner == 'k3s-io'
238-
uses: rancher-eio/read-vault-secrets@0da85151ad1f19ed7986c41587e45aac1ace74b6 # v3
239-
with:
240-
secrets: |
241-
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ;
242-
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_TOKEN ;
243-
244-
- name: Login to DockerHub with Rancher Secrets
245-
if: github.repository_owner == 'k3s-io'
246-
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
247-
with:
248-
username: ${{ env.DOCKER_USERNAME }}
249-
password: ${{ env.DOCKER_TOKEN }}
250-
251-
# For forks, setup DockerHub login with GHA secrets
252-
- name: Login to DockerHub with GHA Secrets
253-
if: github.repository_owner != 'k3s-io'
254-
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
255-
with:
256-
username: ${{ secrets.DOCKER_USERNAME }}
257-
password: ${{ secrets.DOCKER_TOKEN }}
258-
259-
- name: Login to GitHub Container Registry
260-
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
261-
with:
262-
registry: ghcr.io
263-
username: ${{ github.repository_owner }}
264-
password: ${{ secrets.GITHUB_TOKEN }}
265-
266-
- name: Set up Docker Buildx
267-
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
268-
269-
- name: Docker meta
270-
id: meta
271-
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6
272-
with:
273-
images: |
274-
${{ env.DOCKERHUB_REPO }}
275-
${{ env.GHCR_REPO }}
276-
277-
- name: Create manifest list and push
278-
id: get-digest
279-
working-directory: ${{ runner.temp }}/digests
280-
run: |
281-
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
282-
$(printf '${{ env.DOCKERHUB_REPO }}@sha256:%s ' *)
283-
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
284-
$(printf '${{ env.GHCR_REPO }}@sha256:%s ' *)
285-
GHCR_DIGEST=$(docker buildx imagetools inspect ${{ env.GHCR_REPO }}:${{ steps.meta.outputs.version }} --raw | sha256sum | awk '{print "sha256:"$1}')
286-
echo "ghcr_digest=$GHCR_DIGEST" >> $GITHUB_OUTPUT
78+
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/riscv64
79+
tags: ${{ steps.meta.outputs.tags }}
80+
labels: ${{ steps.meta.outputs.labels }}
81+
push: true
28782

28883
- name: Attest multi-arch image (GHCR)
28984
uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # v4
29085
with:
29186
subject-name: ${{ env.GHCR_REPO }}
292-
subject-digest: ${{ steps.get-digest.outputs.ghcr_digest }}
87+
subject-digest: ${{ steps.build.outputs.digest }}
29388
push-to-registry: true
29489

29590
- name: Inspect image

0 commit comments

Comments
 (0)