Skip to content

Build multiarch protobuf Docker images#73

Closed
yvrhdn wants to merge 2 commits intoopen-telemetry:mainfrom
yvrhdn:multiarch
Closed

Build multiarch protobuf Docker images#73
yvrhdn wants to merge 2 commits intoopen-telemetry:mainfrom
yvrhdn:multiarch

Conversation

@yvrhdn
Copy link
Copy Markdown

@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
Copy Markdown
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

builder: ${{ steps.buildx.outputs.name }}
context: ./protobuf/
platforms: linux/amd64,linux/arm64
push: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }}
Copy link
Copy Markdown
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
Copy Markdown
Author

yvrhdn commented Oct 11, 2021

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

Copy link
Copy Markdown

@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
Copy link
Copy Markdown

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
Copy Markdown
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.

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
Copy Markdown
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
Copy Markdown
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