Skip to content

Commit bbe097b

Browse files
committed
checkmate-server: init at 3.5.1
1 parent 93f4025 commit bbe097b

File tree

6 files changed

+8634
-0
lines changed

6 files changed

+8634
-0
lines changed

nixos/modules/module-list.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,7 @@
999999
./services/monitoring/bosun.nix
10001000
./services/monitoring/cadvisor.nix
10011001
./services/monitoring/certspotter.nix
1002+
./services/monitoring/checkmate-server.nix
10021003
./services/monitoring/cockpit.nix
10031004
./services/monitoring/collectd.nix
10041005
./services/monitoring/das_watchdog.nix
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
{
2+
config,
3+
pkgs,
4+
lib,
5+
...
6+
}:
7+
let
8+
cfg = config.services.checkmate-server;
9+
10+
inherit (lib)
11+
mkEnableOption
12+
mkPackageOption
13+
mkIf
14+
mkOption
15+
types
16+
isPath
17+
;
18+
19+
assertStringPath =
20+
optionName: value:
21+
if isPath value then
22+
throw ''
23+
services.checkmate-server.${optionName}:
24+
${toString value}
25+
is a Nix path, but should be a string, since Nix
26+
paths are copied into the world-readable Nix store.
27+
''
28+
else
29+
value;
30+
in
31+
{
32+
options = {
33+
services.checkmate-server = {
34+
enable = mkEnableOption "the Checkmate monitoring server";
35+
36+
package = mkPackageOption pkgs "checkmate-server" { };
37+
38+
vhostName = mkOption {
39+
type = types.str;
40+
default = "checkmate-server";
41+
description = "Name of the nginx vhost.";
42+
};
43+
44+
enableLocalDB = mkEnableOption "a local MongoDB instance";
45+
46+
settings = {
47+
clientHost = mkOption {
48+
type = types.str;
49+
default = "http://127.0.0.1";
50+
description = "Frontend Host URI.";
51+
};
52+
53+
origin = mkOption {
54+
type = types.str;
55+
default = "localhost";
56+
description = ''
57+
Origin where requests to server originate from, for CORS purposes.
58+
'';
59+
};
60+
61+
port = mkOption {
62+
type = types.port;
63+
default = 52345;
64+
description = "Port the Checkmate backend should listen on.";
65+
};
66+
67+
logLevel = mkOption {
68+
type = types.enum [
69+
"debug"
70+
"info"
71+
"warn"
72+
"error"
73+
];
74+
default = "info";
75+
description = "Debug level, can be one of: debug, info, warn, error.";
76+
};
77+
78+
tokenTTL = mkOption {
79+
type = types.str;
80+
default = "1h";
81+
description = ''
82+
Time for token to live in vercel/ms format, see: https://github.com/vercel/ms.
83+
'';
84+
};
85+
86+
JWTSecretFile = mkOption {
87+
type = types.path;
88+
apply = assertStringPath "settings.JWTSecretFile";
89+
description = ''
90+
Path to a file that contains the secret to sign web requests using JSON Web Tokens.
91+
'';
92+
};
93+
};
94+
95+
mongodbUri = mkOption {
96+
type = types.str;
97+
default = "mongodb://127.0.0.1:27017/uptime_db";
98+
description = ''
99+
MongoDB connection string.
100+
See http://docs.mongodb.org/manual/reference/connection-string/ for details.
101+
'';
102+
};
103+
};
104+
};
105+
106+
config = mkIf cfg.enable {
107+
108+
services.mongodb = mkIf cfg.enableLocalDB {
109+
enable = true;
110+
};
111+
112+
systemd.services.checkmate-backend = {
113+
description = "Checkmate backend daemon";
114+
wantedBy = [ "multi-user.target" ];
115+
after = [ "network.target" ] ++ lib.optionals cfg.enableLocalDB [ "mongodb.service" ];
116+
startLimitIntervalSec = 60;
117+
startLimitBurst = 3;
118+
environment = {
119+
CLIENT_HOST = cfg.settings.clientHost;
120+
LOG_LEVEL = cfg.settings.logLevel;
121+
DB_CONNECTION_STRING = cfg.mongodbUri;
122+
ORIGIN = cfg.settings.origin;
123+
TOKEN_TTL = cfg.settings.tokenTTL;
124+
PORT = toString cfg.settings.port;
125+
};
126+
serviceConfig = {
127+
LoadCredential = [ "JWT_SECRET:${cfg.settings.JWTSecretFile}" ];
128+
PrivateDevices = true;
129+
LimitCORE = 0;
130+
KillSignal = "SIGINT";
131+
TimeoutStopSec = "30s";
132+
Restart = "on-failure";
133+
DynamicUser = true;
134+
};
135+
script = ''
136+
set -eou pipefail
137+
shopt -s inherit_errexit
138+
139+
JWT_SECRET="$(<"$CREDENTIALS_DIRECTORY/JWT_SECRET")" \
140+
${cfg.package}/startserver ${cfg.package}/backend/index.js
141+
'';
142+
};
143+
144+
services.nginx.virtualHosts.${cfg.vhostName} = {
145+
locations."/" = {
146+
root = "${cfg.package}/public";
147+
index = "index.html index.htm";
148+
tryFiles = "$uri $uri/ /index.html";
149+
};
150+
locations."/api/" = {
151+
proxyPass = "http://127.0.0.1:${toString cfg.settings.port}/api/";
152+
proxyWebsockets = true;
153+
};
154+
locations."/api-docs/" = {
155+
proxyPass = "http://127.0.0.1:${toString cfg.settings.port}/api-docs/";
156+
proxyWebsockets = true;
157+
};
158+
};
159+
160+
};
161+
}

