Skip to content

Commit 4f348f2

Browse files
committed
Add multiarch Docker images
Signed-off-by: Luca Comellini <luca.com@gmail.com>
1 parent e8bd6f8 commit 4f348f2

2 files changed

Lines changed: 134 additions & 44 deletions

File tree

Lines changed: 118 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,133 @@
11
name: Protobuf Docker Image
22
on:
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+
1319
jobs:
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 }}

protobuf/Dockerfile

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
# gRPC core version that applies to C++, C#, Objective-C, PhP, Python, Ruby
2-
ARG GRPC_VERSION=1.52.0
3-
ARG PROTOBUF_C_VERSION=1.4.1
2+
ARG GRPC_VERSION=1.52.2
3+
ARG PROTOBUF_C_VERSION=1.5.0
44
ARG GRPC_WEB_VERSION=1.3.0
55

6-
ARG PROTOC_GEN_GO_VERSION=1.5.2
7-
ARG PROTOC_GEN_GO_GRPC_VERSION=1.41.0
8-
ARG GRPC_JAVA_VERSION=1.51.3
9-
# v1.3.2, using the version directly does not work: "tar: invalid magic"
10-
ARG PROTOC_GEN_GOGO_VERSION=b03c65ea87cdc3521ede29f62fe3ce239267c1bc
6+
ARG PROTOC_GEN_GO_VERSION=1.32.0
7+
ARG PROTOC_GEN_GO_GRPC_VERSION=1.52.3
8+
ARG GRPC_JAVA_VERSION=1.52.1
9+
# use the lastest commit from master
10+
ARG PROTOC_GEN_GOGO_VERSION=f67b8970b736e53dbd7d0a27146c8f1ac52f74e5
1111
ARG PROTOC_GEN_LINT_VERSION=0.3.0
12-
ARG GRPC_GATEWAY_VERSION=2.15.0
12+
ARG GRPC_GATEWAY_VERSION=2.19.1
1313
ARG PROTOC_GEN_PARQUET_VERSION=0.4.3
14-
ARG UPX_VERSION=4.0.2
15-
16-
ARG TARGETARCH=amd64
14+
ARG UPX_VERSION=4.2.2
1715

1816
FROM alpine:3.18 as protoc_builder
1917
RUN apk add --no-cache build-base curl automake autoconf libtool git zlib-dev linux-headers cmake ninja
@@ -55,7 +53,7 @@ RUN mkdir -p /grpc-java && \
5553
-I. -I/usr/include \
5654
compiler/src/java_plugin/cpp/*.cpp \
5755
-L/usr/lib64 \
58-
-lprotoc -lprotobuf -lpthread --std=c++0x -s \
56+
-lprotoc -lprotobuf -lpthread -s \
5957
-o protoc-gen-grpc-java && \
6058
install -Ds protoc-gen-grpc-java /out/usr/bin/protoc-gen-grpc-java && \
6159
rm -Rf /grpc-java && \
@@ -68,7 +66,7 @@ RUN mkdir -p /grpc-web && \
6866
make install-plugin && \
6967
install -Ds /usr/local/bin/protoc-gen-grpc-web /out/usr/bin/protoc-gen-grpc-web
7068

71-
FROM golang:1.18-alpine3.14 as go_builder
69+
FROM golang:1.22-alpine as go_builder
7270
RUN apk add --no-cache build-base curl git
7371

7472
ARG PROTOC_GEN_GO_GRPC_VERSION
@@ -79,10 +77,10 @@ RUN mkdir -p ${GOPATH}/src/github.com/grpc/grpc-go && \
7977
install -Ds /golang-protobuf-out/protoc-gen-go-grpc /out/usr/bin/protoc-gen-go-grpc
8078

8179
ARG PROTOC_GEN_GO_VERSION
82-
RUN mkdir -p ${GOPATH}/src/github.com/golang/protobuf && \
83-
curl -sSL https://api.github.com/repos/golang/protobuf/tarball/v${PROTOC_GEN_GO_VERSION} | tar xz --strip 1 -C ${GOPATH}/src/github.com/golang/protobuf &&\
84-
cd ${GOPATH}/src/github.com/golang/protobuf && \
85-
go build -ldflags '-w -s' -o /golang-protobuf-out/protoc-gen-go ./protoc-gen-go && \
80+
RUN mkdir -p ${GOPATH}/src/github.com/protocolbuffers/protobuf-go && \
81+
curl -sSL https://api.github.com/repos/protocolbuffers/protobuf-go/tarball/v${PROTOC_GEN_GO_VERSION} | tar xz --strip 1 -C ${GOPATH}/src/github.com/protocolbuffers/protobuf-go &&\
82+
cd ${GOPATH}/src/github.com/protocolbuffers/protobuf-go && \
83+
go build -ldflags '-w -s' -o /golang-protobuf-out/protoc-gen-go ./cmd/protoc-gen-go && \
8684
install -Ds /golang-protobuf-out/protoc-gen-go /out/usr/bin/protoc-gen-go
8785

8886
ARG PROTOC_GEN_GOGO_VERSION
@@ -108,7 +106,7 @@ RUN cd / && \
108106
mkdir -p /protoc-gen-lint-out && \
109107
cd /protoc-gen-lint-out && \
110108
unzip -q /protoc-gen-lint_linux_${TARGETARCH}.zip && \
111-
install -Ds /protoc-gen-lint-out/protoc-gen-lint /out/usr/bin/protoc-gen-lint
109+
install -D /protoc-gen-lint-out/protoc-gen-lint /out/usr/bin/protoc-gen-lint
112110

113111
ARG GRPC_GATEWAY_VERSION
114112
RUN mkdir -p ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway && \

0 commit comments

Comments
 (0)