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

PIT-105: use buildx to build the image for multiple architectures #2595

Closed
wants to merge 3 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG GO_VERSION
FROM golang:${GO_VERSION}-buster AS builder
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-buster AS builder

WORKDIR /usr/src/fleet-server

Expand All @@ -12,12 +12,16 @@ COPY . .
ARG GCFLAGS=""
ARG LDFLAGS=""
ARG DEV=""
RUN GCFLAGS="${GCFLAGS}" LDFLAGS="${LDFLAGS}" DEV="${DEV}" make release-linux/amd64
ARG TARGETPLATFORM

RUN GCFLAGS="${GCFLAGS}" LDFLAGS="${LDFLAGS}" DEV="${DEV}" make release-${TARGETPLATFORM}

FROM ubuntu:20.04
ARG VERSION
ARG TARGETOS
ARG TARGETARCH

COPY fleet-server.yml /etc/fleet-server.yml
COPY --from=builder /usr/src/fleet-server/build/binaries/fleet-server-${VERSION}-linux-x86_64/fleet-server /usr/bin/fleet-server
COPY --from=builder /usr/src/fleet-server/build/binaries/fleet-server-${VERSION}-${TARGETOS}-*/fleet-server /usr/bin/fleet-server

CMD /usr/bin/fleet-server -c /etc/fleet-server.yml
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ TARGET_ARCH_386=x86
TARGET_ARCH_amd64=x86_64
TARGET_ARCH_arm64=arm64
PLATFORMS ?= darwin/amd64 darwin/arm64 linux/386 linux/amd64 linux/arm64 windows/386 windows/amd64
DOCKER_PLATFORMS ?= linux/amd64 linux/arm64
BUILDMODE_linux_amd64=-buildmode=pie
BUILDMODE_linux_arm64=-buildmode=pie
BUILDMODE_windows_386=-buildmode=pie
Expand Down Expand Up @@ -198,12 +199,14 @@ $(PLATFORM_TARGETS): release-%:

.PHONY: build-docker
build-docker:
docker build \
docker buildx create --use
docker buildx build --push \
--platform $(shell echo ${DOCKER_PLATFORMS} | sed 's/ /,/g') \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg=GCFLAGS="${GCFLAGS}" \
--build-arg=LDFLAGS="${LDFLAGS}" \
--build-arg=DEV="$(DEV)" \
--build-arg=VERSION="$(VERSION)" \
--build-arg=VERSION="$(VERSION)" --push \
-t $(DOCKER_IMAGE):$(DOCKER_IMAGE_TAG)$(if $(DEV),-dev,) .

.PHONY: release-docker
Expand Down
Loading