Skip to content

Commit

Permalink
feat: support dockerTools.streamLayeredImage
Browse files Browse the repository at this point in the history
Support the more optimized way of building docker images.

Uses `isExe` to differentiate between a prebuilt image or a command that spits out an image. See [sources][].

[sources]: https://github.com/NixOS/nixpkgs/blob/0dbb76220d1090753ba7919353c13b96d5969aff/pkgs/build-support/docker/default.nix#L1042-L1044
  • Loading branch information
yajo committed Nov 6, 2023
1 parent ea469ff commit 881a8dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/content/examples/image/image.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ dockerTools, nginx }:
dockerTools.buildLayeredImage {
dockerTools.streamLayeredImage {
name = "nginx";
contents = [ nginx ];
extraCommands = ''
Expand Down
17 changes: 11 additions & 6 deletions lib/docker/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
with lib; {
copyDockerImages = { images, dest, args ? "" }:
pkgs.writeScript "copy-docker-images.sh" (concatMapStrings
(image: ''
#!${pkgs.runtimeShell}
(image:
let
prefix = optionalString (image.isExe or false) "${image} | ${pkgs.gzip}/bin/gzip --fast |";
src = if image.isExe or false then "/dev/stdin" else ${image};
in
''
#!${pkgs.runtimeShell}
set -e
set -e
echo "copying '${image.imageName}:${image.imageTag}' to '${dest}/${image.imageName}:${image.imageTag}'"
${pkgs.skopeo}/bin/skopeo copy ${args} $@ docker-archive:${image} ${dest}/${image.imageName}:${image.imageTag}
'')
echo "copying '${image.imageName}:${image.imageTag}' to '${dest}/${image.imageName}:${image.imageTag}'"
${prefix} ${pkgs.skopeo}/bin/skopeo copy ${args} $@ docker-archive:${src} ${dest}/${image.imageName}:${image.imageTag}
'')
images);
}

0 comments on commit 881a8dc

Please sign in to comment.