Skip to content

Commit e5c5700

Browse files
committed
Use native arm runner to build arm64 images
1 parent e3ecd76 commit e5c5700

9 files changed

+739
-105
lines changed

.github/workflows/docker-build-simple.libsonnet

Lines changed: 82 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,27 @@
33
// Docker manifest #{name}/Dockerfile
44
// ECR repository: #{name}
55

6+
local runnersMap = {
7+
'linux/amd64': 'ubuntu-24.04',
8+
'linux/arm64': 'ubuntu-24.04-arm',
9+
};
10+
11+
local setupSteps = function(region) [
12+
{ uses: 'docker/setup-buildx-action@v3' },
13+
{
14+
uses: 'aws-actions/configure-aws-credentials@v4',
15+
with: {
16+
'aws-region': region,
17+
'role-to-assume': 'arn:aws:iam::005216166247:role/GhaDockerPush',
18+
'role-skip-session-tagging': true,
19+
},
20+
},
21+
{
22+
uses: 'aws-actions/amazon-ecr-login@v2',
23+
id: 'login-ecr',
24+
},
25+
];
26+
627
function(name, region='ap-northeast-1', platforms=['linux/arm64']) {
728
name: std.format('docker-%s', name),
829
on: {
@@ -16,34 +37,76 @@ function(name, region='ap-northeast-1', platforms=['linux/arm64']) {
1637
},
1738
jobs: {
1839
build: {
19-
name: 'build',
20-
'runs-on': 'ubuntu-latest',
40+
strategy: {
41+
matrix: {
42+
include: std.map(function(platform) {
43+
key: std.strReplace(platform, '/', '-'), // for artifact name
44+
platform: platform,
45+
runner: runnersMap[platform],
46+
}, platforms),
47+
},
48+
},
49+
name: 'build (${{ matrix.platform }})',
50+
'runs-on': '${{ matrix.runner }}',
2151
permissions: { 'id-token': 'write', contents: 'read' },
22-
steps: [] +
23-
(if std.member(platforms, 'linux/arm64') then [{ uses: 'docker/setup-qemu-action@v2' }] else []) + [
24-
{ uses: 'docker/setup-buildx-action@v2' },
52+
steps: setupSteps(region) + [
2553
{
26-
uses: 'aws-actions/configure-aws-credentials@v1',
54+
uses: 'docker/build-push-action@v6',
55+
id: 'build-push',
2756
with: {
28-
'aws-region': region,
29-
'role-to-assume': 'arn:aws:iam::005216166247:role/GhaDockerPush',
30-
'role-skip-session-tagging': true,
57+
context: std.format('{{defaultContext}}:%s', name),
58+
platforms: '${{ matrix.platform }}',
59+
outputs: std.format('type=image,"name=${{ steps.login-ecr.outputs.registry }}/%s",push-by-digest=true,name-canonical=true,push=true', name),
3160
},
3261
},
3362
{
34-
uses: 'aws-actions/amazon-ecr-login@v1',
35-
id: 'login-ecr',
63+
name: 'Export digests',
64+
run: |||
65+
mkdir -p "${RUNNER_TEMP}/digests"
66+
printenv DIGEST > "${RUNNER_TEMP}/digests/${PLATFORM}"
67+
|||,
68+
env: {
69+
RUNNER_TEMP: '${{ runner.temp }}',
70+
DIGEST: '${{ steps.build-push.outputs.digest }}',
71+
PLATFORM: '${{ matrix.key }}',
72+
},
3673
},
3774
{
38-
uses: 'docker/build-push-action@v3',
75+
name: 'Upload digests',
76+
uses: 'actions/upload-artifact@v4',
3977
with: {
40-
context: std.format('{{defaultContext}}:%s', name),
41-
platforms: std.join(',', platforms),
42-
tags: std.join(',', [
43-
std.format('${{ steps.login-ecr.outputs.registry }}/%s:${{ github.sha }}', name),
44-
std.format('${{ steps.login-ecr.outputs.registry }}/%s:latest', name),
45-
]),
46-
push: true,
78+
name: 'digests-${{ matrix.key }}',
79+
path: '${{ runner.temp }}/digests/*',
80+
'if-no-files-found': 'error',
81+
'retention-days': 1,
82+
},
83+
},
84+
],
85+
},
86+
merge: {
87+
'runs-on': 'ubuntu-latest',
88+
needs: ['build'],
89+
permissions: { 'id-token': 'write' },
90+
steps: setupSteps(region) + [
91+
{
92+
name: 'Download digests',
93+
uses: 'actions/download-artifact@v4',
94+
with: {
95+
path: '${{ runner.temp }}/digests',
96+
pattern: 'digests-*',
97+
'merge-multiple': true,
98+
},
99+
},
100+
{
101+
name: 'Push manifest',
102+
run: |||
103+
cat "${RUNNER_TEMP}"/digests/* | xargs -I{} printf "%s@%s" "${REPO}" {} | docker buildx imagetools create -f /dev/stdin -t "${REPO}:latest" -t "${REPO}:${SHA}"
104+
docker buildx imagetools inspect "${REPO}:${SHA}"
105+
|||,
106+
env: {
107+
RUNNER_TEMP: '${{ runner.temp }}',
108+
REPO: std.format('${{ steps.login-ecr.outputs.registry }}/%s', name),
109+
SHA: '${{ github.sha }}',
47110
},
48111
},
49112
],

.github/workflows/docker-dnscollector.yml

Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,83 @@
11
{
22
"jobs": {
33
"build": {
4-
"name": "build",
4+
"name": "build (${{ matrix.platform }})",
55
"permissions": {
66
"contents": "read",
77
"id-token": "write"
88
},
9-
"runs-on": "ubuntu-latest",
9+
"runs-on": "${{ matrix.runner }}",
1010
"steps": [
1111
{
12-
"uses": "docker/setup-qemu-action@v2"
12+
"uses": "docker/setup-buildx-action@v3"
1313
},
1414
{
15-
"uses": "docker/setup-buildx-action@v2"
15+
"uses": "aws-actions/configure-aws-credentials@v4",
16+
"with": {
17+
"aws-region": "ap-northeast-1",
18+
"role-skip-session-tagging": true,
19+
"role-to-assume": "arn:aws:iam::005216166247:role/GhaDockerPush"
20+
}
21+
},
22+
{
23+
"id": "login-ecr",
24+
"uses": "aws-actions/amazon-ecr-login@v2"
1625
},
1726
{
18-
"uses": "aws-actions/configure-aws-credentials@v1",
27+
"id": "build-push",
28+
"uses": "docker/build-push-action@v6",
29+
"with": {
30+
"context": "{{defaultContext}}:dnscollector",
31+
"outputs": "type=image,\"name=${{ steps.login-ecr.outputs.registry }}/dnscollector\",push-by-digest=true,name-canonical=true,push=true",
32+
"platforms": "${{ matrix.platform }}"
33+
}
34+
},
35+
{
36+
"env": {
37+
"DIGEST": "${{ steps.build-push.outputs.digest }}",
38+
"PLATFORM": "${{ matrix.key }}",
39+
"RUNNER_TEMP": "${{ runner.temp }}"
40+
},
41+
"name": "Export digests",
42+
"run": "mkdir -p \"${RUNNER_TEMP}/digests\"\nprintenv DIGEST > \"${RUNNER_TEMP}/digests/${PLATFORM}\"\n"
43+
},
44+
{
45+
"name": "Upload digests",
46+
"uses": "actions/upload-artifact@v4",
47+
"with": {
48+
"if-no-files-found": "error",
49+
"name": "digests-${{ matrix.key }}",
50+
"path": "${{ runner.temp }}/digests/*",
51+
"retention-days": 1
52+
}
53+
}
54+
],
55+
"strategy": {
56+
"matrix": {
57+
"include": [
58+
{
59+
"key": "linux-arm64",
60+
"platform": "linux/arm64",
61+
"runner": "ubuntu-24.04-arm"
62+
}
63+
]
64+
}
65+
}
66+
},
67+
"merge": {
68+
"needs": [
69+
"build"
70+
],
71+
"permissions": {
72+
"id-token": "write"
73+
},
74+
"runs-on": "ubuntu-latest",
75+
"steps": [
76+
{
77+
"uses": "docker/setup-buildx-action@v3"
78+
},
79+
{
80+
"uses": "aws-actions/configure-aws-credentials@v4",
1981
"with": {
2082
"aws-region": "ap-northeast-1",
2183
"role-skip-session-tagging": true,
@@ -24,16 +86,25 @@
2486
},
2587
{
2688
"id": "login-ecr",
27-
"uses": "aws-actions/amazon-ecr-login@v1"
89+
"uses": "aws-actions/amazon-ecr-login@v2"
2890
},
2991
{
30-
"uses": "docker/build-push-action@v3",
92+
"name": "Download digests",
93+
"uses": "actions/download-artifact@v4",
3194
"with": {
32-
"context": "{{defaultContext}}:dnscollector",
33-
"platforms": "linux/arm64",
34-
"push": true,
35-
"tags": "${{ steps.login-ecr.outputs.registry }}/dnscollector:${{ github.sha }},${{ steps.login-ecr.outputs.registry }}/dnscollector:latest"
95+
"merge-multiple": true,
96+
"path": "${{ runner.temp }}/digests",
97+
"pattern": "digests-*"
3698
}
99+
},
100+
{
101+
"env": {
102+
"REPO": "${{ steps.login-ecr.outputs.registry }}/dnscollector",
103+
"RUNNER_TEMP": "${{ runner.temp }}",
104+
"SHA": "${{ github.sha }}"
105+
},
106+
"name": "Push manifest",
107+
"run": "cat \"${RUNNER_TEMP}\"/digests/* | xargs -I{} printf \"%s@%s\" \"${REPO}\" {} | docker buildx imagetools create -f /dev/stdin -t \"${REPO}:latest\" -t \"${REPO}:${SHA}\"\ndocker buildx imagetools inspect \"${REPO}:${SHA}\"\n"
37108
}
38109
]
39110
}

.github/workflows/docker-fluentd.yml

Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,83 @@
11
{
22
"jobs": {
33
"build": {
4-
"name": "build",
4+
"name": "build (${{ matrix.platform }})",
55
"permissions": {
66
"contents": "read",
77
"id-token": "write"
88
},
9-
"runs-on": "ubuntu-latest",
9+
"runs-on": "${{ matrix.runner }}",
1010
"steps": [
1111
{
12-
"uses": "docker/setup-qemu-action@v2"
12+
"uses": "docker/setup-buildx-action@v3"
1313
},
1414
{
15-
"uses": "docker/setup-buildx-action@v2"
15+
"uses": "aws-actions/configure-aws-credentials@v4",
16+
"with": {
17+
"aws-region": "ap-northeast-1",
18+
"role-skip-session-tagging": true,
19+
"role-to-assume": "arn:aws:iam::005216166247:role/GhaDockerPush"
20+
}
21+
},
22+
{
23+
"id": "login-ecr",
24+
"uses": "aws-actions/amazon-ecr-login@v2"
1625
},
1726
{
18-
"uses": "aws-actions/configure-aws-credentials@v1",
27+
"id": "build-push",
28+
"uses": "docker/build-push-action@v6",
29+
"with": {
30+
"context": "{{defaultContext}}:fluentd",
31+
"outputs": "type=image,\"name=${{ steps.login-ecr.outputs.registry }}/fluentd\",push-by-digest=true,name-canonical=true,push=true",
32+
"platforms": "${{ matrix.platform }}"
33+
}
34+
},
35+
{
36+
"env": {
37+
"DIGEST": "${{ steps.build-push.outputs.digest }}",
38+
"PLATFORM": "${{ matrix.key }}",
39+
"RUNNER_TEMP": "${{ runner.temp }}"
40+
},
41+
"name": "Export digests",
42+
"run": "mkdir -p \"${RUNNER_TEMP}/digests\"\nprintenv DIGEST > \"${RUNNER_TEMP}/digests/${PLATFORM}\"\n"
43+
},
44+
{
45+
"name": "Upload digests",
46+
"uses": "actions/upload-artifact@v4",
47+
"with": {
48+
"if-no-files-found": "error",
49+
"name": "digests-${{ matrix.key }}",
50+
"path": "${{ runner.temp }}/digests/*",
51+
"retention-days": 1
52+
}
53+
}
54+
],
55+
"strategy": {
56+
"matrix": {
57+
"include": [
58+
{
59+
"key": "linux-arm64",
60+
"platform": "linux/arm64",
61+
"runner": "ubuntu-24.04-arm"
62+
}
63+
]
64+
}
65+
}
66+
},
67+
"merge": {
68+
"needs": [
69+
"build"
70+
],
71+
"permissions": {
72+
"id-token": "write"
73+
},
74+
"runs-on": "ubuntu-latest",
75+
"steps": [
76+
{
77+
"uses": "docker/setup-buildx-action@v3"
78+
},
79+
{
80+
"uses": "aws-actions/configure-aws-credentials@v4",
1981
"with": {
2082
"aws-region": "ap-northeast-1",
2183
"role-skip-session-tagging": true,
@@ -24,16 +86,25 @@
2486
},
2587
{
2688
"id": "login-ecr",
27-
"uses": "aws-actions/amazon-ecr-login@v1"
89+
"uses": "aws-actions/amazon-ecr-login@v2"
2890
},
2991
{
30-
"uses": "docker/build-push-action@v3",
92+
"name": "Download digests",
93+
"uses": "actions/download-artifact@v4",
3194
"with": {
32-
"context": "{{defaultContext}}:fluentd",
33-
"platforms": "linux/arm64",
34-
"push": true,
35-
"tags": "${{ steps.login-ecr.outputs.registry }}/fluentd:${{ github.sha }},${{ steps.login-ecr.outputs.registry }}/fluentd:latest"
95+
"merge-multiple": true,
96+
"path": "${{ runner.temp }}/digests",
97+
"pattern": "digests-*"
3698
}
99+
},
100+
{
101+
"env": {
102+
"REPO": "${{ steps.login-ecr.outputs.registry }}/fluentd",
103+
"RUNNER_TEMP": "${{ runner.temp }}",
104+
"SHA": "${{ github.sha }}"
105+
},
106+
"name": "Push manifest",
107+
"run": "cat \"${RUNNER_TEMP}\"/digests/* | xargs -I{} printf \"%s@%s\" \"${REPO}\" {} | docker buildx imagetools create -f /dev/stdin -t \"${REPO}:latest\" -t \"${REPO}:${SHA}\"\ndocker buildx imagetools inspect \"${REPO}:${SHA}\"\n"
37108
}
38109
]
39110
}

0 commit comments

Comments
 (0)