-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add first integrated test with nixosTest VM
This is a first pass at adding integrated tests for keter. This works by spinning up a NixOS virtual machine, running keter as a systemd service on it, and probing it with an HTTP request. This can even be run on MacOS interactively, like this: ``` nix run \ .#checks.x86_64-darwin.integratedTests.driverInteractive \ -- --interactive ```
- Loading branch information
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,5 @@ cabal.sandbox.config | |
*.sublime-* | ||
dist-newstyle/ | ||
.pre-commit-config.yaml | ||
result | ||
.nixos-test-history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
]; | ||
}; | ||
} | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
''; | ||
} |