From b5323b5e05cc2df7f7a107646231559db0eac8be Mon Sep 17 00:00:00 2001 From: Robin Breathe Date: Mon, 29 Apr 2024 12:39:56 +0200 Subject: [PATCH] feat: linux/arm64 compatibility Fixes: #283 Signed-off-by: Robin Breathe --- .github/workflows/on-push-to-main-branch.yml | 1 + .github/workflows/on-release.yml | 1 + Dockerfile | 8 ++++---- Makefile | 11 +++++++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/on-push-to-main-branch.yml b/.github/workflows/on-push-to-main-branch.yml index 84fa9936..39d789e6 100644 --- a/.github/workflows/on-push-to-main-branch.yml +++ b/.github/workflows/on-push-to-main-branch.yml @@ -43,6 +43,7 @@ jobs: build-args: | pkg_version=${{ env.PLUGIN_VERSION }} context: . + platforms: linux/amd64,linux/arm64 tags: | ${{ env.TAG_BASE }}:latest ${{ env.TAG_BASE }}:${{ env.PLUGIN_VERSION }} diff --git a/.github/workflows/on-release.yml b/.github/workflows/on-release.yml index 0e44c0c4..3f357c27 100644 --- a/.github/workflows/on-release.yml +++ b/.github/workflows/on-release.yml @@ -44,6 +44,7 @@ jobs: build-args: | pkg_version=${{ steps.tag.outputs.tag }} context: . + platforms: linux/amd64,linux/arm64 tags: | ${{ env.TAG_BASE }}:latest ${{ env.TAG_BASE }}:${{steps.tag.outputs.tag}} diff --git a/Dockerfile b/Dockerfile index 7288a6b1..533705fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,8 @@ FROM golang:1.21 as builder WORKDIR /workspace -ARG TARGETARCH=amd64 -ARG TARGETOS=linux +ARG TARGETARCH +ARG TARGETOS ENV GOPROXY=direct # Copy the Go Modules manifests @@ -18,8 +18,8 @@ COPY main.go main.go COPY pkg/ pkg/ ENV CGO_ENABLED=0 -ENV GOOS=$TARGETOS -ENV GOARCH=$TARGETARCH +ENV GOOS=${TARGETOS:-linux} +ENV GOARCH=${TARGETARCH:-amd64} ENV GO111MODULE=on # Do an initial compilation before setting the version so that there is less to diff --git a/Makefile b/Makefile index a80e1372..4acc438f 100644 --- a/Makefile +++ b/Makefile @@ -151,6 +151,17 @@ docker-build: test docker-push: docker push ${IMG} +PLATFORMS ?= linux/arm64,linux/amd64 +.PHONY: docker-buildx +docker-buildx: ## Build docker image for the manager with cross-platform support + # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile + sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross + - docker buildx create --name project-v3-builder + docker buildx use project-v3-builder + - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . + - docker buildx rm project-v3-builder + rm Dockerfile.cross + CONTROLLER_GEN = $(shell pwd)/bin/controller-gen controller-gen: $(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1)