Skip to content

Commit aeb81c8

Browse files
committed
Add multiarch Docker images
1 parent 3b9a9d3 commit aeb81c8

File tree

2 files changed

+78
-46
lines changed

2 files changed

+78
-46
lines changed

.github/workflows/protobuf-dockerimage.yml

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,55 @@ on:
1010
- protobuf/Dockerfile
1111
- protobuf/protoc-wrapper
1212

13+
env:
14+
PLATFORMS: "linux/arm, linux/arm64, linux/amd64"
15+
1316
jobs:
1417
build:
1518
runs-on: ubuntu-latest
1619
steps:
17-
- uses: actions/checkout@v3
18-
- name: Build the Docker image
19-
run: docker build protobuf/. -t build-protobuf
20-
- name: Push the Docker image
21-
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
22-
run: |
23-
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
24-
function tag_and_push {
25-
docker tag build-protobuf "otel/build-protobuf:${1}" && docker push "otel/build-protobuf:${1}"
26-
}
27-
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
28-
tag_and_push "latest"
29-
elif [[ "${GITHUB_REF}" =~ refs/tags/v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
30-
TAG="${GITHUB_REF#"refs/tags/v"}"
31-
tag_and_push "${TAG}"
32-
else
33-
tag_and_push "${GITHUB_REF#"refs/tags/"}"
34-
fi
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
23+
- name: Docker meta
24+
id: meta
25+
uses: docker/metadata-action@v4
26+
with:
27+
images: |
28+
name=otel/build-protobuf
29+
tags: |
30+
type=edge
31+
type=ref,event=pr
32+
type=semver,pattern={{version}}
33+
34+
- name: Setup QEMU
35+
uses: docker/setup-qemu-action@v2
36+
with:
37+
platforms: arm,arm64
38+
# if: github.event_name != 'pull_request' # remove after PR testing
39+
40+
- name: Docker Buildx
41+
uses: docker/setup-buildx-action@v2
42+
43+
- name: DockerHub Login
44+
uses: docker/login-action@v2
45+
with:
46+
username: ${{ secrets.DOCKER_USERNAME }}
47+
password: ${{ secrets.DOCKER_PASSWORD }}
48+
if: github.event_name != 'pull_request'
49+
50+
- name: Build Docker image
51+
uses: docker/build-push-action@v3
52+
id: build-push
53+
with:
54+
context: 'protobuf/.'
55+
cache-from: type=gha,scope=protobuf
56+
cache-to: type=gha,scope=protobuf,mode=max
57+
tags: ${{ steps.meta.outputs.tags }}
58+
labels: ${{ steps.meta.outputs.labels }}
59+
platforms: env.PLATFORMS
60+
# platforms: ${{ github.event_name != 'pull_request' && env.PLATFORMS || '' }} # remove after PR testing
61+
load: ${{ github.event_name == 'pull_request' }}
62+
push: ${{ github.event_name != 'pull_request' }}
63+
pull: true
64+
no-cache: ${{ github.event_name != 'pull_request' }}

protobuf/Dockerfile

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
ARG ALPINE_VERSION=3.14
2-
ARG GO_VERSION=1.17.1
1+
ARG ALPINE_VERSION=3.17
2+
ARG GO_VERSION=1.19.4
33
# gRPC core version that applies to C++, C#, Objective-C, PhP, Python, Ruby
44
ARG GRPC_VERSION=1.41.0
55
ARG PROTOBUF_C_VERSION=1.4.0
@@ -10,10 +10,10 @@ ARG PROTOC_GEN_GO_GRPC_VERSION=1.41.0
1010
ARG GRPC_JAVA_VERSION=1.41.0
1111
# v1.3.2, using the version directly does not work: "tar: invalid magic"
1212
ARG PROTOC_GEN_GOGO_VERSION=b03c65ea87cdc3521ede29f62fe3ce239267c1bc
13-
ARG PROTOC_GEN_LINT_VERSION=0.2.4
14-
ARG GRPC_GATEWAY_VERSION=2.6.0
13+
ARG PROTOC_GEN_LINT_VERSION=0.3.0
14+
ARG GRPC_GATEWAY_VERSION=2.15.0
1515
ARG PROTOC_GEN_PARQUET_VERSION=0.4.3
16-
ARG UPX_VERSION=3.96
16+
ARG UPX_VERSION=4.0.1
1717

1818

1919
FROM alpine:${ALPINE_VERSION} as protoc_builder
@@ -27,16 +27,16 @@ RUN git clone --recursive --depth=1 -b v${GRPC_VERSION} https://github.com/grpc/
2727
mkdir -p /grpc/cmake/build && \
2828
cd /grpc/cmake/build && \
2929
cmake \
30-
-GNinja \
31-
-DBUILD_SHARED_LIBS=ON \
32-
-DCMAKE_INSTALL_PREFIX=/usr \
33-
-DCMAKE_BUILD_TYPE=Release \
34-
-DgRPC_INSTALL=ON \
35-
-DgRPC_BUILD_TESTS=OFF \
36-
../.. && \
30+
-GNinja \
31+
-DBUILD_SHARED_LIBS=ON \
32+
-DCMAKE_INSTALL_PREFIX=/usr \
33+
-DCMAKE_BUILD_TYPE=Release \
34+
-DgRPC_INSTALL=ON \
35+
-DgRPC_BUILD_TESTS=OFF \
36+
../.. && \
3737
cmake --build . --target plugins && \
3838
cmake --build . --target install && \
39-
DESTDIR=/out cmake --build . --target install
39+
DESTDIR=/out cmake --build . --target install
4040

4141
ARG PROTOBUF_C_VERSION
4242
RUN mkdir -p /protobuf-c && \
@@ -53,11 +53,11 @@ RUN mkdir -p /grpc-java && \
5353
curl -sSL https://api.github.com/repos/grpc/grpc-java/tarball/v${GRPC_JAVA_VERSION} | tar xz --strip 1 -C /grpc-java && \
5454
cd /grpc-java && \
5555
g++ \
56-
-I. -I/usr/include \
57-
compiler/src/java_plugin/cpp/*.cpp \
58-
-L/usr/lib64 \
59-
-lprotoc -lprotobuf -lpthread --std=c++0x -s \
60-
-o protoc-gen-grpc-java && \
56+
-I. -I/usr/include \
57+
compiler/src/java_plugin/cpp/*.cpp \
58+
-L/usr/lib64 \
59+
-lprotoc -lprotobuf -lpthread --std=c++0x -s \
60+
-o protoc-gen-grpc-java && \
6161
install -Ds protoc-gen-grpc-java /out/usr/bin/protoc-gen-grpc-java && \
6262
rm -Rf /grpc-java && \
6363
rm -Rf /grpc
@@ -103,11 +103,12 @@ RUN mkdir -p ${GOPATH}/src/github.com/gogo/protobuf && \
103103
install -D ./gogoproto/gogo.proto /out/usr/include/github.com/gogo/protobuf/gogoproto/gogo.proto
104104

105105
ARG PROTOC_GEN_LINT_VERSION
106+
ARG TARGETARCH
106107
RUN cd / && \
107-
curl -sSLO https://github.com/ckaznocha/protoc-gen-lint/releases/download/v${PROTOC_GEN_LINT_VERSION}/protoc-gen-lint_linux_amd64.zip && \
108+
curl -sSLO https://github.com/ckaznocha/protoc-gen-lint/releases/download/v${PROTOC_GEN_LINT_VERSION}/protoc-gen-lint_linux_${TARGETARCH}.zip && \
108109
mkdir -p /protoc-gen-lint-out && \
109110
cd /protoc-gen-lint-out && \
110-
unzip -q /protoc-gen-lint_linux_amd64.zip && \
111+
unzip -q /protoc-gen-lint_linux_${TARGETARCH}.zip && \
111112
install -Ds /protoc-gen-lint-out/protoc-gen-lint /out/usr/bin/protoc-gen-lint
112113

113114
ARG GRPC_GATEWAY_VERSION
@@ -134,7 +135,8 @@ FROM alpine:${ALPINE_VERSION} as packer
134135
RUN apk add --no-cache curl
135136

136137
ARG UPX_VERSION
137-
RUN mkdir -p /upx && curl -sSL https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-amd64_linux.tar.xz | tar xJ --strip 1 -C /upx && \
138+
ARG TARGETARCH
139+
RUN mkdir -p /upx && curl -sSL https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-${TARGETARCH}_linux.tar.xz | tar xJ --strip 1 -C /upx && \
138140
install -D /upx/upx /usr/local/bin/upx
139141

140142
# Use all output including headers and protoc from protoc_builder
@@ -144,13 +146,13 @@ COPY --from=protoc_builder /out/ /out/
144146
COPY --from=go_builder /out/ /out/
145147

146148
RUN upx --lzma $(find /out/usr/bin/ \
147-
-type f -name 'grpc_*' \
148-
-not -name 'grpc_csharp_plugin' \
149-
-not -name 'grpc_node_plugin' \
150-
-not -name 'grpc_php_plugin' \
151-
-not -name 'grpc_ruby_plugin' \
152-
-not -name 'grpc_python_plugin' \
153-
-or -name 'protoc-gen-*' \
149+
-type f -name 'grpc_*' \
150+
-not -name 'grpc_csharp_plugin' \
151+
-not -name 'grpc_node_plugin' \
152+
-not -name 'grpc_php_plugin' \
153+
-not -name 'grpc_ruby_plugin' \
154+
-not -name 'grpc_python_plugin' \
155+
-or -name 'protoc-gen-*' \
154156
)
155157
RUN find /out -name "*.a" -delete -or -name "*.la" -delete
156158

0 commit comments

Comments
 (0)