summary refs log tree commit diff
path: root/pkgs/build-support/docker/default.nix
diff options
context:
space:
mode:
authorRichard Wallace <richard.wallace@simspace.com>2019-12-30 14:45:10 -0700
committerRichard Wallace <richard.wallace@simspace.com>2019-12-30 14:47:11 -0700
commit3be767593b69ed334606ef077425b800ce1c0f71 (patch)
tree86e977b03e324afe5295f274c0df702a47ef9d5f /pkgs/build-support/docker/default.nix
parentad7c7cfe7a6873e17078478a845168ebefb4aa17 (diff)
downloadnixpkgs-3be767593b69ed334606ef077425b800ce1c0f71.tar
nixpkgs-3be767593b69ed334606ef077425b800ce1c0f71.tar.gz
nixpkgs-3be767593b69ed334606ef077425b800ce1c0f71.tar.bz2
nixpkgs-3be767593b69ed334606ef077425b800ce1c0f71.tar.lz
nixpkgs-3be767593b69ed334606ef077425b800ce1c0f71.tar.xz
nixpkgs-3be767593b69ed334606ef077425b800ce1c0f71.tar.zst
nixpkgs-3be767593b69ed334606ef077425b800ce1c0f71.zip
dockerTools.buildLayeredImage: fix building layered images in parallel
when tar'ing store paths into layered archives when building layered
images, don't use the absolute nix store path so that tar won't complain
if something new is added to the nix store

when building the final docker image, ignore any file changes tar
detects in the layers. they are all immutable and the only thing that
might change is the number of hard links due to store optimization
Diffstat (limited to 'pkgs/build-support/docker/default.nix')
-rw-r--r--pkgs/build-support/docker/default.nix18
1 files changed, 16 insertions, 2 deletions
diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix
index e10ff269950..a6304d9c064 100644
--- a/pkgs/build-support/docker/default.nix
+++ b/pkgs/build-support/docker/default.nix
@@ -325,7 +325,6 @@ rec {
         | jshon -d config \
         | jshon -s "1970-01-01T00:00:01Z" -i created > generic.json
 
-
       # WARNING!
       # The following code is fiddly w.r.t. ensuring every layer is
       # created, and that no paths are missed. If you change the
@@ -625,7 +624,22 @@ rec {
           -i "$imageName" > image/repositories
 
         echo "Cooking the image..."
-        tar -C image --dereference --hard-dereference --sort=name --mtime="@$SOURCE_DATE_EPOCH" --owner=0 --group=0  --mode=a-w --xform s:'^./':: -c . | pigz -nT > $out
+        # tar exits with an exit code of 1 if files changed while it was
+        # reading them. it considers a change in the number of hard links
+        # to be a "change", which can cause this to fail if images are being
+        # built concurrently and auto-optimise-store is turned on. since
+        # know the contents of these files will not change, we can reasonably
+        # ignore this exit code
+        set +e
+        tar -C image --dereference --hard-dereference --sort=name \
+          --mtime="@$SOURCE_DATE_EPOCH" --owner=0 --group=0  \
+          --mode=a-w --xform s:'^./':: --use-compress-program='pigz -nT' \
+          --warning=no-file-changed -cf $out .
+        RET=$?
+        if [ $RET -ne 0 ] && [ $RET -ne 1 ]; then
+          exit $RET
+        fi
+        set -e
 
         echo "Finished."
       '';