Skip to content

Commit 7a24c90

Browse files
committed
Add multiarch Docker images
1 parent 974d6d0 commit 7a24c90

2 files changed

Lines changed: 73 additions & 46 deletions

File tree

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,70 @@
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

1316
jobs:
1417
build:
15-
strategy:
16-
matrix:
17-
TARGETARCH: [amd64]
1818
runs-on: ubuntu-latest
19+
services:
20+
registry:
21+
image: registry:2
22+
ports:
23+
- 5000:5000
1924
steps:
20-
- uses: actions/checkout@v3
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 }}
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Docker meta
29+
id: meta
30+
uses: docker/metadata-action@v5
31+
with:
32+
images: |
33+
name=otel/build-protobuf,enable=${{ github.event_name != 'pull_request' }}
34+
name=localhost:5000/otel/build-protobuf
35+
tags: |
36+
type=edge
37+
type=ref,event=pr
38+
type=semver,pattern={{version}}
39+
40+
- name: Docker Buildx
41+
uses: docker/setup-buildx-action@v3
42+
43+
- name: Setup QEMU
44+
uses: docker/setup-qemu-action@v3
45+
with:
46+
platforms: arm64
47+
48+
- name: DockerHub Login
49+
uses: docker/login-action@v3
50+
with:
51+
username: ${{ secrets.DOCKER_USERNAME }}
52+
password: ${{ secrets.DOCKER_PASSWORD }}
53+
if: github.event_name != 'pull_request'
54+
55+
- name: Build Docker image
56+
uses: docker/build-push-action@v5
57+
id: build-push
58+
with:
59+
context: "protobuf/."
60+
cache-from: type=gha,scope=protobuf
61+
cache-to: type=gha,scope=protobuf,mode=max
62+
tags: ${{ steps.meta.outputs.tags }}
63+
labels: ${{ steps.meta.outputs.labels }}
64+
annotations: ${{ steps.meta.outputs.annotations }}
65+
platforms: "linux/arm64, linux/amd64"
66+
push: true
67+
pull: true
68+
sbom: true
69+
provenance: mode=max
70+
no-cache: ${{ github.event_name != 'pull_request' }}

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)