1
+ on :
2
+ workflow_call :
3
+ inputs :
4
+ image :
5
+ required : true
6
+ type : string
7
+ context :
8
+ required : true
9
+ type : string
10
+ dockerfile :
11
+ required : false
12
+ type : string
13
+ default : ${{ inputs.context }}
14
+ digestName :
15
+ required : true
16
+ type : string
17
+
18
+ jobs :
19
+ build :
20
+ runs-on : ubuntu-latest
21
+ strategy :
22
+ fail-fast : true
23
+ matrix :
24
+ platform :
25
+ - linux/amd64
26
+ - linux/arm64
27
+ steps :
28
+ - name : Checkout
29
+ uses : actions/checkout@v4
30
+ - name : Docker meta
31
+ id : meta
32
+ uses : docker/metadata-action@v5
33
+ with :
34
+ images : ${{ inputs.image }}
35
+ tags : |
36
+ type=raw,value=latest,enable=true
37
+ type=raw,value={{date 'YYYYMMDD'}},enable=true
38
+ - name : Set up Docker Buildx
39
+ uses : docker/setup-buildx-action@v3
40
+ - name : Login to GitHub Container Registry
41
+ uses : docker/login-action@v3
42
+ with :
43
+ registry : ghcr.io
44
+ username : ${{ github.actor }}
45
+ password : ${{ secrets.GITHUB_TOKEN }}
46
+ - name : Build and push by digest
47
+ id : build
48
+ uses : docker/build-push-action@v5
49
+ with :
50
+ build-args : ${{ inputs.buildArgs }}
51
+ context : ${{ inputs.context }}
52
+ file : ${{ inputs.dockerfile }}
53
+ labels : ${{ steps.meta.outputs.labels }}
54
+ platforms : ${{ matrix.platform }}
55
+ outputs : type=image,name=${{ inputs.image }},push-by-digest=true,name-canonical=true,push=true
56
+ cache-from : type=gha
57
+ cache-to : type=gha,mode=max
58
+ - name : Export digest
59
+ run : |
60
+ mkdir -p /tmp/digests
61
+ digest="${{ steps.build.outputs.digest }}"
62
+ touch "/tmp/digests/${digest#sha256:}"
63
+ - name : Upload digest
64
+ uses : actions/upload-artifact@v3
65
+ with :
66
+ name : ${{ inputs.digestName }}
67
+ path : /tmp/digests/*
68
+ if-no-files-found : error
69
+ retention-days : 1
70
+
71
+ merge :
72
+ name : Merge and publish
73
+ runs-on : ubuntu-latest
74
+ needs :
75
+ - build
76
+ steps :
77
+ - name : Download digests
78
+ uses : actions/download-artifact@v3
79
+ with :
80
+ name : ${{ inputs.digestName }}
81
+ path : /tmp/digests
82
+ - uses : geekyeggo/delete-artifact@v2
83
+ with :
84
+ name : ${{ inputs.digestName }}
85
+ - name : Set up Docker Buildx
86
+ uses : docker/setup-buildx-action@v3
87
+ - name : Docker meta
88
+ id : meta
89
+ uses : docker/metadata-action@v5
90
+ with :
91
+ images : ${{ inputs.image }}
92
+ tags : |
93
+ type=raw,value=latest,enable=true
94
+ type=raw,value={{date 'YYYYMMDD'}},enable=true
95
+ - name : Login to GitHub Container Registry
96
+ uses : docker/login-action@v3
97
+ with :
98
+ registry : ghcr.io
99
+ username : ${{ github.actor }}
100
+ password : ${{ secrets.GITHUB_TOKEN }}
101
+ - name : Create manifest list and push
102
+ working-directory : /tmp/digests
103
+ run : |
104
+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
105
+ $(printf '${{ inputs.image }}@sha256:%s ' *)
106
+ - name : Inspect image
107
+ run : |
108
+ docker buildx imagetools inspect ${{ inputs.image }}:${{ steps.meta.outputs.version }}
0 commit comments