Skip to content

Commit b61878d

Browse files
committed
refactor: refactor docker build
1 parent cc346d6 commit b61878d

3 files changed

Lines changed: 69 additions & 33 deletions

File tree

.github/workflows/build-test-docker.yml

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@ on:
66
image-tag:
77
type: string
88
required: true
9+
platform:
10+
type: string
11+
required: false
12+
default: "linux/amd64"
13+
image-name:
14+
type: string
15+
required: true
16+
cache-from:
17+
type: string
18+
required: false
19+
default: ""
20+
cache-to:
21+
type: string
22+
required: false
23+
default: ""
24+
setup-qemu:
25+
type: string
26+
required: false
27+
default: "false"
928

1029
jobs:
1130
test-docker-build:
@@ -14,17 +33,7 @@ jobs:
1433
permissions:
1534
contents: read
1635
packages: read
17-
strategy:
18-
matrix:
19-
include:
20-
- arch: amd64
21-
platform: linux/amd64
22-
image-name: build-amd64
23-
needs-qemu: false
24-
- arch: arm64
25-
platform: linux/arm64
26-
image-name: build-arm64
27-
needs-qemu: true
36+
2837
steps:
2938
- name: Check out the repo
3039
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -43,11 +52,12 @@ jobs:
4352
file: ./Dockerfile
4453
push: false
4554
load: true
46-
platforms: ${{ matrix.platform }}
47-
cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-${{ matrix.arch }}
48-
image-name: ${{ matrix.image-name }}
49-
setup-qemu: ${{ matrix.needs-qemu }}
55+
platforms: ${{ inputs.platform }}
56+
cache-from: ${{ inputs.cache-from }}
57+
cache-to: ${{ inputs.cache-to }}
58+
image-name: ${{ inputs.image-name }}
59+
setup-qemu: ${{ inputs.setup-qemu }}
5060

5161
- name: Test
5262
run: |
53-
docker run --platform ${{ matrix.platform }} --rm ${{ matrix.image-name }}:${{ inputs.image-tag }} --version
63+
docker run --platform ${{ inputs.platform }} --rm ${{ inputs.image-name }}:${{ inputs.image-tag }} --version

.github/workflows/publish.yml

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,29 @@ jobs:
1414

1515
build_and_test_docker:
1616
uses: ./.github/workflows/build-test-docker.yml
17+
strategy:
18+
matrix:
19+
include:
20+
- platform: linux/amd64
21+
cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-amd64
22+
cache-to: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-amd64
23+
image-name: build-amd64
24+
setup-qemu: false
25+
- platform: linux/arm64
26+
cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-arm64
27+
cache-to: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-arm64
28+
image-name: build-arm64
29+
setup-qemu: true
30+
1731
with:
18-
image-tag: latest
32+
image-tag: "pr-${{ github.event.pull_request.number }}"
33+
platform: ${{ matrix.platform }}
34+
cache-from: ${{ matrix.cache-from }}
35+
cache-to: ${{ matrix.cache-to }}
36+
image-name: ${{ matrix.image-name }}
37+
setup-qemu: ${{ matrix.setup-qemu }}
38+
39+
secrets: inherit
1940

2041
publish_to_pypi:
2142
name: Publish to PyPI
@@ -77,22 +98,6 @@ jobs:
7798
type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-amd64
7899
type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-arm64
79100
80-
- name: Delete old cache entries
81-
env:
82-
GH_TOKEN: ${{ github.token }}
83-
run: |
84-
# Get all versions of the container package
85-
versions=$(gh api "orgs/elementsinteractive/packages/container/twyn/versions" --paginate)
86-
87-
# Extract version IDs that do NOT have any buildcache-* tags (buildcache-amd64, buildcache-arm64, etc.)
88-
ids_to_delete=$(echo "$versions" | jq -r '.[] | select(.metadata.container.tags | map(test("^buildcache-")) | any | not) | .id')
89-
90-
# Delete them
91-
for id in $ids_to_delete; do
92-
echo "Deleting old cache version ID: $id"
93-
gh api -X DELETE "orgs/elementsinteractive/packages/container/twyn/versions/$id"
94-
done
95-
96101
release_notes:
97102
runs-on: ubuntu-latest
98103
needs: [publish_to_pypi, publish_to_dockerhub]

.github/workflows/trigger-test-docker-build.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,26 @@ jobs:
3737
name: Trigger test Docker build
3838
if: (needs.should-test-docker-build.outputs.workflow == 'true' || needs.should-test-docker-build.outputs.docker == 'true')
3939
uses: ./.github/workflows/build-test-docker.yml
40+
strategy:
41+
matrix:
42+
include:
43+
- platform: linux/amd64
44+
cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-amd64
45+
cache-to: ""
46+
image-name: build-amd64
47+
setup-qemu: false
48+
- platform: linux/arm64
49+
cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-arm64
50+
cache-to: ""
51+
image-name: build-arm64
52+
setup-qemu: false
53+
4054
with:
4155
image-tag: "pr-${{ github.event.pull_request.number }}"
56+
platform: ${{ matrix.platform }}
57+
cache-from: ${{ matrix.cache-from }}
58+
cache-to: ${{ matrix.cache-to }}
59+
image-name: ${{ matrix.image-name }}
60+
setup-qemu: ${{ matrix.setup-qemu }}
61+
62+
secrets: inherit

0 commit comments

Comments
 (0)