dockerTools: Fix the layer order
The layer order was not correct when a parent image was used: parent image layers were above the new created layer. This commits simplifies the code related to layer ordering. In particular, layers in `layer-list` are ordered from bottom-most to top-most. This is also the order of layers in the `rootfs.diff_ids` attribute of the image configuration.
This commit is contained in:
parent
5ef1223f30
commit
a5a5820048
|
@ -216,7 +216,7 @@ rec {
|
||||||
find image/$extractionID/layer -name ".wh.*" -exec bash -c 'name="$(basename {}|sed "s/^.wh.//")"; mknod "$(dirname {})/$name" c 0 0; rm {}' \;
|
find image/$extractionID/layer -name ".wh.*" -exec bash -c 'name="$(basename {}|sed "s/^.wh.//")"; mknod "$(dirname {})/$name" c 0 0; rm {}' \;
|
||||||
|
|
||||||
# Get the next lower directory and continue the loop.
|
# Get the next lower directory and continue the loop.
|
||||||
lowerdir=$lowerdir''${lowerdir:+:}image/$extractionID/layer
|
lowerdir=image/$extractionID/layer''${lowerdir:+:}$lowerdir
|
||||||
done
|
done
|
||||||
|
|
||||||
mkdir work
|
mkdir work
|
||||||
|
@ -585,9 +585,9 @@ rec {
|
||||||
layerID=$(sha256sum "$layer/json" | cut -d ' ' -f 1)
|
layerID=$(sha256sum "$layer/json" | cut -d ' ' -f 1)
|
||||||
ln -s "$layer" "./image/$layerID"
|
ln -s "$layer" "./image/$layerID"
|
||||||
|
|
||||||
manifestJson=$(echo "$manifestJson" | jq ".[0].Layers |= [\"$layerID/layer.tar\"] + .")
|
manifestJson=$(echo "$manifestJson" | jq ".[0].Layers |= . + [\"$layerID/layer.tar\"]")
|
||||||
imageJson=$(echo "$imageJson" | jq ".history |= [{\"created\": \"$(jq -r .created ${configJson})\"}] + .")
|
imageJson=$(echo "$imageJson" | jq ".history |= . + [{\"created\": \"$(jq -r .created ${configJson})\"}]")
|
||||||
imageJson=$(echo "$imageJson" | jq ".rootfs.diff_ids |= [\"sha256:$layerChecksum\"] + .")
|
imageJson=$(echo "$imageJson" | jq ".rootfs.diff_ids |= . + [\"sha256:$layerChecksum\"]")
|
||||||
done
|
done
|
||||||
imageJsonChecksum=$(echo "$imageJson" | sha256sum | cut -d ' ' -f1)
|
imageJsonChecksum=$(echo "$imageJson" | sha256sum | cut -d ' ' -f1)
|
||||||
echo "$imageJson" > "image/$imageJsonChecksum.json"
|
echo "$imageJson" > "image/$imageJsonChecksum.json"
|
||||||
|
@ -779,23 +779,24 @@ rec {
|
||||||
# Use the temp folder we've been working on to create a new image.
|
# Use the temp folder we've been working on to create a new image.
|
||||||
mv temp image/$layerID
|
mv temp image/$layerID
|
||||||
|
|
||||||
# Add the new layer ID to the beginning of the layer list
|
# Add the new layer ID to the end of the layer list
|
||||||
(
|
(
|
||||||
|
cat layer-list
|
||||||
# originally this used `sed -i "1i$layerID" layer-list`, but
|
# originally this used `sed -i "1i$layerID" layer-list`, but
|
||||||
# would fail if layer-list was completely empty.
|
# would fail if layer-list was completely empty.
|
||||||
echo "$layerID/layer.tar"
|
echo "$layerID/layer.tar"
|
||||||
cat layer-list
|
|
||||||
) | ${pkgs.moreutils}/bin/sponge layer-list
|
) | ${pkgs.moreutils}/bin/sponge layer-list
|
||||||
|
|
||||||
# Create image json and image manifest
|
# Create image json and image manifest
|
||||||
imageJson=$(cat ${baseJson} | jq ". + {\"rootfs\": {\"diff_ids\": [], \"type\": \"layers\"}}")
|
imageJson=$(cat ${baseJson} | jq ". + {\"rootfs\": {\"diff_ids\": [], \"type\": \"layers\"}}")
|
||||||
manifestJson=$(jq -n "[{\"RepoTags\":[\"$imageName:$imageTag\"]}]")
|
manifestJson=$(jq -n "[{\"RepoTags\":[\"$imageName:$imageTag\"]}]")
|
||||||
|
|
||||||
for layerTar in $(tac ./layer-list); do
|
for layerTar in $(cat ./layer-list); do
|
||||||
layerChecksum=$(sha256sum image/$layerTar | cut -d ' ' -f1)
|
layerChecksum=$(sha256sum image/$layerTar | cut -d ' ' -f1)
|
||||||
imageJson=$(echo "$imageJson" | jq ".history |= [{\"created\": \"$(jq -r .created ${baseJson})\"}] + .")
|
imageJson=$(echo "$imageJson" | jq ".history |= . + [{\"created\": \"$(jq -r .created ${baseJson})\"}]")
|
||||||
imageJson=$(echo "$imageJson" | jq ".rootfs.diff_ids |= [\"sha256:$layerChecksum\"] + .")
|
# diff_ids order is from the bottom-most to top-most layer
|
||||||
manifestJson=$(echo "$manifestJson" | jq ".[0].Layers |= [\"$layerTar\"] + .")
|
imageJson=$(echo "$imageJson" | jq ".rootfs.diff_ids |= . + [\"sha256:$layerChecksum\"]")
|
||||||
|
manifestJson=$(echo "$manifestJson" | jq ".[0].Layers |= . + [\"$layerTar\"]")
|
||||||
done
|
done
|
||||||
|
|
||||||
imageJsonChecksum=$(echo "$imageJson" | sha256sum | cut -d ' ' -f1)
|
imageJsonChecksum=$(echo "$imageJson" | sha256sum | cut -d ' ' -f1)
|
||||||
|
|
Loading…
Reference in New Issue