Repository navigation
Description
Summary:
Multiple Canonical/Ubuntu resources refer to minimal image sizes while comparing to Google distroless image size.
- There are no equivalent images presently published for use?
- Proper recreation requires more effort and technical confidence from the user. More verbose and fragile than some published rocks?
- No package/slice that could simplify creation? (along with an official
chiselimage published)
Are these intentionally not published for some reason? Or are there plans to simplify producing such?
In this Jan 2023 guide (prior to the Nov 2023 General Availability announcement), the first step is to build chisel. The 2nd step was then to use chisel to create a minimal image like the Google distroless ones offer.
This page shows some comparisions to promote chisel, comparing to published rocks that are available on DockerHub for services and language runtimes, but this last one about a minimal equivalent image suitable for Go and Rust projects is nowhere to be found:
Images from online resources
The benefits of that minimal base are shown above, and it's useful for projects that just need to have basic deps like glibc with /etc/passwd + /etc/group, and ca-certificates, possibly TZ data.
I don't recall from the various resources I came across, any explanation for why chiseled images are produced for some services and language runtimes, but not these minimal glibc / distroless base image referenced above?
The project README does seem to suggest getting chisel and demonstrating an example which is simple enough. But I'd assume that's not too different for the published images? (like this using this Python3.12 slice)
Recreating the Python rock with chisel
I think the Python image might look something like this?:
# `chisel` lacks the ability to create the `--root` dir for you when it doesn't exist:
mkdir /rootfs
# Produces 40MB output:
# - `ubuntu/python:3.12-24.04_stable` image appears to roughly match contents of these slices, but is 48MB in size.
# - Missing `pebble` binary (8MB) and the `/etc/{passwd,group,localtime}` files.
chisel cut --release ubuntu-24.04 --root /rootfs \
python3.12_standard \
tzdata_zoneinfo \
ca-certificates_data-with-certs \
openssl_config \
base-files_baseEDIT: I found the actual rockcraft.yaml used to build ubuntu/python:3.12-24.04_stable (it'd be nice if the DockerHub image README referenced that btw! I wasn't sure where or what the build source was for a while until I learned more about "rocks"). It seems I was reasonably close at guessing it's internals 😎 (this will be easier to derive once that manifest feature arrives I assume)
- While I didn't explicitly provide
lib6_libsorlibgcc_s-1like therockcraft.yamlhas explicitly, those are brought in from the dependency chain, similar to how therockcraft.yamlbrings intzdata_zoneinfofrom an implicit python dep. - Although the
rockcraft.yamlwas last modified Aug 7 where it's slice forca-certificates_datawas reverted upstream on Aug 12 to what wasca-certificates_data-with-certs. Thus building that rock at present will not match the current published image, and that's why I assumedca-certificates_data-with-certsbased on the content (no clue if the Python rock image actually requires the extra data from that slice).




