Find slices easily with the new `chisel find` command!

Chisel is great at helping you generate a very minimal rootfs with only your application and it’s dependencies! All you need to do is find the necessary slices and voila, Chisel does the rest.

But, finding the slices hasn’t been great so far. You have to go to the chisel-releases repository, choose the branch you want your slices for, go to the slices directory and finally look for the package you need. Pretty tiresome for someone lazy like me. Well, that was until now.

Chisel v0.10.0 was released a while ago, and with it, comes the new find command! The find command helps you search for slices with ease, across releases.

* AI-generated image. “Penguin looking for slices with binoculars”.

Usage

$ chisel find -h
Usage:
  chisel find [find-OPTIONS] [<query>...]

The find command queries the slice definitions for matching slices.
Globs (* and ?) are allowed in the query.

By default it fetches the slices for the same Ubuntu version as the
current host, unless the --release flag is used.

[find command options]
      --release=<branch|dir>      Chisel release name or directory (e.g. ubuntu-22.04)

Basic usage

Say you are looking for python3.10 slices for ubuntu-22.04. You can do the following:

$ chisel find python3.10
2024/07/04 17:29:32 Consulting release repository...
2024/07/04 17:29:33 Cached ubuntu-22.04 release is still up-to-date.
2024/07/04 17:29:33 Processing ubuntu-22.04 release...
Slice                 Summary
python3.10_copyright  -
python3.10_core       -
python3.10_standard   -
python3.10_utils      -
python3.11_copyright  -
python3.11_core       -
python3.11_standard   -
python3.11_utils      -

And you will have a list of python3.10 slices. Notice that there are some python3.11 slices as well. This is because the find command finds partially-matched slices with Levenshtein Distance of up to 1.

The first three lines are logs, which you can ignore with:

$ chisel find python3.10 2> logs

Search across releases with --release

Notice how I haven’t provided the --release option to the find command. When the --release option is not provided, chisel will try to deduce the release to search for based on the host system Chisel is running on. You can, however, search for slices in other releases too.

Say you want to look for python3.10 slices for Ubuntu 24.04. Just do this:

$ chisel find --release ubuntu-24.04 python3.10 2> logs
Slice                 Summary
python3.12_copyright  -
python3.12_core       -
python3.12_standard   -
python3.12_utils      -

Unfortunately, there are no python3.10 slices for 24.04 (Contribute?). But, it does have python3.12 slices as listed above.

An in-depth view of how the find command works

The command takes in a list of query terms. For each term, it finds the matching slices. However, it only outputs the slices which matches each query. For example, if you run chisel find query1 query2, Chisel will list only the slices who matches with query1 and query2.

Additonally, for matching slices against a query term, the find command has a conditional logic.

  1. If the term does not have any underscore(_), it will match against package names only. As shown above, chisel find foo will search for packages whose name matches with foo and list all of their slices.

  2. If the term starts with an underscore(_), then Chisel will list all the slices whose slice name matches with the rest of the query. Note here that, for a slice python3.12_core, python3.12 is the package name and core is the slice name (short name). Thus, if you were to run chisel find _foo, you will get a list of slices whose slice names match with foo. Examples below in latter sections.

  3. If the term does not start with an underscore(_) but contains one, then only those slices are listed whose full slice name (pkg_slice) match with the query term.

Find slices across packages

If you want to know how many bins slices are there, you can run the following:

$ chisel find _bins 2> logs
Slice                    Summary
base-files_bin           -
bash_bins                -
busybox_bins             -
coreutils_bins           -
curl_bins                -
dash_bins                -
dotnet-host_bins         -
findutils_bins           -
gawk_bins                -
grep_bins                -
hello_bins               -
openssl_bins             -
p11-kit_bins             -
python3.10-minimal_bins  -
python3.11-minimal_bins  -

This illustrates the behaviour mentioned in the above list at number 2.

Find a particular slice

To look for a particular slice you have in mind, search with it’s full name:

$ chisel find libc6_libs 2> logs
Slice       Summary
libc6_libs  -

Wildcards!

The find command supports wildcards (*, ?).

  • * matches any zero or more character including _.
  • ? matches zero or one character including _.

Let’s say we want to know about all the dotnet slices. We can run the following:

$ chisel find dotnet* 2> logs
Slice                         Summary
dotnet-host_bins              -
dotnet-host_copyright         -
dotnet-hostfxr-6.0_copyright  -
dotnet-hostfxr-6.0_libs       -
dotnet-runtime-6.0_copyright  -
dotnet-runtime-6.0_libs       -

Well, maybe we only care about the bins and libs slice from above. While we can’t really unleash the magic of regexp here, but the following does the trick:

$ chisel find dotnet* _?i?s 2> logs
Slice                    Summary
dotnet-host_bins         -
dotnet-hostfxr-6.0_libs  -
dotnet-runtime-6.0_libs  -

Notice how I used two query terms above.

Conclusion

The find command should come in very handy to look up a slice you want to use. If there are any suggestions, or if you find a cool way to search for slices with wildcards, multiple terms etc., please leave a comment. I would be very happy to know!

2 Likes