about summary refs log tree commit diff
path: root/pkgs/build-support/docker
diff options
context:
space:
mode:
authorAntoine Eiche <lewo@abesis.fr>2017-07-26 21:53:35 +0200
committerRobin Gloster <mail@glob.in>2017-07-26 23:05:29 +0200
commit9ee7e8b67ecdab5bf1cd41a73053f2e57c35c184 (patch)
tree58d271a808e54add67133641a5b20ebf79800c5f /pkgs/build-support/docker
parent8a431e13b5873295f7a6714fe63623f52daea743 (diff)
downloadnixlib-9ee7e8b67ecdab5bf1cd41a73053f2e57c35c184.tar
nixlib-9ee7e8b67ecdab5bf1cd41a73053f2e57c35c184.tar.gz
nixlib-9ee7e8b67ecdab5bf1cd41a73053f2e57c35c184.tar.bz2
nixlib-9ee7e8b67ecdab5bf1cd41a73053f2e57c35c184.tar.lz
nixlib-9ee7e8b67ecdab5bf1cd41a73053f2e57c35c184.tar.xz
nixlib-9ee7e8b67ecdab5bf1cd41a73053f2e57c35c184.tar.zst
nixlib-9ee7e8b67ecdab5bf1cd41a73053f2e57c35c184.zip
docker: generate the image configuration and manifest
This is required to push images to the Docker registry v2.
Diffstat (limited to 'pkgs/build-support/docker')
-rw-r--r--pkgs/build-support/docker/default.nix14
1 files changed, 13 insertions, 1 deletions
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" \