Skip to content

Commit e5e1b82

Browse files
committed
chore: simplify system manager tests
Move ubuntu docker image to its own package. Create one test for all system modules.
1 parent 61e6200 commit e5e1b82

File tree

7 files changed

+108
-131
lines changed

7 files changed

+108
-131
lines changed

nix/packages/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
ansible-test = pkgs.callPackage ./ansible-test.nix { };
3535
cleanup-ami = pkgs.callPackage ./cleanup-ami.nix { };
3636
dbmate-tool = pkgs.callPackage ./dbmate-tool.nix { inherit (self.supabase) defaults; };
37+
docker-image-ubuntu = pkgs.callPackage ./docker-ubuntu.nix { };
3738
docs = pkgs.callPackage ./docs.nix { };
3839
supabase-groonga = pkgs.callPackage ./groonga { };
3940
local-infra-bootstrap = pkgs.callPackage ./local-infra-bootstrap.nix { };

nix/packages/docker-ubuntu.nix

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{ runCommand, dockerTools, xz, buildEnv }:
2+
let
3+
ubuntu-cloudimg =
4+
let
5+
cloudImg = builtins.fetchurl {
6+
url = "http://cloud-images-archive.ubuntu.com/releases/noble/release-20250430/ubuntu-24.04-server-cloudimg-amd64-root.tar.xz";
7+
sha256 = "sha256:0rfi3qqs0sqarixfic7pzjpx7d4vldv2d98c5zjv7b90mirznvf9";
8+
};
9+
in
10+
runCommand "ubuntu-cloudimg" { nativeBuildInputs = [ xz ]; } ''
11+
mkdir -p $out
12+
tar --exclude='dev/*' \
13+
--exclude='etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service' \
14+
--exclude='etc/systemd/system/multi-user.target.wants/systemd-resolved.service' \
15+
--exclude='usr/lib/systemd/system/tpm-udev.service' \
16+
--exclude='usr/lib/systemd/system/systemd-remount-fs.service' \
17+
--exclude='usr/lib/systemd/system/systemd-resolved.service' \
18+
--exclude='usr/lib/systemd/system/proc-sys-fs-binfmt_misc.automount' \
19+
--exclude='usr/lib/systemd/system/sys-kernel-*' \
20+
--exclude='var/lib/apt/lists/*' \
21+
-xJf ${cloudImg} -C $out
22+
rm $out/bin $out/lib $out/lib64 $out/sbin
23+
mkdir -p $out/run/systemd && echo 'docker' > $out/run/systemd/container
24+
mkdir $out/var/lib/apt/lists/partial
25+
'';
26+
in
27+
dockerTools.buildImage {
28+
name = "ubuntu-cloudimg";
29+
tag = "24.04";
30+
created = "now";
31+
extraCommands = ''
32+
ln -s usr/bin
33+
ln -s usr/lib
34+
ln -s usr/lib64
35+
ln -s usr/sbin
36+
'';
37+
copyToRoot = buildEnv {
38+
name = "image-root";
39+
pathsToLink = [ "/" ];
40+
paths = [ ubuntu-cloudimg ];
41+
};
42+
config.Cmd = [ "/lib/systemd/systemd" ];
43+
}

nix/systemModules/default.nix

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
{
2-
flake-parts-lib,
3-
withSystem,
4-
self,
52
...
63
}:
74
{
85
imports = [ ./tests ];
96
flake = {
10-
systemModules = {
11-
nginx = flake-parts-lib.importApply ./nginx.nix { inherit withSystem self; };
12-
};
7+
systemModules = { };
138
};
149
}

nix/systemModules/nginx.nix

Lines changed: 0 additions & 25 deletions
This file was deleted.

nix/systemModules/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def wait_for_target(host, target, timeout=60):
9292
result = host.run(f"systemctl is-active {target}")
9393
if result.rc == 0:
9494
return True
95-
time.sleep(1)
95+
time.sleep(0.2)
9696
return False
9797

9898

nix/systemModules/tests/default.nix

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,70 @@
11
{ self, ... }:
22
{
33
perSystem =
4-
{ lib, pkgs, ... }:
4+
{
5+
lib,
6+
pkgs,
7+
self',
8+
...
9+
}:
510
{
611
packages = lib.optionalAttrs (pkgs.stdenv.hostPlatform.isLinux) {
7-
check-system-manager-nginx = (import ./nginx.nix { inherit self pkgs; });
12+
check-system-manager =
13+
let
14+
lib = pkgs.lib;
15+
systemManagerConfig = self.inputs.system-manager.lib.makeSystemConfig {
16+
modules = [
17+
({
18+
services.nginx.enable = true;
19+
nixpkgs.hostPlatform = pkgs.system;
20+
})
21+
];
22+
};
23+
24+
dockerImageUbuntuWithTools =
25+
let
26+
tools = [ systemManagerConfig ];
27+
in
28+
pkgs.dockerTools.buildLayeredImage {
29+
name = "ubuntu-cloudimg-with-tools";
30+
tag = "0.2";
31+
created = "now";
32+
maxLayers = 30;
33+
fromImage = self'.packages.docker-image-ubuntu;
34+
compressor = "zstd";
35+
config = {
36+
Env = [
37+
"PATH=${lib.makeBinPath tools}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
38+
];
39+
Cmd = [ "/lib/systemd/systemd" ];
40+
};
41+
};
42+
in
43+
pkgs.writeShellApplication {
44+
name = "system-manager-test";
45+
passthru = {
46+
inherit systemManagerConfig dockerImageUbuntuWithTools;
47+
};
48+
runtimeInputs = with pkgs; [
49+
(python3.withPackages (
50+
ps: with ps; [
51+
requests
52+
pytest
53+
pytest-testinfra
54+
rich
55+
]
56+
))
57+
];
58+
text = ''
59+
export DOCKER_IMAGE=${dockerImageUbuntuWithTools.imageName}:${dockerImageUbuntuWithTools.imageTag}
60+
TEST_DIR=${./.}
61+
pytest -p no:cacheprovider -s -v "$@" $TEST_DIR --image-name=$DOCKER_IMAGE --image-path=${dockerImageUbuntuWithTools}
62+
'';
63+
meta = with pkgs.lib; {
64+
description = "Test deployment with system-manager";
65+
platforms = platforms.linux;
66+
};
67+
};
868
};
969
};
1070
}

nix/systemModules/tests/nginx.nix

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)