3
0
Fork 0
forked from mirrors/nixpkgs

Merge pull request #80068 from jbedo/docker

dockerTools: fix export
This commit is contained in:
Robert Hensing 2021-09-29 14:55:21 +02:00 committed by GitHub
commit ae03fb8121
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 15 deletions

View file

@ -378,5 +378,10 @@ import ./make-test-python.nix ({ pkgs, ... }: {
docker.succeed(
"docker run --rm ${examples.layeredImageWithFakeRootCommands.imageName} sh -c 'stat -c '%u' /home/jane | grep -E ^1000$'"
)
with subtest("exportImage produces a valid tarball"):
docker.succeed(
"tar -tf ${examples.exportBash} | grep '\./bin/bash' > /dev/null"
)
'';
})

View file

@ -191,13 +191,13 @@ rec {
, postMount ? ""
, postUmount ? ""
}:
let
result = vmTools.runInLinuxVM (
vmTools.runInLinuxVM (
runCommand name
{
preVM = vmTools.createEmptyImage {
size = diskSize;
fullName = "docker-run-disk";
destination = "./image";
};
inherit fromImage fromImageName fromImageTag;
@ -278,12 +278,6 @@ rec {
${postUmount}
'');
in
runCommand name { } ''
mkdir -p $out
cd ${result}
cp layer.tar json VERSION $out
'';
exportImage = { name ? fromImage.name, fromImage, fromImageName ? null, fromImageTag ? null, diskSize ? 1024 }:
runWithOverlay {
@ -291,7 +285,13 @@ rec {
postMount = ''
echo "Packing raw image..."
tar -C mnt --hard-dereference --sort=name --mtime="@$SOURCE_DATE_EPOCH" -cf $out .
tar -C mnt --hard-dereference --sort=name --mtime="@$SOURCE_DATE_EPOCH" -cf $out/layer.tar .
'';
postUmount = ''
mv $out/layer.tar .
rm -rf $out
mv layer.tar $out
'';
};

View file

@ -541,4 +541,7 @@ rec {
config.Cmd = [ "hello" ];
includeStorePaths = false;
};
# Example export of the bash image
exportBash = pkgs.dockerTools.exportImage { fromImage = bash; };
}

View file

@ -257,14 +257,23 @@ rec {
eval "$postVM"
'';
createEmptyImage = {size, fullName}: ''
mkdir $out
diskImage=$out/disk-image.qcow2
/*
A bash script fragment that produces a disk image at `destination`.
*/
createEmptyImage = {
# Disk image size in MiB
size,
# Name that will be written to ${destination}/nix-support/full-name
fullName,
# Where to write the image files, defaulting to $out
destination ? "$out"
}: ''
mkdir -p ${destination}
diskImage=${destination}/disk-image.qcow2
${qemu}/bin/qemu-img create -f qcow2 $diskImage "${toString size}M"
mkdir $out/nix-support
echo "${fullName}" > $out/nix-support/full-name
mkdir ${destination}/nix-support
echo "${fullName}" > ${destination}/nix-support/full-name
'';