@@ -2,10 +2,8 @@ name: Docker Build
22
33on :
44 push :
5- branches :
6- - main
7- tags :
8- - " *"
5+ branches : [main]
6+ tags : ["*"]
97 workflow_dispatch :
108 inputs :
119 tag :
1412 default : " nightly"
1513
1614jobs :
17- prepare :
18- name : Prepare Docker Metadata
19- runs-on : ubuntu-latest
20- permissions :
21- contents : read
22- outputs :
23- tags : ${{ steps.meta.outputs.tags }}
24- labels : ${{ steps.meta.outputs.labels }}
25- json : ${{ steps.meta.outputs.json }}
26- steps :
27- - name : Checkout code
28- uses : actions/checkout@v4
29-
30- - name : Extract metadata for Docker
31- id : meta
32- uses : docker/metadata-action@v5
33- with :
34- images : ghcr.io/${{ github.repository_owner }}/ziit
35- tags : |
36- type=raw,value=${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_type == 'tag' && github.ref_name || 'nightly' }}
37- type=sha,format=short
38-
3915 build :
40- name : Build ${{ matrix.platform }}
41- needs : prepare
4216 runs-on : ubuntu-latest
4317 permissions :
4418 contents : read
4519 packages : write
46- strategy :
47- fail-fast : false
48- matrix :
49- platform :
50- - linux/amd64
51- - linux/arm64
52- steps :
53- - name : Checkout code
54- uses : actions/checkout@v4
5520
56- - name : Prepare platform name
57- run : |
58- platform=${{ matrix.platform }}
59- echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
21+ steps :
22+ - uses : actions/checkout@v4
6023
6124 - name : Set up QEMU
6225 uses : docker/setup-qemu-action@v3
@@ -71,64 +34,22 @@ jobs:
7134 username : ${{ github.actor }}
7235 password : ${{ secrets.GITHUB_TOKEN }}
7336
74- - name : Build and push by digest
75- id : build
76- uses : docker/build-push-action@v5
77- with :
78- context : .
79- platforms : ${{ matrix.platform }}
80- labels : ${{ needs.prepare.outputs.labels }}
81- outputs : type=image,name=ghcr.io/${{ github.repository_owner }}/ziit,push-by-digest=true,name-canonical=true,push=true
82- cache-from : type=gha,scope=build-${{ env.PLATFORM_PAIR }}
83- cache-to : type=gha,mode=max,scope=build-${{ env.PLATFORM_PAIR }}
84-
85- - name : Export digest
86- run : |
87- mkdir -p /tmp/digests
88- digest="${{ steps.build.outputs.digest }}"
89- touch "/tmp/digests/${digest#sha256:}"
90-
91- - name : Upload digest
92- uses : actions/upload-artifact@v4
93- with :
94- name : digests-${{ env.PLATFORM_PAIR }}
95- path : /tmp/digests/*
96- if-no-files-found : error
97- retention-days : 1
98-
99- merge :
100- name : Create multi-arch manifest
101- runs-on : ubuntu-latest
102- needs : [prepare, build]
103- permissions :
104- contents : read
105- packages : write
106- steps :
107- - name : Download digests
108- uses : actions/download-artifact@v4
37+ - name : Docker meta
38+ id : meta
39+ uses : docker/metadata-action@v5
10940 with :
110- path : /tmp/digests
111- pattern : digests-*
112- merge-multiple : true
113-
114- - name : Set up Docker Buildx
115- uses : docker/setup-buildx-action@v3
41+ images : ghcr.io/${{ github.repository }}
42+ tags : |
43+ type=raw,value=${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_type == 'tag' && github.ref_name || 'nightly' }}
44+ type=sha,format=short
11645
117- - name : Login to GitHub Container Registry
118- uses : docker/login- action@v3
46+ - name : Build and push (multi-arch)
47+ uses : docker/build-push- action@v5
11948 with :
120- registry : ghcr.io
121- username : ${{ github.actor }}
122- password : ${{ secrets.GITHUB_TOKEN }}
123-
124- - name : Create manifest and push
125- working-directory : /tmp/digests
126- run : |
127- docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
128- $(printf 'ghcr.io/${{ github.repository_owner }}/ziit@sha256:%s ' *)
129- env :
130- DOCKER_METADATA_OUTPUT_JSON : ${{ needs.prepare.outputs.json }}
131-
132- - name : Inspect image
133- run : |
134- docker buildx imagetools inspect ghcr.io/${{ github.repository_owner }}/ziit:${{ fromJSON(needs.prepare.outputs.json).labels['org.opencontainers.image.version'] }}
49+ context : .
50+ platforms : linux/amd64,linux/arm64
51+ push : true
52+ tags : ${{ steps.meta.outputs.tags }}
53+ labels : ${{ steps.meta.outputs.labels }}
54+ cache-from : type=gha
55+ cache-to : type=gha,mode=max
0 commit comments