Enhance GitHub Actions workflow for multi-platform builds.#286
Enhance GitHub Actions workflow for multi-platform builds.#286nunnatsa merged 1 commit intokubevirt:mainfrom
Conversation
|
Hi @machadovilaca @sradco Could you please review this PR whenever possible?? |
| ENV TARGETOS=${TARGETOS:-linux} | ||
| ENV TARGETARCH=${TARGETARCH:-amd64} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
|
||
| 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/ . |
There was a problem hiding this comment.
I don't think we need the default value for the TARGETOS, assuming it's always set.
These changes enable building and pushing Docker images for multiple platforms (amd64, arm64, s390x). Signed-off-by: Ashok Pariya <ashok.pariya@ibm.com>
102a48c to
3a51cc9
Compare
| 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 |
There was a problem hiding this comment.
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})
There was a problem hiding this comment.
If you want to do it, let's do it in a follow PR.
/lgtm
There was a problem hiding this comment.
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.
|
/lgtm |
…0x-support Enhance GitHub Actions workflow for multi-platform builds.
…able-s390x-support Enhance GitHub Actions workflow for multi-platform builds.
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: