summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>2021-03-12 00:39:51 +0000
committerGitHub <noreply@github.com>2021-03-12 00:39:51 +0000
commit903fc486743b951457b2cc2b8321c77c1289d168 (patch)
tree682e48af4e93393b974fdaf513199795e7bce73f /pkgs/build-support
parentd6257d451b70acba456c13be88fab53d90273dfd (diff)
parent0fad702a50b12266722fce7df48003d4316eee85 (diff)
Merge master into staging-next
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/docker/default.nix16
-rw-r--r--pkgs/build-support/docker/examples.nix14
-rw-r--r--pkgs/build-support/docker/stream_layered_image.py10
3 files changed, 30 insertions, 10 deletions
diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix
index e9014a889540..fec289f0ff1e 100644
--- a/pkgs/build-support/docker/default.nix
+++ b/pkgs/build-support/docker/default.nix
@@ -447,7 +447,7 @@ rec {
let
stream = streamLayeredImage args;
in
- runCommand "${name}.tar.gz" {
+ runCommand "${baseNameOf name}.tar.gz" {
inherit (stream) imageName;
passthru = { inherit (stream) imageTag; };
nativeBuildInputs = [ pigz ];
@@ -746,8 +746,10 @@ rec {
(lib.assertMsg (maxLayers > 1)
"the maxLayers argument of dockerTools.buildLayeredImage function must be greather than 1 (current value: ${toString maxLayers})");
let
+ baseName = baseNameOf name;
+
streamScript = writePython3 "stream" {} ./stream_layered_image.py;
- baseJson = writeText "${name}-base.json" (builtins.toJSON {
+ baseJson = writeText "${baseName}-base.json" (builtins.toJSON {
inherit config;
architecture = defaultArch;
os = "linux";
@@ -759,7 +761,7 @@ rec {
# things like permissions set on 'extraCommands' are not overriden
# by Nix. Then we precompute the sha256 for performance.
customisationLayer = symlinkJoin {
- name = "${name}-customisation-layer";
+ name = "${baseName}-customisation-layer";
paths = contentsList;
inherit extraCommands;
postBuild = ''
@@ -788,7 +790,7 @@ rec {
# so they'll be excluded from the created images.
unnecessaryDrvs = [ baseJson overallClosure ];
- conf = runCommand "${name}-conf.json" {
+ conf = runCommand "${baseName}-conf.json" {
inherit maxLayers created;
imageName = lib.toLower name;
passthru.imageTag =
@@ -841,18 +843,20 @@ rec {
cat ${baseJson} | jq '
. + {
+ "store_dir": $store_dir,
"store_layers": $store_layers,
"customisation_layer", $customisation_layer,
"repo_tag": $repo_tag,
"created": $created
}
- ' --argjson store_layers "$store_layers" \
+ ' --arg store_dir "${storeDir}" \
+ --argjson store_layers "$store_layers" \
--arg customisation_layer ${customisationLayer} \
--arg repo_tag "$imageName:$imageTag" \
--arg created "$created" |
tee $out
'';
- result = runCommand "stream-${name}" {
+ result = runCommand "stream-${baseName}" {
inherit (conf) imageName;
passthru = {
inherit (conf) imageTag;
diff --git a/pkgs/build-support/docker/examples.nix b/pkgs/build-support/docker/examples.nix
index 86375a40baa0..9e33a42af23e 100644
--- a/pkgs/build-support/docker/examples.nix
+++ b/pkgs/build-support/docker/examples.nix
@@ -427,4 +427,18 @@ rec {
tag = "latest";
contents = [ pkgs.bash symlink ];
} // { passthru = { inherit symlink; }; };
+
+ # image with registry/ prefix
+ prefixedImage = pkgs.dockerTools.buildImage {
+ name = "registry-1.docker.io/image";
+ tag = "latest";
+ config.Cmd = [ "${pkgs.hello}/bin/hello" ];
+ };
+
+ # layered image with registry/ prefix
+ prefixedLayeredImage = pkgs.dockerTools.buildLayeredImage {
+ name = "registry-1.docker.io/layered-image";
+ tag = "latest";
+ config.Cmd = [ "${pkgs.hello}/bin/hello" ];
+ };
}
diff --git a/pkgs/build-support/docker/stream_layered_image.py b/pkgs/build-support/docker/stream_layered_image.py
index e35bd0b0e8c0..60d67442c169 100644
--- a/pkgs/build-support/docker/stream_layered_image.py
+++ b/pkgs/build-support/docker/stream_layered_image.py
@@ -130,12 +130,13 @@ class ExtractChecksum:
LayerInfo = namedtuple("LayerInfo", ["size", "checksum", "path", "paths"])
-def add_layer_dir(tar, paths, mtime):
+def add_layer_dir(tar, paths, store_dir, mtime):
"""
Appends given store paths to a TarFile object as a new layer.
tar: 'tarfile.TarFile' object for the new layer to be added to.
paths: List of store paths.
+ store_dir: the root directory of the nix store
mtime: 'mtime' of the added files and the layer tarball.
Should be an integer representing a POSIX time.
@@ -143,9 +144,9 @@ def add_layer_dir(tar, paths, mtime):
the layer added.
"""
- invalid_paths = [i for i in paths if not i.startswith("/nix/store/")]
+ invalid_paths = [i for i in paths if not i.startswith(store_dir)]
assert len(invalid_paths) == 0, \
- "Expecting absolute store paths, but got: {invalid_paths}"
+ f"Expecting absolute paths from {store_dir}, but got: {invalid_paths}"
# First, calculate the tarball checksum and the size.
extract_checksum = ExtractChecksum()
@@ -245,6 +246,7 @@ def main():
else datetime.fromisoformat(conf["created"])
)
mtime = int(created.timestamp())
+ store_dir = conf["store_dir"]
with tarfile.open(mode="w|", fileobj=sys.stdout.buffer) as tar:
layers = []
@@ -253,7 +255,7 @@ def main():
"Creating layer", num,
"from paths:", store_layer,
file=sys.stderr)
- info = add_layer_dir(tar, store_layer, mtime=mtime)
+ info = add_layer_dir(tar, store_layer, store_dir, mtime=mtime)
layers.append(info)
print("Creating the customisation layer...", file=sys.stderr)