8
8
IMAGE_NAME : ${{ github.repository }}
9
9
10
10
jobs :
11
+ tagging :
12
+ name : Determine Tags
13
+ runs-on : ubuntu-20.04
14
+ permissions :
15
+ contents : read
16
+ packages : read
17
+ outputs :
18
+ FINAL_TAG : ${{ steps.tags.outputs.FINAL_TAG }}
19
+ SHA_TAG : ${{ steps.tags.outputs.SHA_TAG }}
20
+
21
+ steps :
22
+ - name : Log in to Container Registry
23
+ uses : docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
24
+ with :
25
+ registry : ${{ env.REGISTRY }}
26
+ username : ${{ github.actor }}
27
+ password : ${{ secrets.GITHUB_TOKEN }}
28
+
29
+ - name : Set up Docker Buildx
30
+ uses : docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
31
+
32
+ - name : Extract Docker Metadata
33
+ uses : docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
34
+ id : meta
35
+ with :
36
+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
37
+ tags : |
38
+ # Tag event produce a semver tag. This will capture tags that begin
39
+ # vX.Y.Z and X.Y.Z.
40
+ type=semver,pattern={{version}},event=tag
41
+ # All other push events (no PR, no semver tag), produce a SHA tag
42
+ type=sha,format=long
43
+
44
+ - name : Determine Final Tag
45
+ id : tags
46
+ run : |
47
+ ALL_TAGS="${{ steps.meta.outputs.tags }}"
48
+ SEMVER_TAG=$(echo "$ALL_TAGS" | grep -E '^ghcr.io/.+:[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?' || true)
49
+ SHA_TAG=$(echo "$ALL_TAGS" | grep sha- || true)
50
+
51
+ if [ -n "$SEMVER_TAG" ]; then
52
+ FINAL_TAG="$SEMVER_TAG"
53
+ else
54
+ FINAL_TAG="$SHA_TAG"
55
+ fi
56
+
57
+ echo "SHA_TAG=$SHA_TAG" >> $GITHUB_OUTPUT
58
+ echo "FINAL_TAG=$FINAL_TAG" >> $GITHUB_OUTPUT
59
+
60
+ - name : Debug Tags
61
+ run : |
62
+ echo "SHA_TAG: ${{ steps.tags.outputs.SHA_TAG }}"
63
+ echo "FINAL_TAG: ${{ steps.tags.outputs.FINAL_TAG }}"
64
+
11
65
build :
66
+ needs : tagging
12
67
runs-on : ${{ matrix.runner }}
13
68
strategy :
14
69
matrix :
@@ -41,27 +96,25 @@ jobs:
41
96
uses : docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
42
97
id : meta
43
98
with :
99
+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
44
100
tags : |
45
101
type=sha,format=long
46
- type=ref,prefix=pr-,event=pr
47
- type=semver,pattern={{version}},event=tag
48
- type=semver,pattern={{major}}.{{minor}},event=tag
49
- type=semver,pattern={{major}},event=tag
50
- images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
51
102
52
103
- name : Build and push Docker image
53
104
uses : docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v6.10.0
54
105
with :
55
106
file : Dockerfile
56
- tags : ${{ steps.meta .outputs.tags }}-${{ matrix.arch }}
107
+ tags : ${{ needs.tagging .outputs.SHA_TAG }}-${{ matrix.arch }}
57
108
push : true
58
109
labels : ${{ steps.meta.outputs.labels }}
59
110
cache-from : type=registry,ref=ghcr.io/datadog/lading:cache
60
111
cache-to : type=registry,ref=ghcr.io/datadog/lading:cache,mode=max
61
112
62
113
manifest :
63
114
name : Create Multi-Arch Manifest
64
- needs : build
115
+ needs :
116
+ - tagging
117
+ - build
65
118
runs-on : ubuntu-20.04
66
119
permissions :
67
120
contents : read
@@ -78,21 +131,9 @@ jobs:
78
131
- name : Set up Docker Buildx
79
132
uses : docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
80
133
81
- - name : Extract Docker Metadata
82
- uses : docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
83
- id : meta
84
- with :
85
- tags : |
86
- type=sha,format=long
87
- type=ref,prefix=pr-,event=pr
88
- type=semver,pattern={{version}},event=tag
89
- type=semver,pattern={{major}}.{{minor}},event=tag
90
- type=semver,pattern={{major}},event=tag
91
- images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
92
-
93
134
- name : Create and Push Multiarch Manifest
94
135
run : |
95
136
docker buildx imagetools create \
96
- --tag ${{ steps.meta .outputs.tags }} \
97
- ${{ steps.meta .outputs.tags }}-amd64 \
98
- ${{ steps.meta .outputs.tags }}-arm64
137
+ --tag " ${{ needs.tagging .outputs.FINAL_TAG }}" \
138
+ " ${{ needs.tagging .outputs.SHA_TAG }}-amd64" \
139
+ " ${{ needs.tagging .outputs.SHA_TAG }}-arm64"
0 commit comments