From 468df177c4f01bce239da426710484fbc7b5a89d Mon Sep 17 00:00:00 2001 From: Jaka Hudoklin Date: Tue, 26 Mar 2019 10:35:21 +0100 Subject: [PATCH] dockerTools: add finalImageName parameter for pullImage --- doc/functions/dockertools.xml | 23 ++++++++++++++++------- nixos/tests/docker-tools.nix | 4 ++-- pkgs/build-support/docker/default.nix | 11 ++++++++--- pkgs/build-support/docker/examples.nix | 3 ++- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/doc/functions/dockertools.xml b/doc/functions/dockertools.xml index 75db0bd3918c..cb32db74b424 100644 --- a/doc/functions/dockertools.xml +++ b/doc/functions/dockertools.xml @@ -417,10 +417,11 @@ pkgs.dockerTools.buildLayeredImage { pullImage { imageName = "nixos/nix"; imageDigest = "sha256:20d9485b25ecfd89204e843a962c1bd70e9cc6858d65d7f5fadc340246e2116b"; - finalImageTag = "1.11"; - sha256 = "0mqjy3zq2v6rrhizgb9nvhczl87lcfphq9601wcprdika2jz7qh8"; - os = "linux"; - arch = "x86_64"; + finalImageName = "nix"; + finalImageTag = "1.11"; + sha256 = "0mqjy3zq2v6rrhizgb9nvhczl87lcfphq9601wcprdika2jz7qh8"; + os = "linux"; + arch = "x86_64"; } @@ -451,6 +452,14 @@ sha256:20d9485b25ecfd89204e843a962c1bd70e9cc6858d65d7f5fadc340246e2116b + + finalImageName, if specified, this is the name of the + image to be created. Note it is never used to fetch the image since we + prefer to rely on the immutable digest ID. By default it's equal to + imageName. + + + finalImageTag, if specified, this is the tag of the image to be created. Note it is never used to fetch the image since we @@ -458,19 +467,19 @@ sha256:20d9485b25ecfd89204e843a962c1bd70e9cc6858d65d7f5fadc340246e2116b latest. - + sha256 is the checksum of the whole fetched image. This argument is required. - + os, if specified, is the operating system of the fetched image. By default it's linux. - + arch, if specified, is the cpu architecture of the fetched image. By default it's x86_64. diff --git a/nixos/tests/docker-tools.nix b/nixos/tests/docker-tools.nix index 399e4d4e428f..502b537ed68b 100644 --- a/nixos/tests/docker-tools.nix +++ b/nixos/tests/docker-tools.nix @@ -34,8 +34,8 @@ import ./make-test.nix ({ pkgs, ... }: { # To test the pullImage tool $docker->succeed("docker load --input='${pkgs.dockerTools.examples.nixFromDockerHub}'"); - $docker->succeed("docker run --rm nixos/nix:2.2.1 nix-store --version"); - $docker->succeed("docker rmi nixos/nix:2.2.1"); + $docker->succeed("docker run --rm nix:2.2.1 nix-store --version"); + $docker->succeed("docker rmi nix:2.2.1"); # To test runAsRoot and entry point $docker->succeed("docker load --input='${pkgs.dockerTools.examples.nginx}'"); diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix index 6efb447e1424..ef93c97fd4d4 100644 --- a/pkgs/build-support/docker/default.nix +++ b/pkgs/build-support/docker/default.nix @@ -45,13 +45,18 @@ rec { , sha256 , os ? "linux" , arch ? "amd64" + + # This is used to set name to the pulled image + , finalImageName ? imageName # This used to set a tag to the pulled image , finalImageTag ? "latest" - , name ? fixName "docker-image-${imageName}-${finalImageTag}.tar" + + , name ? fixName "docker-image-${finalImageName}-${finalImageTag}.tar" }: runCommand name { - inherit imageName imageDigest; + inherit imageDigest; + imageName = finalImageName; imageTag = finalImageTag; impureEnvVars = pkgs.stdenv.lib.fetchers.proxyImpureEnvVars; outputHashMode = "flat"; @@ -62,7 +67,7 @@ rec { SSL_CERT_FILE = "${pkgs.cacert.out}/etc/ssl/certs/ca-bundle.crt"; sourceURL = "docker://${imageName}@${imageDigest}"; - destNameTag = "${imageName}:${finalImageTag}"; + destNameTag = "${finalImageName}:${finalImageTag}"; } '' skopeo --override-os ${os} --override-arch ${arch} copy "$sourceURL" "docker-archive://$out:$destNameTag" ''; diff --git a/pkgs/build-support/docker/examples.nix b/pkgs/build-support/docker/examples.nix index 8a1b35f02d99..557a4dbf54b7 100644 --- a/pkgs/build-support/docker/examples.nix +++ b/pkgs/build-support/docker/examples.nix @@ -88,8 +88,9 @@ rec { nixFromDockerHub = pullImage { imageName = "nixos/nix"; imageDigest = "sha256:85299d86263a3059cf19f419f9d286cc9f06d3c13146a8ebbb21b3437f598357"; - sha256 = "0vnp3mhpk4ny3xa3cgngqsargnmvfgld54d5sn4b5av6yqzzp67z"; + sha256 = "07q9y9r7fsd18sy95ybrvclpkhlal12d30ybnf089hq7v1hgxbi7"; finalImageTag = "2.2.1"; + finalImageName = "nix"; }; # 5. example of multiple contents, emacs and vi happily coexisting