-
Notifications
You must be signed in to change notification settings - Fork 9
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
ci: Enable building for s390x and arm64 #73
Conversation
Once all the comments are ref please let me know and i will review |
Change the Dockerfile to support fast multi-arch builds using cross-compilation. Do not hardcode the target arch as amd64. Signed-off-by: Jan Schintag <[email protected]>
Signed-off-by: Jan Schintag <[email protected]>
The ci outputs a warning since both FROM and AS keywords should be all uppercase. Signed-off-by: Jan Schintag <[email protected]>
Add support for installing golang on arm64 and s390x. Signed-off-by: Jan Schintag <[email protected]>
eed4043
to
d03ce8e
Compare
@oshoval I have addressed the comments and added the changes from #74 to this PR, as requested in #74 (comment) |
.github/workflows/image-push.yaml
Outdated
@@ -41,6 +41,7 @@ jobs: | |||
uses: docker/build-push-action@v2 | |||
with: | |||
context: . | |||
platforms: linux/amd64,linux/s390x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to add arm please ? (as you added on install go script)
(assuming git actions support arm cross compile)
if you prefer it can wait for follow-ups, unless it is straight forward
(according other PRs i saw, it seems straight forward and supported)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure i can add it. I just haven't tested it, so if it works or not i can't say.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added it as a separate commit so it is easier to revert should it not work out.
Signed-off-by: Jan Schintag <[email protected]>
@@ -13,8 +13,10 @@ RUN go mod download | |||
COPY main.go main.go | |||
COPY pkg/ pkg/ | |||
|
|||
ARG TARGETARCH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont we need something like this ?
https://github.com/kubevirt/bridge-marker/pull/77/files#diff-5aecd73bbcb9b7410938673269f0d4e676dd18509277b0ff2f2787c9d3e22604R3-R11
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, we only need TARGETARCH
and ARG
already sets it as an enviroment variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
@ashokpariya0 does it mean maybe that the logic on bridge-marker or whatever projects that done the same as it can be simplified maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oshoval No, it's important to handle default cases. The combination of ARG
and ENV
is beneficial because it allows you to manage both build-time and runtime configurations more flexibly and efficiently.
case $arch in | ||
x86_64 | amd64) | ||
arch="amd64" | ||
;; | ||
aarch64 | arm64) | ||
arch="arm64" | ||
;; | ||
s390x) | ||
arch="s390x" | ||
;; | ||
*) | ||
echo "ERROR: invalid arch=${arch}, only support x86_64, aarch64 and s390x" | ||
exit 1 | ||
;; | ||
esac |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we modify it like below? Instead of restricting the architecture to only support x86_64, aarch64, and s390x, it would be helpful to allow building for other architectures, such as ppc64le, using the make command.
arch=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets see please if we do need it imo, because there wasnt an item to support ppc and i prefer to not do just parts unless needed
on the other hand, the suggestion is indeed more compact and robust, so it will be fine to adapt this
but the rest shouldn't be adapted yet
thanks
EDIT - for more context
kubevirt/bridge-marker#77 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually prefer the more verbose version, since it is more easy to read later on and to see what is intended to work.
My proposal would be i keep the switch-case, but change the default to a warning instead of an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i do understand it is more verbose, but it is good to be in the same format on the repos we maintain
anyhow i wont insist, we can change later according needs,
(i also tend to like compactness personally)
we do need to error imo if one supplied unsupported version in case we keep it this way
Thanks
/lgtm Thanks, |
/lgtm cancel we need another reviewer |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: oshoval The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@0xFelix |
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you verify this by running it against a test registry?
# Build | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH="${TARGETARCH}" go build -a -o manager main.go | ||
|
||
FROM registry.access.redhat.com/ubi8/ubi-minimal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which image is pulled here? Do the resulting image arch and the BUILDPLATFORM match?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested the whole workflow on my own fork against ghcr.io.
The BUILDPLATFORM means that the first stage is run natively, e.g. on amd64, while the TARGETARCH may be s390x.
The 2nd stage is not affected, so if you target s390x, you compile the s390x binary on amd64 via cross-compile but still get a s390x image in the 2nd stage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you set --platform
in the first stage, it will be used for the second stage as well. Is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.docker.com/build/building/multi-platform/#cross-compilation
Nevermind, I see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we need to update the following:
FROM registry.access.redhat.com/ubi8/ubi-minimal
to:
FROM --platform=linux/${TARGETARCH} registry.access.redhat.com/ubi8/ubi-minimal
This is necessary because FROM registry.access.redhat.com/ubi8/ubi-minimal works fine with docker buildx, but it fails with podman when building for multiple platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am not familiar about it by heart tbh
maybe lets wait please from ideas from the people involved
curious, iiuc it works without it on all the required combinations ?
native and s390x (cross / native) are most important, on podman (because this what CNV suggests)
to see it builds and runs on those combinations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested native with docker/podman by running make build
on s390x. Let me test it on x86 as well just to be sure, though there should not be a difference. Cross as i said seemed to not work for me with OCI: podman, host: s390x, target: amd64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Native amd64 -> amd64 works as well with docker/podman.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
host: s390x, target: amd64
we can fix this one later specifically according needs, because atm native host/target amd64 works which is what important in this aspect
host: amd64, target: s390x - does work ? (podman / docker, higher priority for podman)
maybe the PRs of @ashokpariya0 might help in this, if it works there
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The combination of host: s390x and target: amd64 is not supported, so there is no need to test this configuration.
As @oshoval pointed out we need to test following:
Host: amd64
Target: amd64, arm64, and s390x.
Also For the final stage of the build, better to use the following:
FROM --platform=linux/${TARGETARCH} registry.access.redhat.com/ubi8/ubi-minimal
This approach is necessary when building multi-platform images using Podman. You will need to create a Podman manifest and then add the individual platform-specific builds one by one to the manifest. Also adding (linux/${TARGETARCH}) works well with docker buildx.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
once we are good to create a release please let me know |
@oshoval I have created #78 to address the issue with podman cross-build on amd64. Once that is merged, from my side that should be everything we need for a release of kubesecondarydns. @ashokpariya0 WDYT? |
@jschintag yes sounds good. |
Created |
What this PR does / why we need it:
This PR enables building kubesecondarydns for s390x in addition to amd64.
Additionally arm64 is enabled as well, though i can't test it to verify it works.
Additionally it bumps the workflow action versions to their latest to get rid of multiple deprecation warnings.
Finally it fixes a small warning about the case of "AS" in the Dockerfile.
Special notes for your reviewer:
PRs to enable unit-tests and build test for s390x will follow. E2E needs the provider, which for s390x still has some problems to be worked out.