hercules-ci / arion

Run docker-compose with help from Nix/NixOS
Apache License 2.0
643 stars 47 forks source link

Expose a bundle of all docker-images in a composition. #132

Open tomprince opened 3 years ago

tomprince commented 3 years ago

I'm using arion to build docker-compose configuration for running on a non-nix-based system. I'd like to be able get a single file with all the needed docker images (such as is made be dockerTools.mergeImages.

I'm currently using:

let
arion = pkgs.arion.eval { ... };
in pkgs.dockerTools.mergeImages (
  map (
    { imageName, imageTag, imageExe }:
    pkgs.runCommand "${baseNameOf imageName}.tar.gz"
      {
        inherit imageName;
        passthru = { inherit imageTag; };
        nativeBuildInputs = [ pkgs.pigz ];
      } "${imageExe} | pigz -nT > $out"
    ) arion.config.build.imagesToLoad
)

to build one. (Unfortunately, mergeImages doesn't support streamed images, so I needed to reimplement buildLayerdImage).

roberth commented 3 years ago

I think the most significant part of solving this is to improve dockerTools to add a streaming mergeImages, but the glue can also be improved on the arion side.

The info to do this is already available in the x-arion field.

examples/full-nixos$ ../../run-arion-quick cat | jq '."x-arion".images'
[
  {
    "imageExe": "/nix/store/371w0nm23r6a6kmpncz8q5kvqpks74qh-stream-webserver",
    "imageName": "webserver",
    "imageTag": "5r4gm8i0wfpggzw8bygmzfmsw45arcd3"
  }
]

But you don't have to process this information externally. You could write a module instead, that you import at the arion project level (top level of arion-compose.nix). This module can write to config.docker-compose.extended, so you can extract it with arion cat | jq '."x-arion".loadImagesScript'. I suppose it would be nice if arion cat could select the option by itself, so you don't have to worry about jq and the compose file internals.