nixos/tests/all-tests.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ in
354354
cfssl = runTestOn [ "aarch64-linux" "x86_64-linux" ] ./cfssl.nix;
355355
cgit = runTest ./cgit.nix;
356356
charliecloud = runTest ./charliecloud.nix;
357+
checkmate-server = runTest ./checkmate-server.nix;
357358
chhoto-url = runTest ./chhoto-url.nix;
358359
chromadb = runTest ./chromadb.nix;
359360
chromium = (handleTestOn [ "aarch64-linux" "x86_64-linux" ] ./chromium.nix { }).stable or { };

nixos/tests/checkmate-server.nix

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Run this test with NIXPKGS_ALLOW_UNFREE=1
2+
{ lib, ... }:
3+
{
4+
name = "checkmate-server";
5+
meta.maintainers = with lib.maintainers; [ robertjakub ];
6+
7+
nodes.machine =
8+
{ pkgs, ... }:
9+
{
10+
services.mongodb.package = pkgs.mongodb-ce;
11+
12+
services.checkmate-server = {
13+
enable = true;
14+
vhostName = "default";
15+
enableLocalDB = true;
16+
settings = {
17+
logLevel = "info";
18+
clientHost = "http://127.0.0.1";
19+
JWTSecretFile = "/run/checkmate-jwt";
20+
};
21+
};
22+
23+
services.nginx = {
24+
enable = true;
25+
recommendedProxySettings = true;
26+
};
27+
28+
};
29+
30+
testScript = ''
31+
machine.start()
32+
33+
machine.execute("echo \"JWTSecret\" > /run/checkmate-jwt && chmod 400 /run/checkmate-jwt")
34+
machine.wait_for_unit("checkmate-backend.service")
35+
machine.wait_for_open_port(52345)
36+
37+
machine.wait_until_succeeds("journalctl -o cat -u checkmate-backend.service | grep 'Server started on port:52345'")
38+
39+
machine.succeed("curl -sSfN http://127.0.0.1:52345/ | grep \"<title>Checkmate</title>\"")
40+
machine.succeed("curl -sSfN http://127.0.0.1:52345/api-docs/ | grep \"<title>Swagger UI</title>\"")
41+
machine.succeed("curl -sSfN http://127.0.0.1/ | grep \"<title>Checkmate</title>\"")
42+
machine.succeed("curl -sSfN http://127.0.0.1/api-docs/ | grep \"<title>Swagger UI</title>\"")
43+
44+
machine.shutdown()
45+
'';
46+
47+
}

0 commit comments

Comments
 (0)