Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add first integrated test with nixosTest VM #307

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ cabal.sandbox.config
*.sublime-*
dist-newstyle/
.pre-commit-config.yaml
result
.nixos-test-history
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
stylish-haskell.enable = true;
};
};

integratedTests = pkgs.callPackage ./vm.nix { inherit self; };
};

devShells.default = pkgs.haskellPackages.shellFor {
Expand Down
71 changes: 71 additions & 0 deletions keter.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{ config, lib, pkgs, ... }:

let
cfg = config.services.keter-ng;

in
{
options.services.keter-ng = {
enable = lib.mkEnableOption (lib.mdDoc ''
keter — a web app deployment manager.
'');

root = lib.mkOption {
type = lib.types.str;
default = "/opt/keter";
description = lib.mdDoc "Mutable state folder for keter";
};

package = lib.mkOption {
type = lib.types.package;
default = pkgs.haskellPackages.keter;
defaultText = lib.literalExpression "pkgs.haskellPackages.keter";
description = lib.mdDoc "The keter package to be used";
};

globalKeterConfig = lib.mkOption {
type = lib.types.str;
default = "";
description = lib.mdDoc ''
A custom YAML configuration for Keter. This content will be directly
written to the `keter-config.yml` file without modification. See
<https://github.com/snoyberg/keter/blob/master/etc/keter-config.yaml>
for reference.
'';
};
};

config = lib.mkIf cfg.enable (
let
incoming = "${cfg.root}/incoming";

globalKeterConfigFile = pkgs.writeTextFile {
name = "keter-config.yml";
text = cfg.globalKeterConfig;
};
in
{
systemd.services.keter-ng = {
description = "keter app loader";
script = ''
set -xe
mkdir -p ${incoming}
${lib.getExe cfg.package} ${globalKeterConfigFile};
'';
wantedBy = [ "multi-user.target" "nginx.service" ];

serviceConfig = {
Restart = "always";
RestartSec = "10s";
};

after = [
"network.target"
"local-fs.target"
"postgresql.service"
];
};
}
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did see that, but I don't think the module definition is quite right for a couple of reasons. From memory,

  1. It doesn't support all of the possible configuration options for the global configuration
  2. It concerns itself with the bundle configuration, when it shouldn't

The comment describing the indirection is already a good hint that this is trying to do too much. The easiest thing to do is to delegate configuring this correctly to the user.


37 changes: 37 additions & 0 deletions vm.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{ testers, self }:

testers.nixosTest {
name = "vm-test";

nodes.server = { ... }: {

imports = [
./keter.nix
];

nix.settings = {
experimental-features = [ "nix-command" "flakes" ];
auto-optimise-store = true;
};

services.keter-ng = {
enable = true;
package = self.packages.x86_64-linux.keter;
globalKeterConfig = ''
root: /opt/keter
rotate-logs: false
listeners:
- host: "*4"
port: 80
'';
};

};

testScript = ''
server.start()
server.wait_for_unit("keter-ng.service")
server.wait_for_open_port(80)
server.succeed("curl localhost")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is able to distinct between bundle content and the default "hello keter" welcome message

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right — it won't. This test doesn't exercise bundle loading at all. We can add more tests later for exercising various bundle loading scenarios.

'';
}
Loading