From 95d9429f88cdffae651c9b47a3e8cf6f9f8de019 Mon Sep 17 00:00:00 2001 From: W-Mark Kubacki Date: Mon, 28 Nov 2016 16:18:31 +0100 Subject: [PATCH] aci: sort contents, and pull manifest to the front If the manifest is the first file then tools do not need to download the whole image file in order to detect changes or updates. Sorted contents of ACIs allow for easier comparison, and usage of tools such as zsync, and deduplication on the server. The price, sorting by 'tar', is cheap. Parameter 'f' for 'tar' must be followed by the filename for recent versions of 'tar'. Mind the order! closes #210 --- aci-builder/build.sh | 5 +++-- aci-tester/build.sh | 3 ++- dgr/common/tar.go | 10 +++------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/aci-builder/build.sh b/aci-builder/build.sh index e37ba0d4..17f7ac55 100755 --- a/aci-builder/build.sh +++ b/aci-builder/build.sh @@ -42,7 +42,7 @@ if ! [[ -x ${dir}/files/dgr/usr/bin/tar ]]; then rm -r ${WORKDIR} fi -sudo tar xf ${dir}/rootfs.tar.xz -C ${rootfs}/dgr/ +sudo tar -C ${rootfs}/dgr/ -xf ${dir}/rootfs.tar.xz sudo cp -R ${dir}/files/. ${rootfs} sudo chown root: ${rootfs} cp ${dir}/manifest.json ${target}/manifest @@ -61,7 +61,8 @@ sudo rm -Rf ${rootfs}/dgr/usr/sbin/ sudo bash -c "cd ${rootfs}/dgr/usr && ln -s bin sbin && cd -" cd ${target} -sudo tar cpfz ../bindata/aci-builder.aci rootfs manifest +sudo tar --sort=name --numeric-owner -cpzf ../bindata/aci-builder.aci manifest rootfs \ +|| sudo tar -cpzf ../bindata/aci-builder.aci manifest rootfs sudo chown ${USER}: ../bindata/aci-builder.aci sudo rm -Rf rootfs/ cd - diff --git a/aci-tester/build.sh b/aci-tester/build.sh index c779d028..cd5c4d52 100755 --- a/aci-tester/build.sh +++ b/aci-tester/build.sh @@ -31,5 +31,6 @@ curl --fail --silent --show-error --location --remote-time --compressed --create chmod +x ${rootfs}/dgr/usr/bin/* cd ${target} -tar cpfz ../bindata/aci-tester.aci rootfs manifest +tar --sort=name --numeric-owner -cpzf ../bindata/aci-tester.aci manifest rootfs \ +|| tar -cpzf ../bindata/aci-tester.aci manifest rootfs cd - diff --git a/dgr/common/tar.go b/dgr/common/tar.go index 1da0af8a..20a7b4dc 100644 --- a/dgr/common/tar.go +++ b/dgr/common/tar.go @@ -1,11 +1,7 @@ package common func Tar(destination string, source ...string) error { // remove zip - source = append(source, "") - source = append(source, "") - copy(source[2:], source[0:]) - source[0] = "cpf" - source[1] = destination - - return ExecCmd("tar", source...) + params := []string{"--sort=name", "--numeric-owner", "-cpf", destination} + params = append(params, source...) + return ExecCmd("tar", params...) }