feat: add arbitrary Docker image tarball example
and associated subtest. This tests the functionality of the newly-added `services.<name>.image.tarball` parameter.
This commit is contained in:
parent
fc14ff7abf
commit
d2fb84c6e0
3 changed files with 67 additions and 0 deletions
48
examples/custom-image/arion-compose.nix
Normal file
48
examples/custom-image/arion-compose.nix
Normal file
|
@ -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}"
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
6
examples/custom-image/arion-pkgs.nix
Normal file
6
examples/custom-image/arion-pkgs.nix
Normal file
|
@ -0,0 +1,6 @@
|
|||
# Instead of pinning Nixpkgs, we can opt to use the one in NIX_PATH
|
||||
import <nixpkgs> {
|
||||
# We specify the architecture explicitly. Use a Linux remote builder when
|
||||
# calling arion from other platforms.
|
||||
system = "x86_64-linux";
|
||||
}
|
|
@ -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"):
|
||||
|
|
Loading…
Reference in a new issue