dockerTools.buildLayeredImage: Avoid appending to tarballs when building layers

Appending to an existing tar archive repeatedly seems to be a quadratic
operation, since tar seems to traverse the existing archive even using
the `-r, --append` flag. This commit avoids that by passing the list of
files to a single tar invocation.
This commit is contained in:
Utku Demir 2020-05-06 15:43:39 +12:00
parent defdda6f93
commit 69f6294724
No known key found for this signature in database
GPG Key ID: F3F8629C3E0BF60B

View File

@ -32,15 +32,13 @@ tar -cf "$layerPath/layer.tar" \
# to /nix/store. In order to create the correct structure
# in the tar file, we transform the relative nix store
# path to the absolute store path.
for storePath in "$@"; do
n=$(basename "$storePath")
basename -a "$@" |
tar -C /nix/store -rpf "$layerPath/layer.tar" \
--hard-dereference --sort=name \
--mtime="@$SOURCE_DATE_EPOCH" \
--owner=0 --group=0 \
--transform="s,$n,/nix/store/$n," \
$n
done
--verbatim-files-from --files-from - \
--hard-dereference --sort=name \
--mtime="@$SOURCE_DATE_EPOCH" \
--owner=0 --group=0 \
--transform="flags=rS;s,^,/nix/store/,"
# Compute a checksum of the tarball.
tarhash=$(tarsum < $layerPath/layer.tar)