From d80e5fdeb1612c1c9426ceac4a945949104651c3 Mon Sep 17 00:00:00 2001 From: dharam Date: Tue, 11 Nov 2025 10:58:07 +0530 Subject: [PATCH 1/2] Add ARM multi-platform support with docker buildx - Update Dockerfile to support multi-platform builds using BUILDPLATFORM and TARGETPLATFORM - Add default values for backward compatibility with regular docker build - Update GitHub Actions workflow to use docker buildx for linux/amd64 and linux/arm64 - Simplify Makefile docker-buildx target to directly use updated Dockerfile - Remove platform hardcoding and enable cross-platform builds Fixes #355 Signed-off-by: dharam --- .github/workflows/build-and-release.yml | 37 ++++++++++++------------- Dockerfile | 15 ++++++++-- Makefile | 8 ++---- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index ade2f084..a8bb703b 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -12,36 +12,35 @@ jobs: runs-on: ubuntu-24.04 steps: - name: Check out code - uses: actions/checkout@master + uses: actions/checkout@v4 with: fetch-depth: 1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - name: Docker login uses: azure/docker-login@v1 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - name: Docker edge build & tag + - name: Docker edge build & push if: startsWith(github.ref, 'refs/tags/') != true && success() run: | - DOCKER_BUILDKIT=1 docker build --no-cache -t ${{ secrets.IMAGE_NAME }}:edge-latest . - docker tag ${{ secrets.IMAGE_NAME }}:edge-latest ${{ secrets.IMAGE_NAME }}:edge-${GITHUB_SHA::7} - - name: Docker edge push - if: startsWith(github.ref, 'refs/tags/') != true && success() - run: | - docker push ${{ secrets.IMAGE_NAME }}:edge-latest - docker push ${{ secrets.IMAGE_NAME }}:edge-${GITHUB_SHA::7} - - name: Docker stable build & tag - if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') && success() - run: | - DOCKER_BUILDKIT=1 docker build --no-cache -t ${{ secrets.IMAGE_NAME }}:stable-latest . - docker tag ${{ secrets.IMAGE_NAME }}:stable-latest ${{ secrets.IMAGE_NAME }}:stable-${GITHUB_REF/refs\/tags\//} - docker tag ${{ secrets.IMAGE_NAME }}:stable-latest ${{ secrets.IMAGE_NAME }}:stable-${GITHUB_SHA::7} - - name: Docker stable push + docker buildx build --platform linux/amd64,linux/arm64 \ + --push \ + --no-cache \ + -t ${{ secrets.IMAGE_NAME }}:edge-latest \ + -t ${{ secrets.IMAGE_NAME }}:edge-${GITHUB_SHA::7} \ + . + - name: Docker stable build & push if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') && success() run: | - docker push ${{ secrets.IMAGE_NAME }}:stable-latest - docker push ${{ secrets.IMAGE_NAME }}:stable-${GITHUB_REF/refs\/tags\//} - docker push ${{ secrets.IMAGE_NAME }}:stable-${GITHUB_SHA::7} + docker buildx build --platform linux/amd64,linux/arm64 \ + --push \ + --no-cache \ + -t ${{ secrets.IMAGE_NAME }}:stable-latest \ + -t ${{ secrets.IMAGE_NAME }}:stable-${GITHUB_REF/refs\/tags\//} \ + -t ${{ secrets.IMAGE_NAME }}:stable-${GITHUB_SHA::7} \ + . # - name: Docker Hub Description # if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') && success() # uses: peter-evans/dockerhub-description@v2.0.0 diff --git a/Dockerfile b/Dockerfile index a91d3994..e9024751 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,13 @@ # Build the manager binary -FROM golang:1.24 as builder +ARG BUILDPLATFORM=linux/amd64 +ARG TARGETPLATFORM=linux/amd64 +ARG TARGETOS=linux +ARG TARGETARCH=amd64 + +FROM --platform=${BUILDPLATFORM} golang:1.24 as builder + +ARG TARGETOS +ARG TARGETARCH WORKDIR /workspace # Copy the Go Modules manifests @@ -16,11 +24,12 @@ COPY controllers/ controllers/ COPY pkg/ pkg/ # Build -RUN CGO_ENABLED=0 GO111MODULE=on go build -a -o manager main.go +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GO111MODULE=on go build -a -o manager main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details -FROM gcr.io/distroless/static:nonroot +ARG TARGETPLATFORM +FROM --platform=${TARGETPLATFORM} gcr.io/distroless/static:nonroot WORKDIR / COPY --from=builder /workspace/manager . USER nonroot:nonroot diff --git a/Makefile b/Makefile index 643a50c7..74b4f0a4 100644 --- a/Makefile +++ b/Makefile @@ -150,13 +150,9 @@ docker-push: ## Push docker image with the manager. PLATFORMS ?= linux/arm64,linux/amd64 .PHONY: docker-buildx docker-buildx: test ## Build and push docker image for the manager for 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 create --name project-v3-builder --use + - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile . - docker buildx rm project-v3-builder - rm Dockerfile.cross ##@ Deployment From 73389e576c6535b199feca7fddb2453e3b81fc5a Mon Sep 17 00:00:00 2001 From: Dharmendra solanki <78801686+ProgrammingPirates@users.noreply.github.com> Date: Wed, 12 Nov 2025 11:57:50 +0530 Subject: [PATCH 2/2] Update build-and-release.yml Signed-off-by: Dharmendra solanki <78801686+ProgrammingPirates@users.noreply.github.com> --- .github/workflows/build-and-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index a8bb703b..978d0d6d 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-24.04 steps: - name: Check out code - uses: actions/checkout@v4 + uses: actions/checkout@v5 with: fetch-depth: 1 - name: Set up Docker Buildx