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

Calculate sha256 on the fly on dockerTools.buildLayeredImage #89075

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions pkgs/build-support/docker/default.nix
Expand Up @@ -395,7 +395,13 @@ rec {
# Tar up the layer and throw it into 'layer.tar', while calculating its checksum.
echo "Packing layer..."
mkdir $out
tarhash=$(tar --transform='s|^\./||' -C layer --sort=name --mtime="@$SOURCE_DATE_EPOCH" --owner=${toString uid} --group=${toString gid} -cf - . | tee $out/layer.tar | tarsum)
tarhash=$(
tar --transform='s|^\./||' -C layer \
--sort=name --mtime="@$SOURCE_DATE_EPOCH" \
--owner=${toString uid} --group=${toString gid} -cf - . |
tee $out/layer.tar |
tee >(sha256sum | cut -d ' ' -f 1 > "$out/sha256") |
tarsum)

# Add a 'checksum' field to the JSON, with the value set to the
# checksum of the tarball.
Expand Down Expand Up @@ -626,9 +632,11 @@ rec {
imageJson=$(cat ${configJson} | jq ". + {\"rootfs\": {\"diff_ids\": [], \"type\": \"layers\"}}")
manifestJson=$(jq -n "[{\"RepoTags\":[\"$imageName:$imageTag\"]}]")
for layer in $(cat layer-list); do
layerChecksum=$(sha256sum $layer/layer.tar | cut -d ' ' -f1)
layerChecksum=$(cat $layer/sha256)
layerID=$(sha256sum "$layer/json" | cut -d ' ' -f 1)
ln -s "$layer" "./image/$layerID"

mkdir "./image/$layerID"
ln -s -t "./image/$layerID" "$layer/"{layer.tar,json,VERSION}

manifestJson=$(echo "$manifestJson" | jq ".[0].Layers |= . + [\"$layerID/layer.tar\"]")
imageJson=$(echo "$imageJson" | jq ".history |= . + [{\"created\": \"$(jq -r .created ${configJson})\"}]")
Expand Down
1 change: 1 addition & 0 deletions pkgs/build-support/docker/store-path-to-layer.sh
Expand Up @@ -39,6 +39,7 @@ tarhash=$(
--transform 's,^nix/store$,/\0,' \
--transform 's,^[^/],/nix/store/\0,rS' |
tee "$layerPath/layer.tar" |
tee >(sha256sum | cut -d ' ' -f 1 > $layerPath/sha256) |
tarsum
)

Expand Down