Activity
polarathene commentedon Sep 6, 2024
Side-by-side comparison
The promotional images that compare chiselled Ubuntu images to the Google distroless images do vary in size comparisons. Out of curiosity I have compared (
docker image lsoutput):With
chiselthey're mostly the same:The slight size advantage with
chiselis from sometzdataslice omission (mostly/usr/share/zoneinfo/right) and other/usr/sharecontent (NOTE:chiselimages are missing thelocaltimefor the symlink there, but similar to some other files in/etcwith containers I think that's fine and they get injected or mounted at runtime?):I think the promotional material was not exactly doing a 1:1 parity comparison, but perhaps trying to show off the extra flexibility
chiseloffers by tailoring the deps a bit better for your individual project needs.gconvdependency for example is viable reduction, while some need to still haveglibcandlibgcc_s, and if verifying TLS certsca-certificates, or needing timezone awarenesstzdata, etc.chisel.Building
chiselequivalents of Google distroless image variantsHere's the rough equivalent representation of each images content as they're iterative by appending new layers, I've ordered the slices to match the order they appear in the image layers for context:
NOTES:
openssl_configslice, but that would not providelibssl.so.3where the slice/package changes for Ubuntu 24.04, a low-level change that users interested in such a minimal base image shouldn't really have to think about?essentials, but I haven't yet looked into if supplying your own additional slices is simple. Not that chisel needs to necessarily offer 1:1 parity of the variants, it can be useful as a reference (as per reasoning of the linked distroless docs).As a
Dockerfile:docker build --build-arg IMAGE_VARIANT=cc --tag local/chisel:cc .polarathene commentedon Sep 6, 2024
Producing these types of low-level images is more verbose and requires extra effort vs the published ones for language runtimes or services. Would be nice to simplify that.
chiselcould encourage broader adoption by offering these images too, as it better enables adoption for projects/users with this common use-case to try. Positive experiences can lead to further exploring thechiselecosystem (with related projects like pebble and rockcraft).chiselto DockerHub reduces some friction / redundancy? It wasn't immediately clear if runningchiselrequired an Ubuntu base image to operate, but it does not 👍 (it does require/etc/ssl/certs/ca-certificates.crtto exist, and this does prevent writing to--root /on ascratchbase in aDockerfile, requiring aCOPY)Feature Request:
chiselas an official imageIdeal workflow might be:
docker build --platform linux/amd64,linux/arm64 --tag local/chisel-distroless:cc-24.04 .canonical/chiselor similar image published to registries such as DockerHub./root-fswhen it doesn't exist 🙏chiselby keeping such maintenance upstream (such as with thelibssl3->libssl3t64package change).$BUILDPLATFORMwill pull/use the image for that build hosts native arch, while$TARGETARCHis used to support multiple archs (arm64+amd64). Faster as non-native archs don't go through emulation overhead. I haven't checked how well that works with concurrent builds, shared cache may be an issue, in which case adjusting theidto use$TARGETARCHto have a separate cache mount per arch would perhaps work? Cache was near 100MB for each AMD64 + ARM64 targets.Compared to the currently required manual approach
This is currently much noisier, adds technical knowledge/debt, and less friendly for project maintainers to accept.
Both producing the rough equivalent of
FROM gcr.io/distroless/cc.RUN, and the cache mounts.gcr.io/distroless/cc. Evengcr.io/distroless/staticor variants in-between would look more attractive unless the benefits like flexibility can be leveraged without the maintainer feeling it adds too much complexity.The proposed "ideal" version would still work well enough, and could avoid the cache mount + arch/platform specific optimization.
Variant -
FROM scratchwithout theCOPYstepchiselimage that provideschiseland if needed a relativeca-certificates.crt(or CLI option to reference one at a different location).--ignoreor similar option as a way to workaround the conflict detection when using--root /./canonicalwouldn't actually conflict with the installed content and the mount will be removed after theRUN. Better if it could be handled implicitly, but presently the issue seems to be with external dependency on/etc/ssl/certs/ca-certificates.crt?Not sure how useful that is in practice 🤷♂️
letFunny commentedon Nov 1, 2024
@polarathene Thanks for your comments here, it was very insightful. Apologies for taking this long but I was going through them now and I see a couple of different ideas that would be good additions for Chisel:
We'll need to study all of them separately because they all require different levels of effort. I can tell you that for sure we are going to devote time during the next months to improve the UX and vastly revamp the user documentation, which can include some of your suggestions. Presently we are working on improving the UX for slice creation, so the items that we choose to pursue from the above might take some extra time.
Lastly, pull requests are welcomed, especially for simple improvements that do not require a lot of discussion.
polarathene commentedon Nov 1, 2024
I did put together a slice definition for these a while back, but ran into an issue where I couldn't use
ccas a slice name, two characters was too short. I opened an issue for that, but that has not yet been resolved.If you'd like I can open a PR, it was about 2 months ago but I had this:
slices/base-distroless.yaml: (24.04)I'm not sure if it makes sense to match Google Distroless with those names, or to have them as an alias for names that would be more fitting to chisel?
With that SDF one can more easily use chisel to get the equivalent Google Distroless image and add whatever other slices are needed, throw in Pebble for the entrypoint if multiple services in an image are required, etc.
I think the lack of that SDF being available is the bigger friction point to resolve right now for adopting chisel for base images since I can't easily get maintainers of projects onboard when they're presented a Dockerfile with a large list of slices to maintain which presents as more complexity vs alternatives 😓
letFunny commentedon Nov 5, 2024
I think the distroless slice is the most controversial one here :), apologies for not saying that earlier. Right now slices are functional units of a package and this will be deviating a bit from that, plus I am not sure we want to track the concept of google distroless this way. I think a better solution would involve the other part of your comment about
[...] these base images won't be published separatelywhich seems like a better way forward. But as I say above we need to discuss it internally first, once we have landed the features we are working on right now. Thanks again for your comments!