feat(build): enhance container build times#438
feat(build): enhance container build times#438k8s-ci-robot merged 1 commit intokubernetes-retired:mainfrom hargut:feat/develop-container-images
Conversation
|
Further details can be found within the commit message. This was a rabbit hole and in terms of understandability, simplicity and speed I would prefer a cargo build followed by a container build that just copies the resulting artefacts and checks if the linking matches with what is provided by the container. |
There was a problem hiding this comment.
So in this approach we mount the host system's target/ directory into the container and build inside of the container, emitting the cache to the host.
I get that this can improve build times in general and help with iteration, so I'm still open to it. However I also see it as adding a lot of ceremony to replicate what we have in the Makefile already to build locally, inside the container. 🤔
Question for you: couldn't we get a lot of the same value with much less code if we just chain a make build.all onto the front of a make build.image, and then mount the volume?
I suppose there are potential downsides, including control of the build toolchain inside of the container, but at least that one might be easy enough to deal with by introducing a rust-toolchain.toml. In any case though, I'm curious as to your thoughts 🤔
I think it would be helpful to understand if it is crucial to have everything in one Containerfile, or if there could be a dedicated one for develop use. In terms of simplicity, understandability and speed there will not be anything faster than copying the already built binary into an empty container image. No fancy setup required, potentially just a make flag. No worries about file permissions, id mappings, features of various container runtimes. Within CI the fully blown in-container build for release builds could be built for integration tests. |
|
My idea was to keep the build environment isolated as it was in the existing build. Only copy over the source files and have a clearly defined build.
I do think that there is not a lot of difference in terms of timing between "build, THEN mount" or "mount, THEN build". As the containers are built sequentially, the second container will reuse the build results from the first. To check the results on that I'll push a commit that rebuilds With the container build the layers will as well be reused (as they are identical in the first lines), the first layer being built for the Where I do do see the most potential in terms of overall used resources is to combine the |
|
I think it would be important to clarify what is important and to optimize for that. Currently it is not clear for me what the goals are to aim for. Isolated build within a defined container environment? To enhance developer experience for me a goal is to reduce build and deployment time on a local environment. |
In the CI it is currently setup like this, but it would as well work to build first locally and then reuse the results in the container build. The other direction is right now not fully covered with the
Wouldn't that be nearly equivalent to to just copying the final binaries into the container image? Please let's try to avoid building a time-grave within this topic. It was intended to speed-up things and not to burry hours into the change. Build times are already approx. down to half on a fresh build with the current proposal. |
building and reusing rustc artifacts from container and host
optimized for build speed during development
unfortunately this is a rabbit hole:
- docker buildx does not support volumes during build
- using a build context is an IO heavy and slow operation when target/ is populated
- used podman to mount & build the images
- podman (4.9.x) on github actions within ubuntu-24.04 has issues on the uid/gid maps
with --userns=host
- uid/gid maps work as expected on podman 5.5.2
- kind support for loading images from podman is broken
- kubernetes-sigs/kind#3945
- to reuse cargo compiled artifacts between host and container
- the paths for the sources need to match
- the paths for the toolchains need to match
Signed-off-by: Harald Gutmann <harald@gutmann.one>
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hargut, shaneutt The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This draft pr is intended to further discussing #424. It only comprises the build for controlplane and provides a draft layout that could be enrolled to other containers.
fixes: #424