From aeb81c8f3df424c589d1a423dbdc8d775833b491 Mon Sep 17 00:00:00 2001 From: Luca Comellini Date: Fri, 6 Jan 2023 13:00:16 +0100 Subject: [PATCH] Add multiarch Docker images --- .github/workflows/protobuf-dockerimage.yml | 66 ++++++++++++++++------ protobuf/Dockerfile | 58 ++++++++++--------- 2 files changed, 78 insertions(+), 46 deletions(-) diff --git a/.github/workflows/protobuf-dockerimage.yml b/.github/workflows/protobuf-dockerimage.yml index 69fc0eb5..95f4368d 100644 --- a/.github/workflows/protobuf-dockerimage.yml +++ b/.github/workflows/protobuf-dockerimage.yml @@ -10,25 +10,55 @@ on: - protobuf/Dockerfile - protobuf/protoc-wrapper +env: + PLATFORMS: "linux/arm, linux/arm64, linux/amd64" + jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Build the Docker image - run: docker build protobuf/. -t build-protobuf - - name: Push the Docker image - if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') - run: | - echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin - function tag_and_push { - docker tag build-protobuf "otel/build-protobuf:${1}" && docker push "otel/build-protobuf:${1}" - } - if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then - tag_and_push "latest" - elif [[ "${GITHUB_REF}" =~ refs/tags/v[0-9]+\.[0-9]+\.[0-9]+ ]]; then - TAG="${GITHUB_REF#"refs/tags/v"}" - tag_and_push "${TAG}" - else - tag_and_push "${GITHUB_REF#"refs/tags/"}" - fi \ No newline at end of file + - name: Checkout + uses: actions/checkout@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: | + name=otel/build-protobuf + tags: | + type=edge + type=ref,event=pr + type=semver,pattern={{version}} + + - name: Setup QEMU + uses: docker/setup-qemu-action@v2 + with: + platforms: arm,arm64 + # if: github.event_name != 'pull_request' # remove after PR testing + + - name: Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: DockerHub Login + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + if: github.event_name != 'pull_request' + + - name: Build Docker image + uses: docker/build-push-action@v3 + id: build-push + with: + context: 'protobuf/.' + cache-from: type=gha,scope=protobuf + cache-to: type=gha,scope=protobuf,mode=max + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: env.PLATFORMS + # platforms: ${{ github.event_name != 'pull_request' && env.PLATFORMS || '' }} # remove after PR testing + load: ${{ github.event_name == 'pull_request' }} + push: ${{ github.event_name != 'pull_request' }} + pull: true + no-cache: ${{ github.event_name != 'pull_request' }} diff --git a/protobuf/Dockerfile b/protobuf/Dockerfile index 5042e280..5a465379 100644 --- a/protobuf/Dockerfile +++ b/protobuf/Dockerfile @@ -1,5 +1,5 @@ -ARG ALPINE_VERSION=3.14 -ARG GO_VERSION=1.17.1 +ARG ALPINE_VERSION=3.17 +ARG GO_VERSION=1.19.4 # gRPC core version that applies to C++, C#, Objective-C, PhP, Python, Ruby ARG GRPC_VERSION=1.41.0 ARG PROTOBUF_C_VERSION=1.4.0 @@ -10,10 +10,10 @@ ARG PROTOC_GEN_GO_GRPC_VERSION=1.41.0 ARG GRPC_JAVA_VERSION=1.41.0 # v1.3.2, using the version directly does not work: "tar: invalid magic" ARG PROTOC_GEN_GOGO_VERSION=b03c65ea87cdc3521ede29f62fe3ce239267c1bc -ARG PROTOC_GEN_LINT_VERSION=0.2.4 -ARG GRPC_GATEWAY_VERSION=2.6.0 +ARG PROTOC_GEN_LINT_VERSION=0.3.0 +ARG GRPC_GATEWAY_VERSION=2.15.0 ARG PROTOC_GEN_PARQUET_VERSION=0.4.3 -ARG UPX_VERSION=3.96 +ARG UPX_VERSION=4.0.1 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/ mkdir -p /grpc/cmake/build && \ cd /grpc/cmake/build && \ cmake \ - -GNinja \ - -DBUILD_SHARED_LIBS=ON \ - -DCMAKE_INSTALL_PREFIX=/usr \ - -DCMAKE_BUILD_TYPE=Release \ - -DgRPC_INSTALL=ON \ - -DgRPC_BUILD_TESTS=OFF \ - ../.. && \ + -GNinja \ + -DBUILD_SHARED_LIBS=ON \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DCMAKE_BUILD_TYPE=Release \ + -DgRPC_INSTALL=ON \ + -DgRPC_BUILD_TESTS=OFF \ + ../.. && \ cmake --build . --target plugins && \ cmake --build . --target install && \ - DESTDIR=/out cmake --build . --target install + DESTDIR=/out cmake --build . --target install ARG PROTOBUF_C_VERSION RUN mkdir -p /protobuf-c && \ @@ -53,11 +53,11 @@ RUN mkdir -p /grpc-java && \ curl -sSL https://api.github.com/repos/grpc/grpc-java/tarball/v${GRPC_JAVA_VERSION} | tar xz --strip 1 -C /grpc-java && \ cd /grpc-java && \ g++ \ - -I. -I/usr/include \ - compiler/src/java_plugin/cpp/*.cpp \ - -L/usr/lib64 \ - -lprotoc -lprotobuf -lpthread --std=c++0x -s \ - -o protoc-gen-grpc-java && \ + -I. -I/usr/include \ + compiler/src/java_plugin/cpp/*.cpp \ + -L/usr/lib64 \ + -lprotoc -lprotobuf -lpthread --std=c++0x -s \ + -o protoc-gen-grpc-java && \ install -Ds protoc-gen-grpc-java /out/usr/bin/protoc-gen-grpc-java && \ rm -Rf /grpc-java && \ rm -Rf /grpc @@ -103,11 +103,12 @@ RUN mkdir -p ${GOPATH}/src/github.com/gogo/protobuf && \ install -D ./gogoproto/gogo.proto /out/usr/include/github.com/gogo/protobuf/gogoproto/gogo.proto ARG PROTOC_GEN_LINT_VERSION +ARG TARGETARCH RUN cd / && \ - curl -sSLO https://github.com/ckaznocha/protoc-gen-lint/releases/download/v${PROTOC_GEN_LINT_VERSION}/protoc-gen-lint_linux_amd64.zip && \ + curl -sSLO https://github.com/ckaznocha/protoc-gen-lint/releases/download/v${PROTOC_GEN_LINT_VERSION}/protoc-gen-lint_linux_${TARGETARCH}.zip && \ mkdir -p /protoc-gen-lint-out && \ cd /protoc-gen-lint-out && \ - unzip -q /protoc-gen-lint_linux_amd64.zip && \ + unzip -q /protoc-gen-lint_linux_${TARGETARCH}.zip && \ install -Ds /protoc-gen-lint-out/protoc-gen-lint /out/usr/bin/protoc-gen-lint ARG GRPC_GATEWAY_VERSION @@ -134,7 +135,8 @@ FROM alpine:${ALPINE_VERSION} as packer RUN apk add --no-cache curl ARG UPX_VERSION -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 && \ +ARG TARGETARCH +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 && \ install -D /upx/upx /usr/local/bin/upx # Use all output including headers and protoc from protoc_builder @@ -144,13 +146,13 @@ COPY --from=protoc_builder /out/ /out/ COPY --from=go_builder /out/ /out/ RUN upx --lzma $(find /out/usr/bin/ \ - -type f -name 'grpc_*' \ - -not -name 'grpc_csharp_plugin' \ - -not -name 'grpc_node_plugin' \ - -not -name 'grpc_php_plugin' \ - -not -name 'grpc_ruby_plugin' \ - -not -name 'grpc_python_plugin' \ - -or -name 'protoc-gen-*' \ + -type f -name 'grpc_*' \ + -not -name 'grpc_csharp_plugin' \ + -not -name 'grpc_node_plugin' \ + -not -name 'grpc_php_plugin' \ + -not -name 'grpc_ruby_plugin' \ + -not -name 'grpc_python_plugin' \ + -or -name 'protoc-gen-*' \ ) RUN find /out -name "*.a" -delete -or -name "*.la" -delete