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

ci: Enable building for s390x and arm64 #73

Merged
merged 5 commits into from
Dec 3, 2024

Conversation

jschintag
Copy link
Contributor

@jschintag jschintag commented Nov 29, 2024

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.

@kubevirt-bot kubevirt-bot added the dco-signoff: yes Indicates the PR's author has DCO signed all their commits. label Nov 29, 2024
Dockerfile Outdated Show resolved Hide resolved
@oshoval
Copy link
Collaborator

oshoval commented Dec 1, 2024

Once all the comments are ref please let me know and i will review
Thank you all for your contribution

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]>
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]>
@jschintag
Copy link
Contributor Author

@oshoval I have addressed the comments and added the changes from #74 to this PR, as requested in #74 (comment)

@@ -41,6 +41,7 @@ jobs:
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/s390x
Copy link
Collaborator

@oshoval oshoval Dec 2, 2024

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)

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@@ -13,8 +13,10 @@ RUN go mod download
COPY main.go main.go
COPY pkg/ pkg/

ARG TARGETARCH
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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.

Copy link
Collaborator

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?

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.

Comment on lines +8 to +22
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

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/')

Copy link
Collaborator

@oshoval oshoval Dec 3, 2024

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)

Copy link
Contributor Author

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.

Copy link
Collaborator

@oshoval oshoval Dec 3, 2024

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

@oshoval
Copy link
Collaborator

oshoval commented Dec 3, 2024

/lgtm

Thanks,
Please add arm support to PR desc

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 3, 2024
@oshoval
Copy link
Collaborator

oshoval commented Dec 3, 2024

/lgtm cancel
/approve

we need another reviewer

@kubevirt-bot kubevirt-bot removed the lgtm Indicates that a PR is ready to be merged. label Dec 3, 2024
@kubevirt-bot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 3, 2024
@oshoval
Copy link
Collaborator

oshoval commented Dec 3, 2024

@0xFelix
can you please take a look ?

@jschintag jschintag changed the title ci: Enable building for s390x ci: Enable building for s390x and arm64 Dec 3, 2024
@jschintag
Copy link
Contributor Author

Thanks, Please add arm support to PR desc

done

Copy link
Member

@0xFelix 0xFelix left a 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
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Collaborator

@oshoval oshoval Dec 5, 2024

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

Copy link
Collaborator

@oshoval oshoval Dec 5, 2024

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

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.

Copy link
Member

@0xFelix 0xFelix left a comment

Choose a reason for hiding this comment

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

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 3, 2024
@kubevirt-bot kubevirt-bot merged commit c2d9ba6 into kubevirt:main Dec 3, 2024
8 checks passed
@jschintag jschintag deleted the s390x-build branch December 3, 2024 14:44
@oshoval
Copy link
Collaborator

oshoval commented Dec 5, 2024

once we are good to create a release please let me know
thanks

@jschintag
Copy link
Contributor Author

@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?

@ashokpariya0
Copy link

@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.
@oshoval Looks good to me! Once #78 is merged, we should be all set for the release of kubesecondarydns.

@oshoval
Copy link
Collaborator

oshoval commented Dec 8, 2024

Created v0.0.16
https://github.com/kubevirt/kubesecondarydns/releases/tag/v0.0.16
Please check it works as expected if possible
Thanks all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants