2022-12-02 00:21:38 +01:00
|
|
|
{ usePodman ? false, pkgs, lib ? pkgs.lib, ... }:
|
2019-01-02 09:54:46 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
# To make some prebuilt derivations available in the vm
|
2019-03-05 19:41:54 +01:00
|
|
|
preEval = modules: import ../../src/nix/eval-composition.nix {
|
|
|
|
inherit modules;
|
2019-01-02 09:54:46 +01:00
|
|
|
inherit pkgs;
|
|
|
|
};
|
2021-05-26 16:57:56 +02:00
|
|
|
|
|
|
|
inherit (lib)
|
2021-10-28 21:59:01 +02:00
|
|
|
concatMapStringsSep
|
2021-05-26 16:57:56 +02:00
|
|
|
optionalAttrs
|
|
|
|
optionalString
|
|
|
|
;
|
|
|
|
|
|
|
|
haveSystemd = usePodman || pkgs.arionTestingFlags.dockerSupportsSystemd;
|
|
|
|
|
2021-10-28 21:59:01 +02:00
|
|
|
concatPathLines = paths: concatMapStringsSep "\n" (x: "${x}") paths;
|
|
|
|
|
2019-01-02 09:54:46 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
name = "arion-test";
|
2022-04-07 22:55:22 +02:00
|
|
|
nodes.machine = { pkgs, lib, ... }: {
|
2019-01-02 09:54:46 +01:00
|
|
|
environment.systemPackages = [
|
|
|
|
pkgs.arion
|
2021-05-26 16:57:56 +02:00
|
|
|
] ++ lib.optional usePodman pkgs.docker;
|
|
|
|
virtualisation.docker.enable = !usePodman;
|
|
|
|
virtualisation.podman = optionalAttrs usePodman {
|
|
|
|
enable = true;
|
|
|
|
dockerSocket.enable = true;
|
|
|
|
};
|
2023-08-19 22:13:18 +02:00
|
|
|
|
2019-01-02 09:54:46 +01:00
|
|
|
# no caches, because no internet
|
2023-02-16 23:04:20 +01:00
|
|
|
nix.settings.substituters = lib.mkForce [];
|
2019-01-27 01:08:51 +01:00
|
|
|
|
2019-01-02 09:54:46 +01:00
|
|
|
virtualisation.writableStore = true;
|
2021-10-28 21:59:01 +02:00
|
|
|
# Switch to virtualisation.additionalPaths when dropping all NixOS <= 21.05.
|
|
|
|
environment.etc."extra-paths-for-test".text = concatPathLines [
|
2019-01-02 09:54:46 +01:00
|
|
|
# Pre-build the image because we don't want to build the world
|
|
|
|
# in the vm.
|
2019-10-03 21:30:14 +02:00
|
|
|
(preEval [ ../../examples/minimal/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
|
2021-01-21 23:53:37 +01:00
|
|
|
(preEval [ ../../examples/traefik/arion-compose.nix ]).config.out.dockerComposeYaml
|
2019-01-27 01:08:51 +01:00
|
|
|
pkgs.stdenv
|
2019-01-02 09:54:46 +01:00
|
|
|
];
|
2020-03-02 11:13:47 +01:00
|
|
|
|
2024-02-05 17:28:52 +01:00
|
|
|
virtualisation.memorySize = 2048;
|
2021-05-26 16:57:56 +02:00
|
|
|
virtualisation.diskSize = 8000;
|
2019-01-02 09:54:46 +01:00
|
|
|
};
|
|
|
|
testScript = ''
|
2021-01-21 23:54:53 +01:00
|
|
|
machine.fail("curl --fail localhost:8000")
|
2020-03-02 11:13:47 +01:00
|
|
|
machine.succeed("docker --version")
|
|
|
|
|
|
|
|
# Tests
|
|
|
|
# - arion up
|
|
|
|
# - arion down
|
|
|
|
# - examples/minimal
|
|
|
|
with subtest("minimal"):
|
|
|
|
machine.succeed(
|
|
|
|
"rm -rf work && cp -frT ${../../examples/minimal} work && cd work && NIX_PATH=nixpkgs='${pkgs.path}' arion up -d"
|
|
|
|
)
|
2021-01-21 23:54:53 +01:00
|
|
|
machine.wait_until_succeeds("curl --fail localhost:8000")
|
2020-03-02 11:13:47 +01:00
|
|
|
machine.succeed(
|
|
|
|
"cd work && NIX_PATH=nixpkgs='${pkgs.path}' arion down"
|
|
|
|
)
|
2021-01-21 23:54:53 +01:00
|
|
|
machine.wait_until_fails("curl --fail localhost:8000")
|
2020-03-02 11:13:47 +01:00
|
|
|
|
2021-05-31 15:14:24 +02:00
|
|
|
# Tests
|
|
|
|
# - running same image again doesn't require a `docker load`
|
|
|
|
with subtest("docker load only once"):
|
|
|
|
# We assume image loading relies on the `docker images` and `docker load` commands, so this should fail
|
|
|
|
machine.fail(
|
|
|
|
"export REAL_DOCKER=$(which docker); rm -rf work && cp -frT ${../../examples/minimal} work && cd work && NIX_PATH=nixpkgs='${pkgs.path}' PATH=\"${pkgs.writeScriptBin "docker" ''
|
|
|
|
#!${pkgs.runtimeShell} -eu
|
|
|
|
echo 1>&2 "This failure is expected. Args were" "$@"
|
|
|
|
echo "$@" >/tmp/docker-args
|
|
|
|
exit 1
|
|
|
|
''}/bin:$PATH\" arion up -d"
|
|
|
|
)
|
|
|
|
machine.succeed(
|
|
|
|
"export REAL_DOCKER=$(which docker); rm -rf work && cp -frT ${../../examples/minimal} work && cd work && NIX_PATH=nixpkgs='${pkgs.path}' PATH=\"${pkgs.writeScriptBin "docker" ''
|
|
|
|
#!${pkgs.runtimeShell} -eu
|
|
|
|
case $1 in
|
|
|
|
load)
|
|
|
|
echo 1>&2 "arion must not docker load when upping the same deployment for the second time"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
images)
|
|
|
|
echo 1>&2 "execing docker to list images"
|
|
|
|
exec $REAL_DOCKER "$@"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo 1>&2 "Unknown docker invocation. This may be a shortcoming of this docker mock."
|
|
|
|
echo 1>&2 "Invocation: docker" "$@"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
''}/bin:$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")
|
|
|
|
|
|
|
|
|
2021-04-20 10:31:09 +02:00
|
|
|
# Tests
|
|
|
|
# - examples/flake
|
|
|
|
# This _test_ doesn't work because flake-compat fetches the github
|
|
|
|
# tarballs without sha256 and/or Nix doesn't consult the store before
|
|
|
|
# downloading.
|
|
|
|
# See https://github.com/edolstra/flake-compat/pull/12
|
|
|
|
# with subtest("flake"):
|
|
|
|
# machine.succeed(
|
|
|
|
# "rm -rf work && cp -frT ''${../../examples/flake} work && cd work && NIX_PATH= arion up -d"
|
|
|
|
# )
|
|
|
|
# machine.wait_until_succeeds("curl --fail localhost:8000")
|
|
|
|
# machine.succeed("cd work && NIX_PATH= arion down")
|
|
|
|
# machine.wait_until_fails("curl --fail localhost:8000")
|
|
|
|
|
2021-05-26 16:57:56 +02:00
|
|
|
${optionalString haveSystemd ''
|
2020-03-02 11:13:47 +01:00
|
|
|
# Tests
|
|
|
|
# - arion exec
|
|
|
|
# - examples/full-nixos
|
|
|
|
with subtest("full-nixos"):
|
|
|
|
machine.succeed(
|
|
|
|
"rm -rf work && cp -frT ${../../examples/full-nixos} work && cd work && NIX_PATH=nixpkgs='${pkgs.path}' arion up -d"
|
|
|
|
)
|
2021-01-21 23:54:53 +01:00
|
|
|
machine.wait_until_succeeds("curl --fail localhost:8000")
|
2020-03-02 11:13:47 +01:00
|
|
|
|
|
|
|
machine.succeed(
|
|
|
|
"""
|
|
|
|
set -eux -o pipefail
|
|
|
|
cd work
|
|
|
|
export NIX_PATH=nixpkgs='${pkgs.path}'
|
|
|
|
echo 'target=world; echo Hello $target; exit' \
|
|
|
|
| script 'arion exec webserver' \
|
|
|
|
| grep 'Hello world'
|
|
|
|
"""
|
|
|
|
),
|
|
|
|
|
|
|
|
machine.succeed(
|
|
|
|
"cd work && NIX_PATH=nixpkgs='${pkgs.path}' arion down"
|
|
|
|
)
|
2021-01-21 23:54:53 +01:00
|
|
|
machine.wait_until_fails("curl --fail localhost:8000")
|
2021-05-26 16:57:56 +02:00
|
|
|
''}
|
2020-03-02 11:13:47 +01:00
|
|
|
|
|
|
|
# Tests
|
|
|
|
# - examples/nixos-unit
|
|
|
|
with subtest("nixos-unit"):
|
|
|
|
machine.succeed(
|
|
|
|
"rm -rf work && cp -frT ${../../examples/nixos-unit} work && cd work && NIX_PATH=nixpkgs='${pkgs.path}' arion up -d"
|
|
|
|
)
|
2021-01-21 23:54:53 +01:00
|
|
|
machine.wait_until_succeeds("curl --fail localhost:8000")
|
2020-03-02 11:13:47 +01:00
|
|
|
machine.succeed(
|
|
|
|
"cd work && NIX_PATH=nixpkgs='${pkgs.path}' arion down"
|
|
|
|
)
|
2021-01-21 23:54:53 +01:00
|
|
|
machine.wait_until_fails("curl --fail localhost:8000")
|
2021-01-21 23:53:37 +01:00
|
|
|
|
|
|
|
# Tests
|
|
|
|
# - examples/traefik
|
|
|
|
# - labels
|
|
|
|
with subtest("traefik"):
|
|
|
|
machine.succeed(
|
|
|
|
"rm -rf work && cp -frT ${../../examples/traefik} work && cd work && NIX_PATH=nixpkgs='${pkgs.path}' arion up -d"
|
|
|
|
)
|
2021-01-21 23:54:53 +01:00
|
|
|
machine.wait_until_succeeds("curl --fail nix-docs.localhost")
|
2021-01-21 23:53:37 +01:00
|
|
|
machine.succeed(
|
|
|
|
"cd work && NIX_PATH=nixpkgs='${pkgs.path}' arion down"
|
|
|
|
)
|
2021-01-21 23:54:53 +01:00
|
|
|
machine.wait_until_fails("curl --fail nix-docs.localhost")
|
2019-01-02 09:54:46 +01:00
|
|
|
'';
|
|
|
|
}
|