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

Minified, multi-architectural container images #1644

Closed
jennydaman opened this issue Dec 26, 2023 · 10 comments · Fixed by #1647
Closed

Minified, multi-architectural container images #1644

jennydaman opened this issue Dec 26, 2023 · 10 comments · Fixed by #1647
Labels
enhancement Enhancements under development - feel free to join discussion if you'd like to contribute

Comments

@jennydaman
Copy link
Contributor

Is your feature request related to a problem?

We are interested in using N4BiasFieldCorrection as part of our pipelines and run it in containers on PowerPC.

Proposed new features

A) In Dockerfile, by installing cmake using apt instead of directly from Kitware's website, we can build multi-architectural images using docker buildx. See here:

https://github.com/FNNDSC/ANTs/blob/04c2938830f6c1233bde9c4784ad2f58d6a8f058/Dockerfile

I intend to make a PR after figuring out a good solution to #1069

B) Small (<60MB) images can be produced by creating individual images for each ANTs program. See

https://github.com/FNNDSC/microANTs

Using this script, I created a multi-architectural image for N4BiasFieldCorrection on DockerHub: https://hub.docker.com/layers/fnndsc/n4biasfieldcorrection/2.5.0/images/sha256-7e4da5a9f606aa170ae8d1187a6de915f5a1d03ca2dd7e773fc24c411c2227ab?context=explore (the ppc64le one doesn't work yet, as aforementioned)

If there is more interest in the community, I can use a GitHub Actions matrix to automatically build these minified images for all ANTs programs. I would also like to know whether the ANTsX team is interested in hosting these images and CI infrastructure in their own official namespace.

Alternatives you've considered

docker buildx is a very inefficient solution because it uses QEMU emulation. Cross-compilation would be a much more efficient solution, however it would require in-depth knowledge of the Cmake configurations of ANTs which I lack.

Alternatively, it would also be even better if the ants package in conda-forge was cross-compiled for linux-aarch64 and linux-ppc64le.

Additional context

@cookpa
Copy link
Member

cookpa commented Dec 29, 2023

Hi,

A few thoughts:

ANTsPy has moved to using a conda cmake install for cross-platform compatibility, and it probably would be good to have ANTs do the same.

I'm not sure about the use case for the mini ANTs images. What does having a separate image for each program do? Would it make sense to just have one static build per platform, so people could copy the program(s) they want in their Dockerfile?

Cross-platform builds would be awesome. QEMU takes too long for Github Actions, so this would be a good alternative. But I don't have an arm64 machine to work on.

Regarding conda forge, you'd have to reach out to the developers of that package, we don't maintain that directly - though we've collaborated on updating ANTs to help facilitate conda builds and are happy to discuss further here.

@jennydaman
Copy link
Contributor Author

jennydaman commented Jan 5, 2024

Yeah, I was the one who sent the ANTsPy PR those years ago.

We're interested in using N4BiasFieldCorrection in "pipelines" which run on Kubernetes, i.e. run a sequence of containers to process a dataset on a cluster of computers. Small image sizes can greatly decrease cold boot time. Since N4BiasFieldCorrection might run on any number of the nodes in our cluster, the image needs to be pulled quite often.

@cookpa
Copy link
Member

cookpa commented Jan 5, 2024

Right, the apt conda install was better than the hard-coded kitware download, but it eventually ran into problems when we had to update the CMake version. Another user suggested using conda to install it, which has worked well since then. So I was thinking to copy the same procedure (#1646)

@jennydaman
Copy link
Contributor Author

@cookpa sure! I actually have a branch for that already: https://github.com/FNNDSC/ANTs/blob/multiarch-dockerfile/Dockerfile

Do you want a PR?

@jennydaman
Copy link
Contributor Author

Comparing the Dockerfile I wrote to #1646, I am using micromamba which is a C++ reimplementation of conda. Also, I am using cache mounts to improve speed and minimize the image size. You can try

docker pull docker.io/fnndsc/ants:2.5.0-micromamba

@cookpa
Copy link
Member

cookpa commented Jan 5, 2024

This looks interesting, but I'm inclined to keep things simple for ANTs, I like your Dockerfile here

https://github.com/FNNDSC/ANTs/blob/04c2938830f6c1233bde9c4784ad2f58d6a8f058/Dockerfile

Using Debian and shorter than the existing one. Could you make a PR for that?

I was also thinking of making the shared libs option a build arg - then one could build statically, and then copy a program like N4BiasFieldCorrection into a micro distribution. The executable would be larger but I think on balance it would be smaller than copying the shared-lib executable and all of its shared libraries. Unless this wouldn't work for some reason I'm missing

@jennydaman
Copy link
Contributor Author

I did a force-push to amend the commit message to follow the convention.

@jennydaman
Copy link
Contributor Author

Also, static builds would be very helpful! (I lack the cmake expertise to do it myself)

@cookpa cookpa added the enhancement Enhancements under development - feel free to join discussion if you'd like to contribute label Jan 9, 2024
@cookpa
Copy link
Member

cookpa commented Jan 24, 2024

Hi @jennydaman , I made a few changes in #1665, among them adding a build arg for BUILD_SHARED_LIBS, set this to OFF and it will build static libraries and executables.

After building a static image with all the tools, I was then able to copy individual executables (no need to bring the libraries) into a debian:bookworm-slim base image, and then run them directly.

Thanks again for your help with the Dockerfile

@jennydaman
Copy link
Contributor Author

I tried out BUILD_SHARED_LIBS=OFF and it works, many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancements under development - feel free to join discussion if you'd like to contribute
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants