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

🌱 Cross-compile container image binaries from host platform #2551

Merged

Conversation

astefanutti
Copy link
Member

@astefanutti astefanutti commented Jan 5, 2023

Summary

The compilation of the binaries in the builder stage of the container image is very slow when QEMU is used:

#44 [linux/amd64 builder 11/11] RUN --mount=type=cache,target=/root/.cache/go-build     --mount=type=cache,target=/go/pkg/mod     make
#44 881.5 ln -sf kubectl-workspace bin/kubectl-workspaces
#44 881.5 ln -sf kubectl-workspace bin/kubectl-ws
#44 DONE 882.2s

#49 [linux/arm64 builder 11/11] RUN --mount=type=cache,target=/root/.cache/go-build     --mount=type=cache,target=/go/pkg/mod     make
#49 5526.2 ln -sf kubectl-workspace bin/kubectl-workspaces
#49 5526.3 ln -sf kubectl-workspace bin/kubectl-ws
#49 DONE 5527.0s

#50 [linux/ppc64le builder 11/11] RUN --mount=type=cache,target=/root/.cache/go-build     --mount=type=cache,target=/go/pkg/mod     make
#50 5266.1 ln -sf kubectl-workspace bin/kubectl-workspaces
#50 5266.4 ln -sf kubectl-workspace bin/kubectl-ws
#50 DONE 5266.9s

This PR switches to using Golang cross-compilation instead of QEMU, by forcing the builder stage to run the same platform as that of the host one, that gives:

#27 [linux/amd64 builder 11/11] RUN --mount=type=cache,target=/root/.cache/go-build     --mount=type=cache,target=/go/pkg/mod     make OS=linux ARCH=amd64
#27 963.1 ln -sf kubectl-workspace bin/kubectl-workspaces
#27 963.2 ln -sf kubectl-workspace bin/kubectl-ws
#27 DONE 963.8s

#28 [linux/amd64->arm64 builder 11/11] RUN --mount=type=cache,target=/root/.cache/go-build     --mount=type=cache,target=/go/pkg/mod     make OS=linux ARCH=arm64
#28 987.2 ln -sf kubectl-workspace bin/kubectl-workspaces
#28 987.3 ln -sf kubectl-workspace bin/kubectl-ws
#28 DONE 989.2s

#26 [linux/amd64->ppc64le builder 11/11] RUN --mount=type=cache,target=/root/.cache/go-build     --mount=type=cache,target=/go/pkg/mod     make OS=linux ARCH=ppc64le
#26 991.1 ln -sf kubectl-workspace bin/kubectl-workspaces
#26 991.1 ln -sf kubectl-workspace bin/kubectl-ws
#26 DONE 991.1s

It also triggers the image build workflow on pull requests, so non-regression of the container image build is covered, though the result image is not pushed to any registry.

@openshift-ci openshift-ci bot requested review from stevekuznetsov and sttts January 5, 2023 08:51
@astefanutti astefanutti force-pushed the pr-cross-compile-image branch from b568979 to 287a0f7 Compare January 5, 2023 09:12
@astefanutti astefanutti closed this Jan 5, 2023
@astefanutti astefanutti reopened this Jan 5, 2023
@sttts
Copy link
Member

sttts commented Jan 5, 2023

/retest

pull_request:
branches:
- main
- 'release-*'
Copy link
Member

Choose a reason for hiding this comment

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

is this just for testing?

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'd be inclined to keep it, so as to guarantee PRs do not break the image build for some reasons. In that case, the image is only built, not pushed, which I think is what we want for PRs:

push: ${{ github.event_name != 'pull_request' }}

Copy link
Member

Choose a reason for hiding this comment

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

With 21min it is much faster now. So I am less concerned this blocks our github action queue.

@sttts
Copy link
Member

sttts commented Jan 5, 2023

Nice improvement.

@sttts
Copy link
Member

sttts commented Jan 5, 2023

/retest
/lgtm
/approve

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 5, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 5, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sttts

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 5, 2023
@ncdc
Copy link
Member

ncdc commented Jan 5, 2023

Flake #2501

@openshift-merge-robot openshift-merge-robot merged commit 84bc33e into kcp-dev:main Jan 5, 2023
@astefanutti astefanutti deleted the pr-cross-compile-image branch January 5, 2023 16:55
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. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants