Merge pull request from xtruder/pkgs/dockerTools/buildLayeredImage/extraCommands

dockerTools: allow to pass extraCommands, uid and gid to buildLayered image
This commit is contained in:
lewo 2019-01-10 19:00:19 +01:00 committed by GitHub
commit 7612a6add4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions
nixos/tests
pkgs/build-support/docker

View File

@ -62,6 +62,7 @@ import ./make-test.nix ({ pkgs, ... }: {
# Ensure Layered Docker images work # Ensure Layered Docker images work
$docker->succeed("docker load --input='${pkgs.dockerTools.examples.layered-image}'"); $docker->succeed("docker load --input='${pkgs.dockerTools.examples.layered-image}'");
$docker->succeed("docker run --rm ${pkgs.dockerTools.examples.layered-image.imageName}"); $docker->succeed("docker run --rm ${pkgs.dockerTools.examples.layered-image.imageName}");
$docker->succeed("docker run --rm ${pkgs.dockerTools.examples.layered-image.imageName} cat extraCommands");
# Ensure building an image on top of a layered Docker images work # Ensure building an image on top of a layered Docker images work
$docker->succeed("docker load --input='${pkgs.dockerTools.examples.layered-on-top}'"); $docker->succeed("docker load --input='${pkgs.dockerTools.examples.layered-on-top}'");

View File

@ -316,14 +316,21 @@ rec {
# Files to add to the layer. # Files to add to the layer.
contents, contents,
baseJson, baseJson,
extraCommands,
uid ? 0, gid ? 0, uid ? 0, gid ? 0,
}: }:
runCommand "${name}-customisation-layer" { runCommand "${name}-customisation-layer" {
buildInputs = [ jshon rsync tarsum ]; buildInputs = [ jshon rsync tarsum ];
inherit extraCommands;
} }
'' ''
cp -r ${contents}/ ./layer cp -r ${contents}/ ./layer
if [[ -n $extraCommands ]]; then
chmod ug+w layer
(cd layer; eval "$extraCommands")
fi
# Tar up the layer and throw it into 'layer.tar'. # Tar up the layer and throw it into 'layer.tar'.
echo "Packing layer..." echo "Packing layer..."
mkdir $out mkdir $out
@ -494,6 +501,8 @@ rec {
# Time of creation of the image. Passing "now" will make the # Time of creation of the image. Passing "now" will make the
# created date be the time of building. # created date be the time of building.
created ? "1970-01-01T00:00:01Z", created ? "1970-01-01T00:00:01Z",
# Optional bash script to run on the files prior to fixturizing the layer.
extraCommands ? "", uid ? 0, gid ? 0,
# Docker's lowest maximum layer limit is 42-layers for an old # Docker's lowest maximum layer limit is 42-layers for an old
# version of the AUFS graph driver. We pick 24 to ensure there is # version of the AUFS graph driver. We pick 24 to ensure there is
# plenty of room for extension. I believe the actual maximum is # plenty of room for extension. I believe the actual maximum is
@ -501,8 +510,6 @@ rec {
maxLayers ? 24 maxLayers ? 24
}: }:
let let
uid = 0;
gid = 0;
baseName = baseNameOf name; baseName = baseNameOf name;
contentsEnv = symlinkJoin { name = "bulk-layers"; paths = (if builtins.isList contents then contents else [ contents ]); }; contentsEnv = symlinkJoin { name = "bulk-layers"; paths = (if builtins.isList contents then contents else [ contents ]); };
@ -531,7 +538,7 @@ rec {
name = baseName; name = baseName;
contents = contentsEnv; contents = contentsEnv;
baseJson = configJson; baseJson = configJson;
inherit uid gid; inherit uid gid extraCommands;
}; };
result = runCommand "docker-image-${baseName}.tar.gz" { result = runCommand "docker-image-${baseName}.tar.gz" {
buildInputs = [ jshon pigz coreutils findutils jq ]; buildInputs = [ jshon pigz coreutils findutils jq ];

View File

@ -155,6 +155,7 @@ rec {
layered-image = pkgs.dockerTools.buildLayeredImage { layered-image = pkgs.dockerTools.buildLayeredImage {
name = "layered-image"; name = "layered-image";
tag = "latest"; tag = "latest";
extraCommands = ''echo "(extraCommand)" > extraCommands'';
config.Cmd = [ "${pkgs.hello}/bin/hello" ]; config.Cmd = [ "${pkgs.hello}/bin/hello" ];
contents = [ pkgs.hello pkgs.bash pkgs.coreutils ]; contents = [ pkgs.hello pkgs.bash pkgs.coreutils ];
}; };