Skip to content

Commit

Permalink
Add arbitrary Docker image tar archive example
Browse files Browse the repository at this point in the history
and associated nixosTest subtest.

This tests the functionality of the newly-public
"services.<name>.build.image" parameter.
  • Loading branch information
tomeon committed Jan 28, 2020
1 parent c7d9e74 commit 1debd3d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/custom-image/arion-compose.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{ pkgs, ... }:

let
webRoot = "/www";

webserverImage = pkgs.dockerTools.buildLayeredImage {
name = "a-webserver";

config = {
Entrypoint = [
"${pkgs.darkhttpd}/bin/darkhttpd" webRoot
];

Volumes = {
"${webRoot}" = {};
};
};
};
in {
config.services = {

webserver = {
image.drv = webserverImage;
service.command = [ "--port" "8000" ];
service.ports = [
"8000:8000" # host:container
];
service.volumes = [
"${webRoot}:${pkgs.nix.doc}/share/doc/nix/manual"
];
};
};
}
6 changes: 6 additions & 0 deletions examples/custom-image/arion-pkgs.nix
Original file line number Diff line number Diff line change
@@ -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";
}
2 changes: 2 additions & 0 deletions tests/arion-test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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
pkgs.stdenv
Expand All @@ -53,6 +54,7 @@ in
};
$makeSubtest->("minimal", "${../../examples/minimal}");
$makeSubtest->("custom-image", "${../../examples/custom-image}");
$makeSubtest->("full-nixos", "${../../examples/full-nixos}", sub {
$machine->succeed("cd work && export NIX_PATH=nixpkgs='${pkgs.path}' && (echo 'nix run -f ~/h/arion arion -c arion exec webserver'; echo 'target=world; echo Hello \$target'; echo exit) | script /dev/null | grep 'Hello world'");
});
Expand Down

0 comments on commit 1debd3d

Please sign in to comment.