-
Notifications
You must be signed in to change notification settings - Fork 75
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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" | ||
]; | ||
}; | ||
} | ||
); | ||
} | ||
|
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
''; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi,
keter is upstreamed as a module in nixpkgs:
https://github.com/NixOS/nixpkgs/blob/335958709c637736c44fdfde6f8b7ca5c6bc8da0/nixos/modules/services/web-servers/keter/default.nix#L4
There was a problem hiding this comment.
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,
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.