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

Add support for multiarch images, include ARM64 #1453

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 15 additions & 8 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ jobs:
path: ~/.cache/go-build
key: ${{ runner.os }}-go-build-v1-${{ github.run_id }}

- name: Build operator and Tag Latest
run: make docker-build
env:
IMG: ${{ env.REGISTRY_URL }}/${{ env.ORG }}/${{ env.REPO }}:latest
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Login to Registry
uses: docker/login-action@v3
Expand All @@ -42,7 +44,12 @@ jobs:
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}

- name: Push latest operator
run: make docker-push
env:
IMG: ${{ env.REGISTRY_URL }}/${{ env.ORG }}/${{ env.REPO }}:latest
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ env.REGISTRY_URL }}/${{ env.ORG }}/${{ env.REPO }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
Comment on lines +54 to +55
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the purpose of this?

Copy link
Author

@lwj5 lwj5 Jul 22, 2024

Choose a reason for hiding this comment

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

This exports and retrieves docker build cache to GitHub cache to speed up build time if certain layers have not changed.

https://docs.docker.com/reference/cli/docker/buildx/build/#cache-to

on your local host, this is done transparently. Hence why the 2nd docker build is slightly faster

6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Build the manager binary
FROM golang:1.21 as builder
FROM --platform=$BUILDPLATFORM golang:1.21 as builder
Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume $BUILDPLATFORM will default to the arch on which the build is running on if not set. Can you confirm if make docker-build runs fine and local dev builds are not impacted with this change?

Copy link
Author

@lwj5 lwj5 Jul 22, 2024

Choose a reason for hiding this comment

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

Yes this will default to the local platform it is running on.

There is no difference to local builds. They work as-is like previously


ARG TARGETOS TARGETARCH
Copy link
Collaborator

Choose a reason for hiding this comment

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

These variables are not set anywhere. What are their default values? Are these specific to Docker? Can we remove them?

Copy link
Author

@lwj5 lwj5 Jul 22, 2024

Choose a reason for hiding this comment

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

These arg are auto populated if not specified. They default to the local platform.

https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope

They are required for the multi arch build used in the go build line


WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -18,7 +20,7 @@ COPY version/ version/

# Build
ARG LD_FLAGS
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="$LD_FLAGS" -a -o manager cmd/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="$LD_FLAGS" -a -o manager cmd/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down