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

[WIP] Multi-architecture container images #2397

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions .circleci/config.yml
Expand Up @@ -109,7 +109,27 @@ commands:
type: string
tag:
type: string
environment:
DOCKER_BUILDKIT: 1
BUILDX_PLATFORMS: linux/amd64,linux/arm64
steps:
- run:
name: Install Docker buildx
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh forgot this was still circleci, doh!

command: |
BUILDX_BINARY_URL="https://github.com/docker/buildx/releases/download/v0.5.1/buildx-v0.5.1.linux-amd64"

curl --output docker-buildx \
--silent --show-error --location --fail --retry 3 \
"$BUILDX_BINARY_URL"

mkdir -p ~/.docker/cli-plugins

mv docker-buildx ~/.docker/cli-plugins/
chmod a+x ~/.docker/cli-plugins/docker-buildx

docker buildx install
# Run binfmt
docker run --rm --privileged tonistiigi/binfmt:latest --install "$BUILDX_PLATFORMS"
- run:
name: Build image
command: |
Expand Down
26 changes: 23 additions & 3 deletions Makefile
Expand Up @@ -144,9 +144,25 @@ run:
.PHONY: docker-component # Not intended to be used directly
docker-component: check-component
GOOS=linux GOARCH=amd64 $(MAKE) $(COMPONENT)
cp ./bin/$(COMPONENT)_linux_amd64 ./cmd/$(COMPONENT)/$(COMPONENT)
docker build -t $(COMPONENT) ./cmd/$(COMPONENT)/
rm ./cmd/$(COMPONENT)/$(COMPONENT)
cp ./bin/$(COMPONENT)_linux_amd64 ./cmd/$(COMPONENT)
docker build -t $(COMPONENT) ./cmd/$(COMPONENT)/ --build-arg=TARGETOS=linux --build-arg=TARGETARCH=amd64
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it simpler to use buildx for this too so we don't need to define the args?

Copy link
Member Author

@gramidt gramidt Feb 22, 2021

Choose a reason for hiding this comment

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

My opinion at this time is to make the multi-architecture build additive and not require buildx for all contributors. Since 'make docker-otelcontribcol' is pre-existing, I believe it should continue to work without contributors updating their tooling. If contributors want to build multi-arch images, then they'll need to install buildx (doesn't seem common at this time).

Maybe after we have buildx working as expected in the CI/CD pipeline and are okay with requiring contributors to install an experimental tool, then we can fully migrate to buildx. I'm hoping that buildx will be fully baked into Docker this year, so it will become a natural progression.

rm ./cmd/$(COMPONENT)/$(COMPONENT)_linux_amd64

# Requires Docker buildx = v0.5.1 https://github.com/docker/buildx
export DOCKER_BUILDX_PLATFORMS ?= linux/amd64,linux/arm64
.PHONY: docker-cross-build-component # Not intended to be used directly
docker-cross-build-component: check-component
PLATFORMS='$(shell echo ${DOCKER_BUILDX_PLATFORMS} | sed "s/,/ /g")'; \
for platform in $${PLATFORMS}; do \
IFS='/' osAndArch=($$platform); \
GOOS=$${osAndArch[0]}; \
GOARCH=$${osAndArch[1]}; \
GOOS=$${osAndArch[0]} GOARCH=$${osAndArch[1]} $(MAKE) $(COMPONENT); \
cp ./bin/$(COMPONENT)_$${GOOS}_$${GOARCH} ./cmd/$(COMPONENT)/; \
done
docker buildx rm $(COMPONENT)
docker buildx create --use --name $(COMPONENT)
docker buildx build --platform ${DOCKER_BUILDX_PLATFORMS} -t $(COMPONENT) ./cmd/$(COMPONENT)

.PHONY: check-component
check-component:
Expand All @@ -158,6 +174,10 @@ endif
docker-otelcontribcol:
COMPONENT=otelcontribcol $(MAKE) docker-component

.PHONY: docker-cross-build-otelcontribcol
docker-cross-build-otelcontribcol:
COMPONENT=otelcontribcol $(MAKE) docker-cross-build-component

.PHONY: generate
generate:
$(MAKE) for-all CMD="go generate ./..."
Expand Down
4 changes: 3 additions & 1 deletion cmd/otelcontribcol/Dockerfile
Expand Up @@ -2,8 +2,10 @@ FROM alpine:latest as certs
RUN apk --update add ca-certificates

FROM scratch
ARG TARGETOS
ARG TARGETARCH
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY otelcontribcol /
COPY otelcontribcol_${TARGETOS}_${TARGETARCH} /otelcontribcol
EXPOSE 55680 55679
ENTRYPOINT ["/otelcontribcol"]
CMD ["--config", "/etc/otel/config.yaml"]