git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #52870 from xtruder/pkgs/dockerTools/buildLayeredImage/extraCommands

dockerTools: allow to pass extraCommands, uid and gid to buildLayered image

commit7612a6add4cb0e16716d183bef559f9a0730eb80 authorlewo <lewo@abesis.fr> dateThu 10 Jan 2019, 19:00 (8 years ago) parentb75aff7954cda5
3 files changed+12−3
nixos/tests/docker-tools.nix+1 pkgs/build-support/docker/default.nix+10−3 pkgs/build-support/docker/examples.nix+1
nixos/tests/docker-tools.nix+1
@@ -62,6 +62,7 @@ import ./make-test.nix ({ pkgs, ... }: {
6262 # Ensure Layered Docker images work
6363 $docker->succeed("docker load --input='${pkgs.dockerTools.examples.layered-image}'");
6464 $docker->succeed("docker run --rm ${pkgs.dockerTools.examples.layered-image.imageName}");
65+ $docker->succeed("docker run --rm ${pkgs.dockerTools.examples.layered-image.imageName} cat extraCommands");
6566
6667 # Ensure building an image on top of a layered Docker images work
6768 $docker->succeed("docker load --input='${pkgs.dockerTools.examples.layered-on-top}'");
pkgs/build-support/docker/default.nix+10−3
@@ -316,14 +316,21 @@ rec {
316316 # Files to add to the layer.
317317 contents,
318318 baseJson,
319+ extraCommands,
319320 uid ? 0, gid ? 0,
320321 }:
321322 runCommand "${name}-customisation-layer" {
322323 buildInputs = [ jshon rsync tarsum ];
324+ inherit extraCommands;
323325 }
324326 ''
325327 cp -r ${contents}/ ./layer
326328
329+ if [[ -n $extraCommands ]]; then
330+ chmod ug+w layer
331+ (cd layer; eval "$extraCommands")
332+ fi
333+
327334 # Tar up the layer and throw it into 'layer.tar'.
328335 echo "Packing layer..."
329336 mkdir $out
@@ -494,6 +501,8 @@ rec {
494501 # Time of creation of the image. Passing "now" will make the
495502 # created date be the time of building.
496503 created ? "1970-01-01T00:00:01Z",
504+ # Optional bash script to run on the files prior to fixturizing the layer.
505+ extraCommands ? "", uid ? 0, gid ? 0,
497506 # Docker's lowest maximum layer limit is 42-layers for an old
498507 # version of the AUFS graph driver. We pick 24 to ensure there is
499508 # plenty of room for extension. I believe the actual maximum is
@@ -501,8 +510,6 @@ rec {
501510 maxLayers ? 24
502511 }:
503512 let
504− uid = 0;
505− gid = 0;
506513 baseName = baseNameOf name;
507514 contentsEnv = symlinkJoin { name = "bulk-layers"; paths = (if builtins.isList contents then contents else [ contents ]); };
508515
@@ -531,7 +538,7 @@ rec {
531538 name = baseName;
532539 contents = contentsEnv;
533540 baseJson = configJson;
534− inherit uid gid;
541+ inherit uid gid extraCommands;
535542 };
536543 result = runCommand "docker-image-${baseName}.tar.gz" {
537544 buildInputs = [ jshon pigz coreutils findutils jq ];
pkgs/build-support/docker/examples.nix+1
@@ -155,6 +155,7 @@ rec {
155155 layered-image = pkgs.dockerTools.buildLayeredImage {
156156 name = "layered-image";
157157 tag = "latest";
158+ extraCommands = ''echo "(extraCommand)" > extraCommands'';
158159 config.Cmd = [ "${pkgs.hello}/bin/hello" ];
159160 contents = [ pkgs.hello pkgs.bash pkgs.coreutils ];
160161 };