images: slim OCI images of the swarm daemons from nix
This commit is contained in:
parent
ffbd2f4dea
commit
29ca381114
1 changed files with 218 additions and 6 deletions
|
|
@ -297,6 +297,50 @@ in
|
|||
shared = moduleEvalShared;
|
||||
};
|
||||
|
||||
# Builds `mkServiceImage` around `hello` and reads the tarball back, so the
|
||||
# function is tested without compiling a hyperhive binary. The two `grep -q`
|
||||
# arms for `hello` and `glibc` prove the layer listing finds store paths,
|
||||
# which keeps the "no bash, no systemd" arm from passing on an empty list.
|
||||
image-fn-smoke =
|
||||
let
|
||||
imageSet = import ./images {
|
||||
inherit pkgs;
|
||||
inherit (pkgs) lib;
|
||||
};
|
||||
inherit (imageSet) serviceUser;
|
||||
image = imageSet.mkServiceImage {
|
||||
name = "smoke";
|
||||
package = pkgs.hello;
|
||||
bin = "hello";
|
||||
};
|
||||
in
|
||||
pkgs.runCommand "image-fn-smoke" { nativeBuildInputs = [ pkgs.jq ]; } ''
|
||||
mkdir unpacked
|
||||
tar -xzf ${image} -C unpacked
|
||||
cd unpacked
|
||||
|
||||
config=$(jq -r '.[0].Config' manifest.json)
|
||||
test "$(jq -c '.config.Entrypoint' "$config")" = '["/bin/hello"]'
|
||||
test "$(jq -r '.config.User' "$config")" = '${toString serviceUser.uid}:${toString serviceUser.gid}'
|
||||
jq -e '.config.Env | index("SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt")' "$config" >/dev/null
|
||||
test "${image.imageName}" = hyperhive/smoke
|
||||
|
||||
for layer in $(jq -r '.[0].Layers[]' manifest.json); do
|
||||
tar -tf "$layer"
|
||||
done > paths
|
||||
grep -q -- '-hello-' paths
|
||||
grep -q -- '-glibc-' paths
|
||||
if grep -E -- '-(systemd|bash)-' paths; then
|
||||
echo "image carries a shell or systemd" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
size=$(stat -c %s ${image})
|
||||
test "$size" -lt 50000000
|
||||
|
||||
touch $out
|
||||
'';
|
||||
|
||||
# Clippy via crane's first-class `cargoClippy` builder. Reuses the
|
||||
# shared `cargoArtifacts` (deps already built) and runs
|
||||
# `cargo clippy --workspace --all-targets` directly.
|
||||
|
|
|
|||
Loading…
Reference in a new issue