11name : Protobuf Docker Image
22on :
33 push :
4- tags : [ '**' ]
5- branches : [ main ]
4+ tags :
5+ - " **"
6+ branches :
7+ - main
68 pull_request :
7- branches : [ main ]
9+ branches :
10+ - main
811 paths :
912 - .github/workflows/protobuf-dockerimage.yml
1013 - protobuf/Dockerfile
1114 - protobuf/protoc-wrapper
1215
16+ env :
17+ DOCKERHUB_SLUG : otel/build-protobuf
18+
1319jobs :
1420 build :
21+ runs-on : ubuntu-latest
1522 strategy :
23+ fail-fast : false
1624 matrix :
17- TARGETARCH : [amd64]
25+ platform :
26+ - linux/amd64
27+ - linux/arm64
28+ steps :
29+ - name : Prepare
30+ run : |
31+ platform=${{ matrix.platform }}
32+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
33+
34+ - name : Checkout
35+ uses : actions/checkout@v4
36+
37+ - name : Docker meta
38+ id : meta
39+ uses : docker/metadata-action@v5
40+ with :
41+ images : |
42+ name=${{ env.DOCKERHUB_SLUG}}
43+ tags : |
44+ type=edge
45+ type=ref,event=pr
46+ type=semver,pattern={{version}}
47+
48+ - name : Setup QEMU
49+ uses : docker/setup-qemu-action@v3
50+
51+ - name : Docker Buildx
52+ uses : docker/setup-buildx-action@v3
53+ with :
54+ driver-opts : network=host
55+
56+ - name : DockerHub Login
57+ uses : docker/login-action@v3
58+ with :
59+ username : ${{ secrets.DOCKER_USERNAME }}
60+ password : ${{ secrets.DOCKER_PASSWORD }}
61+ if : github.event_name != 'pull_request'
62+
63+ - name : Build and push by digest
64+ id : build
65+ uses : docker/build-push-action@v6
66+ with :
67+ context : " protobuf/."
68+ cache-from : type=gha,scope=protobuf-${{ env.PLATFORM_PAIR }}
69+ cache-to : type=gha,scope=protobuf-${{ env.PLATFORM_PAIR }},mode=max
70+ platforms : ${{ matrix.platform }}
71+ labels : ${{ steps.meta.outputs.labels }}
72+ annotations : ${{ steps.meta.outputs.annotations }}
73+ pull : true
74+ sbom : true
75+ provenance : mode=max
76+ outputs : type=image,name=${{ env.DOCKERHUB_SLUG }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}
77+
78+ - name : Export digest
79+ run : |
80+ mkdir -p /tmp/digests
81+ digest="${{ steps.build.outputs.digest }}"
82+ touch "/tmp/digests/${digest#sha256:}"
83+
84+ - name : Upload digest
85+ uses : actions/upload-artifact@v4
86+ with :
87+ name : digests-${{ env.PLATFORM_PAIR }}
88+ path : /tmp/digests/*
89+ if-no-files-found : error
90+ retention-days : 1
91+
92+
93+ merge :
1894 runs-on : ubuntu-latest
95+ if : github.event_name != 'pull_request'
96+ needs :
97+ - build
1998 steps :
20- - uses : actions/checkout@v4
21- - name : Build the Docker image
22- run : docker build protobuf/. -t build-protobuf
23- env :
24- TARGETARCH : ${{ matrix.TARGETARCH }}
25- - name : Push the Docker image
26- if : github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
27- run : |
28- echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
29- function tag_and_push {
30- docker tag build-protobuf "otel/build-protobuf:${1}" && docker push "otel/build-protobuf:${1}"
31- }
32- if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
33- tag_and_push "latest"
34- elif [[ "${GITHUB_REF}" =~ refs/tags/v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
35- TAG="${GITHUB_REF#"refs/tags/v"}"
36- tag_and_push "${TAG}"
37- else
38- tag_and_push "${GITHUB_REF#"refs/tags/"}"
39- fi
40- env :
41- TARGETARCH : ${{ matrix.TARGETARCH }}
99+ - name : Download digests
100+ uses : actions/download-artifact@v4
101+ with :
102+ path : /tmp/digests
103+ pattern : digests-*
104+ merge-multiple : true
105+
106+ - name : Set up Docker Buildx
107+ uses : docker/setup-buildx-action@v3
108+
109+ - name : Docker meta
110+ id : meta
111+ uses : docker/metadata-action@v5
112+ with :
113+ images : |
114+ name=${{ env.DOCKERHUB_SLUG}}
115+ tags : |
116+ type=edge
117+ type=semver,pattern={{version}}
118+
119+ - name : Login to Docker Hub
120+ uses : docker/login-action@v3
121+ with :
122+ username : ${{ vars.DOCKERHUB_USERNAME }}
123+ password : ${{ secrets.DOCKERHUB_TOKEN }}
124+
125+ - name : Create manifest list and push
126+ working-directory : /tmp/digests
127+ run : |
128+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
129+ $(printf '${{ env.DOCKERHUB_SLUG }}@sha256:%s ' *)
130+
131+ - name : Inspect image
132+ run : |
133+ docker buildx imagetools inspect ${{ env.DOCKERHUB_SLUG }}:${{ steps.meta.outputs.version }}
0 commit comments