mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 06:53:01 +00:00
dockerTools: Preprocess layers list before unpack to handle repeated layers
This commit is contained in:
parent
298c543e55
commit
84e04ccf85
@ -229,6 +229,15 @@ rec {
|
||||
mount /dev/${vmTools.hd} disk
|
||||
cd disk
|
||||
|
||||
function dedup() {
|
||||
declare -A seen
|
||||
while read ln; do
|
||||
if [[ -z "''${seen["$ln"]:-}" ]]; then
|
||||
echo "$ln"; seen["$ln"]=1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
if [[ -n "$fromImage" ]]; then
|
||||
echo "Unpacking base image..."
|
||||
mkdir image
|
||||
@ -245,7 +254,8 @@ rec {
|
||||
parentID="$(cat "image/manifest.json" | jq -r '.[0].Config | rtrimstr(".json")')"
|
||||
fi
|
||||
|
||||
cat ./image/manifest.json | jq -r '.[0].Layers | .[]' > layer-list
|
||||
# In case of repeated layers, unpack only the last occurrence of each
|
||||
cat ./image/manifest.json | jq -r '.[0].Layers | .[]' | tac | dedup | tac > layer-list
|
||||
else
|
||||
touch layer-list
|
||||
fi
|
||||
@ -259,14 +269,13 @@ rec {
|
||||
|
||||
mkdir -p image/$extractionID/layer
|
||||
tar -C image/$extractionID/layer -xpf image/$layerTar
|
||||
rm image/$layerTar
|
||||
|
||||
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.
|
||||
lowerdir=image/$extractionID/layer''${lowerdir:+:}$lowerdir
|
||||
done
|
||||
# Don't remove tarballs until all unpacked in case some are used more than once
|
||||
awk '{print "image/"$0}' layer-list | xargs rm -f
|
||||
|
||||
mkdir work
|
||||
mkdir layer
|
||||
|
Loading…
Reference in New Issue
Block a user