Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build multiarch protobuf Docker images #73

Closed
wants to merge 2 commits into from
Closed

Build multiarch protobuf Docker images #73

wants to merge 2 commits into from

Conversation

yvrhdn
Copy link

@yvrhdn yvrhdn commented Oct 8, 2021

This adapts protobuf/Dockerfile so it can be built for amd64 and arm64 targets by using TARGETARCH.
I had to update PROTOC_GEN_LINT_VERSION as only v0.2.4 has downloads for all archs.

Next I updated the GitHub Actions workflow, I'm using docker/build-push-action to build multiarch images. Under the hood this uses docker buildx.

You can run buildx locally using:

docker buildx build --load --platform linux/arm64 -t otel/protobuf:latest protobuf

Fixes #42

@yvrhdn yvrhdn requested a review from a team October 8, 2021 14:24
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Determine tag
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might be able to replace this with docker/metadata-action. Basic seems to do what we want here: https://github.com/docker/metadata-action#basic

context: ./protobuf/
platforms: linux/amd64,linux/arm64
push: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will always build the multiarch images, but only push if we are on main or building from a tag. Since this action only runs from main or a tag, this isn't necessary I think? Anyway, I copied the original logic for now.

@yvrhdn
Copy link
Author

yvrhdn commented Oct 11, 2021

I see I used the wrong secret name, this should work 🙂

Copy link

@codeboten codeboten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dockerfile changes look good, I submitted a similar PR without noticing this one existed before https://github.com/open-telemetry/build-tools/pull/75/files.

Regarding the workflow changes, it looks fine, but maybe @jpkrohling has some guidance around the preferred tooling for publishing docker images.

unzip -q /protoc-gen-lint_linux_amd64.zip && \
install -Ds /protoc-gen-lint-out/protoc-gen-lint /out/usr/bin/protoc-gen-lint
unzip -q /protoc-gen-lint_linux_${TARGETARCH}.zip && \
install -D /protoc-gen-lint-out/protoc-gen-lint /out/usr/bin/protoc-gen-lint

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to remove the -s flag?

Copy link
Member

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I don't quite like the tagging logic but might be OK if the linked action (docker/metadata-action) isn't suitable. In general, this is a similar approach we use in other repositories (Jaeger and some operators, IIRC) with the exception of the collector-releases and -builder, but we don't produce container images for every commit there. Instead, we produce the artifacts, including container images, via goreleaser only during releases.

@@ -129,7 +130,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 && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are only building linux/amd64,linux/arm64, so, it should be fine, but I had problems before with binaries for macOS after going through upx. Do you know how big the image is before and after upx? Perhaps it's not worth the risk?

@bogdandrutu
Copy link
Member

@kvrhdn please address all the concerns/comments.

@yvrhdn yvrhdn closed this by deleting the head repository Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

build-protobuf crashes with segmentation fault on Apple M1
4 participants