Skip to content

Enhance GitHub Actions workflow for multi-platform builds.#286

Merged
nunnatsa merged 1 commit intokubevirt:mainfrom
ashokpariya0:enable-s390x-support
Apr 29, 2025
Merged

Enhance GitHub Actions workflow for multi-platform builds.#286
nunnatsa merged 1 commit intokubevirt:mainfrom
ashokpariya0:enable-s390x-support

Conversation

@ashokpariya0
Copy link
Member

These changes enable building and pushing Docker images for multiple platforms (amd64, arm64, s390x).

What this PR does / why we need it:

As of now, only x86 support is available for the prom-metrics-linter image: https://quay.io/repository/kubevirt/prom-metrics-linter?tab=tags&tag=latest.

This PR introduces changes to enable multi-architecture builds for arm64 and s390x, in addition to x86, using GitHub Actions.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes # #285

Special notes for your reviewer:

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

Release note:

None

@kubevirt-bot kubevirt-bot added the dco-signoff: yes Indicates the PR's author has DCO signed all their commits. label Apr 8, 2025
@ashokpariya0
Copy link
Member Author

Hi @machadovilaca @sradco Could you please review this PR whenever possible??

@sradco
Copy link
Collaborator

sradco commented Apr 28, 2025

@avlitman @nunnatsa please review this pr.

Comment on lines +4 to +5
ENV TARGETOS=${TARGETOS:-linux}
ENV TARGETARCH=${TARGETARCH:-amd64}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not needed, for two reasons: the env vars are for the final image, and this is the builder, and also, these ARGs are always set by the CRI.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added this for standard single-platform builds (in case we want to build without Buildx) so that we can use the same Dockerfile for both multi-platform builds with Docker Buildx and standard single-platform builds.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It will work without the ENVs in local build. docker/podman will set the TARGEARCH, TARGETOS and TARGETPLATFORMbuild ARGs to the right values. e.g. if you don't mention the --platform - it will be the value of the local platform, and if you do specify the platform, podman/docker will use it to populate these args.

But even without it, the ENVs are only used for the final image, for a running container. ARGs are like build-time env vars. There is no point to set the ENV

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay thanks, removed that.
Change


RUN go mod tidy && \
CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" -o /bin/ .
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -v -trimpath -ldflags "-s -w" -o /bin/ .
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need the default value for the TARGETOS, assuming it's always set.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, Removed.

These changes enable building and pushing Docker images for
multiple platforms (amd64, arm64, s390x).

Signed-off-by: Ashok Pariya <ashok.pariya@ibm.com>
@ashokpariya0 ashokpariya0 force-pushed the enable-s390x-support branch from 102a48c to 3a51cc9 Compare April 29, 2025 04:59
Comment on lines +10 to +12
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -v -trimpath -ldflags "-s -w" -o /bin/ .

FROM gcr.io/distroless/base:latest
FROM --platform=linux/${TARGETARCH} gcr.io/distroless/base:latest
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Thinking about it again, we can do even better. in line 10, we use the TARGETOS parameter, while in line 12 we're using hard coded value of "linux". WDYT about do the same in both case?

either

CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -v -trimpath -ldflags "-s -w" -o /bin/ .

FROM --platform=linux/${TARGETARCH} gcr.io/distroless/base:latest

or

CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -v -trimpath -ldflags "-s -w" -o /bin/ .

FROM --platform=${TARGETPLATFORM} gcr.io/distroless/base:latest

(TARGETPLATFORM = ${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.

If you want to do it, let's do it in a follow PR.

/lgtm

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I had considered this earlier. Since cross-compilation for platforms like s390x is only available for Linux, I kept it as linux in the configuration.

The current BUILD_PLATFORMS is set to:

linux/amd64,linux/arm64,linux/s390x

That being said, I’ve opened a PR for symmetry: PR #289.

@nunnatsa
Copy link
Collaborator

/lgtm
/approve

@nunnatsa nunnatsa merged commit 5dd61c2 into kubevirt:main Apr 29, 2025
2 checks passed
github-actions bot pushed a commit that referenced this pull request Apr 29, 2025
…0x-support

Enhance GitHub Actions workflow for multi-platform builds.
github-actions bot pushed a commit to ashokpariya0/monitoring that referenced this pull request Apr 29, 2025
…able-s390x-support

Enhance GitHub Actions workflow for multi-platform builds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has DCO signed all their commits. size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants