diff --git a/examples/custom-image/arion-compose.nix b/examples/custom-image/arion-compose.nix new file mode 100644 index 0000000..13b5d5b --- /dev/null +++ b/examples/custom-image/arion-compose.nix @@ -0,0 +1,48 @@ +{ pkgs, ... }: + +let + webRoot = "/www"; + + webserverImage = pkgs.dockerTools.buildLayeredImage { + name = "a-webserver"; + + config = { + Entrypoint = [ + "${pkgs.darkhttpd}/bin/darkhttpd" + webRoot + ]; + + Volumes = { + "${webRoot}" = { }; + }; + }; + }; +in +{ + project.name = "custom-image"; + services = { + + webserver = { + image.tarball = webserverImage; + + # The following is essentially equivalent to + # + # { image.tarball = webserverImage; } + # + # It is included here as a demonstration of how to configure Arion to + # load a Docker image from *any* valid image tarball, not just one + # produced with a `pkgs.dockerTools` builder function. + #image.tarball = webserverImage.outPath; + #image.name = webserverImage.imageName; + #image.tag = webserverImage.imageTag; + + service.command = [ "--port" "8000" ]; + service.ports = [ + "8000:8000" # host:container + ]; + service.volumes = [ + "${pkgs.nix.doc}/share/doc/nix/manual:${webRoot}" + ]; + }; + }; +} diff --git a/examples/custom-image/arion-pkgs.nix b/examples/custom-image/arion-pkgs.nix new file mode 100644 index 0000000..69aad13 --- /dev/null +++ b/examples/custom-image/arion-pkgs.nix @@ -0,0 +1,6 @@ +# Instead of pinning Nixpkgs, we can opt to use the one in NIX_PATH +import { + # We specify the architecture explicitly. Use a Linux remote builder when + # calling arion from other platforms. + system = "x86_64-linux"; +} diff --git a/tests/arion-test/default.nix b/tests/arion-test/default.nix index a366309..961d9ce 100644 --- a/tests/arion-test/default.nix +++ b/tests/arion-test/default.nix @@ -39,6 +39,7 @@ in # Pre-build the image because we don't want to build the world # in the vm. (preEval [ ../../examples/minimal/arion-compose.nix ]).config.out.dockerComposeYaml + (preEval [ ../../examples/custom-image/arion-compose.nix ]).config.out.dockerComposeYaml (preEval [ ../../examples/full-nixos/arion-compose.nix ]).config.out.dockerComposeYaml (preEval [ ../../examples/nixos-unit/arion-compose.nix ]).config.out.dockerComposeYaml (preEval [ ../../examples/traefik/arion-compose.nix ]).config.out.dockerComposeYaml @@ -66,6 +67,18 @@ in ) machine.wait_until_fails("curl --fail localhost:8000") + # Tests + # - examples/custom-image + with subtest("custom-image"): + machine.succeed( + "rm -rf work && cp -frT ${../../examples/custom-image} work && cd work && NIX_PATH=nixpkgs='${pkgs.path}' arion up -d" + ) + machine.wait_until_succeeds("curl --fail localhost:8000") + machine.succeed( + "cd work && NIX_PATH=nixpkgs='${pkgs.path}' arion down" + ) + machine.wait_until_fails("curl --fail localhost:8000") + # Tests # - running same image again doesn't require a `docker load` with subtest("docker load only once"):