Skip to content

Commit 1bce101

Browse files
Refactor the image building in CI to separate based on if we're making a release
Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
1 parent b1f1d80 commit 1bce101

3 files changed

Lines changed: 48 additions & 51 deletions

File tree

.github/workflows/build.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,29 @@ jobs:
1515
build:
1616
name: Invoke build
1717
uses: ./.github/workflows/common.yml
18+
image:
19+
runs-on: ubuntu-latest
20+
needs: [build]
21+
steps:
22+
- name: Login to GitHub container registry
23+
uses: docker/login-action@v3
24+
with:
25+
registry: ghcr.io
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
- name: Set up QEMU
29+
uses: docker/setup-qemu-action@v3
30+
- name: Set up docker-buildx
31+
uses: docker/setup-buildx-action@v3
32+
- name: Build image to tar
33+
uses: docker/build-push-action@v6
34+
with:
35+
platforms: linux/arm64
36+
push: false
37+
tags: ghcr.io/apple/container-builder-shim/builder:test
38+
outputs: type=oci,dest=container-builder-shim.tar
39+
- name: Save artifacts
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: container-builder-shim
43+
path: container-builder-shim.tar

.github/workflows/common.yml

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@ permissions:
55

66
on:
77
workflow_call:
8-
inputs:
9-
publish:
10-
type: boolean
11-
description: "Publish the built image"
12-
default: false
13-
version:
14-
type: string
15-
description: "Version of the builder image to create"
16-
default: "test"
178

189
jobs:
1910
build:
@@ -43,41 +34,3 @@ jobs:
4334
- name: Test
4435
run: |
4536
make test
46-
47-
image:
48-
# Nested jobs inherit permissions from parent job, so if we need to publish an image,
49-
# the caller must set permissions that include packages: write.
50-
runs-on: ubuntu-latest
51-
needs: [build] # don't build the image if the repo doesn't build
52-
steps:
53-
- name: Login to GitHub container registry
54-
uses: docker/login-action@v3
55-
with:
56-
registry: ghcr.io
57-
username: ${{ github.actor }}
58-
password: ${{ secrets.GITHUB_TOKEN }}
59-
- name: Set up QEMU
60-
uses: docker/setup-qemu-action@v3
61-
- name: Set up docker-buildx
62-
uses: docker/setup-buildx-action@v3
63-
- name: Build Dockerfile and push image
64-
if: ${{ inputs.publish }}
65-
uses: docker/build-push-action@v6
66-
with:
67-
platforms: linux/arm64
68-
push: true
69-
tags: ghcr.io/apple/container-builder-shim/builder:${{ inputs.version }}
70-
- name: Build image to tar
71-
if: ${{ !inputs.publish }}
72-
uses: docker/build-push-action@v6
73-
with:
74-
platforms: linux/arm64
75-
push: false
76-
tags: ghcr.io/apple/container-builder-shim/builder:${{ inputs.version }}
77-
outputs: type=oci,dest=container-builder-shim.tar
78-
- name: Save artifacts
79-
if: ${{ !inputs.publish }}
80-
uses: actions/upload-artifact@v4
81-
with:
82-
name: container-builder-shim
83-
path: container-builder-shim.tar

.github/workflows/release.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,27 @@ jobs:
1313
if: startsWith(github.ref, 'refs/tags/')
1414
name: Invoke build and release
1515
uses: ./.github/workflows/common.yml
16-
with:
17-
publish: true
18-
version: ${{ github.ref_name }}
1916
permissions:
2017
contents: read
21-
packages: write
18+
image:
19+
runs-on: ubuntu-latest
20+
needs: [build]
21+
permissions:
22+
packages: write
23+
steps:
24+
- name: Login to GitHub container registry
25+
uses: docker/login-action@v3
26+
with:
27+
registry: ghcr.io
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
- name: Set up QEMU
31+
uses: docker/setup-qemu-action@v3
32+
- name: Set up docker-buildx
33+
uses: docker/setup-buildx-action@v3
34+
- name: Build Dockerfile and push image
35+
uses: docker/build-push-action@v6
36+
with:
37+
platforms: linux/arm64
38+
push: true
39+
tags: ghcr.io/apple/container-builder-shim/builder:${{ github.ref_name }}

0 commit comments

Comments
 (0)