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@v2' },
13+ {
14+ uses: 'aws-actions/configure-aws-credentials@v1' ,
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@v1' ,
23+ id: 'login-ecr' ,
24+ },
25+ ];
26+
627function (name, region='ap-northeast-1' , platforms=['linux/arm64' ]) {
728 name: std.format ('docker-%s' , name),
829 on: {
@@ -17,33 +38,72 @@ function(name, region='ap-northeast-1', platforms=['linux/arm64']) {
1738 jobs: {
1839 build: {
1940 name: 'build' ,
20- 'runs-on' : 'ubuntu-latest' ,
41+ strategy: {
42+ matrix: {
43+ include: std.map (function (platform) {
44+ key: std.strReplace (platform, '/' , '-' ), // for artifact name
45+ platform: platform,
46+ runner: runnersMap[platform],
47+ }, platforms),
48+ },
49+ },
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@v3' ,
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 digest' ,
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+ uses: 'actions/upload-artifact@v4 ' ,
3976 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 ,
77+ name: 'digests-${{ matrix.key }}' ,
78+ path: '${{ runner.temp }}/digests/*' ,
79+ 'if-no-files-found' : 'error' ,
80+ 'retention-days' : 1 ,
81+ },
82+ },
83+ ],
84+ },
85+ merge: {
86+ 'runs-on' : 'ubuntu-latest' ,
87+ needs: ['build' ],
88+ permissions: { 'id-token' : 'write' },
89+ steps: setupSteps(region) + [
90+ {
91+ uses: 'actions/download-artifact@v4' ,
92+ with: {
93+ path: '${{ runner.temp }}/digests' ,
94+ pattern: 'digests-*' ,
95+ 'merge-multiple' : true ,
96+ },
97+ },
98+ {
99+ name: 'Push manifest' ,
100+ run: |||
101+ cat * | xargs -I{} printf "%s@%s" "${REPO}" {} | docker buildx imagetools create -f /dev/stdin -t "${REPO}:latest" -t "${REPO}:${SHA}"
102+ docker buildx imagetools inspect "${REPO}:${SHA}"
103+ ||| ,
104+ env: {
105+ REPO: std.format ('${{ steps.login-ecr.outputs.registry }}/%s' , name),
106+ SHA: '${{ github.sha }}' ,
47107 },
48108 },
49109 ],
0 commit comments