From 9ee7e8b67ecdab5bf1cd41a73053f2e57c35c184 Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Wed, 26 Jul 2017 21:53:35 +0200 Subject: [PATCH] docker: generate the image configuration and manifest This is required to push images to the Docker registry v2. --- pkgs/build-support/docker/default.nix | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix index e29970280245..b6e342cf9b5e 100644 --- a/pkgs/build-support/docker/default.nix +++ b/pkgs/build-support/docker/default.nix @@ -6,6 +6,7 @@ findutils, go, jshon, + jq, lib, pkgs, pigz, @@ -408,7 +409,7 @@ rec { contents runAsRoot diskSize extraCommands; }; result = runCommand "docker-image-${baseName}.tar.gz" { - buildInputs = [ jshon pigz coreutils findutils ]; + buildInputs = [ jshon pigz coreutils findutils jq ]; # Image name and tag must be lowercase imageName = lib.toLower name; imageTag = lib.toLower tag; @@ -496,6 +497,17 @@ rec { # Use the temp folder we've been working on to create a new image. mv temp image/$layerID + # Create image configuration file (used by registry v2) by using + # the configuration of the last layer + SHA_ARRAY=$(find ./ -name layer.tar | xargs sha256sum | cut -d" " -f1 | xargs -I{} echo -n '"sha256:{}" ' | sed 's/" "/","/g' | awk '{ print "["$1"]" }') + jq ". + {\"rootfs\": {\"diff_ids\": $SHA_ARRAY, \"type\": \"layers\"}}" image/$layerID/json > config.json + CONFIG_SHA=$(sha256sum config.json | cut -d ' ' -f1) + mv config.json image/$CONFIG_SHA.json + + # Create image manifest + LAYER_PATHS=$(find image/ -name layer.tar -printf '"%P" ' | sed 's/" "/","/g') + jq -n "[{\"Config\":\"$CONFIG_SHA.json\",\"RepoTags\":[\"$imageName:$imageTag\"],\"Layers\":[$LAYER_PATHS]}]" > image/manifest.json + # Store the json under the name image/repositories. jshon -n object \ -n object -s "$layerID" -i "$imageTag" \