-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,309 additions
and
832 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# ruff format | ||
706580fbb393467063c6a372a902172203bfd382 |
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,52 @@ | ||
# Copyright © 2024 Brrr Authors | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published | ||
# by the Free Software Foundation, version 3 of the License. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
# A NixOS module for a brrr demo binary. N.B.: It does not contain any | ||
# dependencies; this is just the demo script. | ||
# | ||
# Inspired by | ||
# https://blakesmith.me/2024/03/02/running-nixos-tests-with-flakes.html | ||
|
||
{ lib, config, pkgs, ... }: { | ||
options.services.brrr-demo = let | ||
native = import ./brrr-demo.options.nix { inherit lib pkgs; }; | ||
mod1 = { options = native; }; | ||
mod2 = { | ||
options.enable = lib.mkEnableOption "brrr-demo"; | ||
}; | ||
in lib.mkOption { | ||
description = "Brrr demo service configuration"; | ||
type = lib.types.submoduleWith { | ||
modules = [ mod1 mod2 ]; | ||
}; | ||
default = {}; | ||
}; | ||
|
||
config = let | ||
cfg = config.services.brrr-demo; | ||
in lib.mkIf cfg.enable { | ||
|
||
systemd.services.brrr-demo = { | ||
inherit (cfg) environment; | ||
after = [ "network.target" ]; | ||
wantedBy = [ "multi-user.target" ]; | ||
script = '' | ||
exec ${lib.getExe cfg.package} ${lib.escapeShellArgs cfg.args} | ||
''; | ||
serviceConfig = { | ||
Type = "simple"; | ||
}; | ||
}; | ||
}; | ||
} |
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,43 @@ | ||
# Copyright © 2024 Brrr Authors | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published | ||
# by the Free Software Foundation, version 3 of the License. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
# Module options for any brrr-demo service. These are shared between the actual | ||
# NixOS module and the services-flake module. N.B.: pkgs must have a brrr-demo | ||
# derivation available, from an overlay. | ||
# | ||
# I think I’m still missing one layer of submodule use here--these are just the | ||
# raw options for the caller to directly import, but I’m sure there’s some way | ||
# to use submodule for this instead? Maybe... deferred? This works for now but | ||
# TBD. | ||
|
||
{ lib, pkgs }: | ||
|
||
with lib.types; { | ||
# You’ll want to override this unless you use an overlay | ||
package = lib.mkPackageOption pkgs "brrr-demo" { }; | ||
args = lib.mkOption { | ||
default = []; | ||
type = listOf str; | ||
}; | ||
environment = lib.mkOption { | ||
type = types.attrsOf types.str; | ||
default = { }; | ||
example = { | ||
AWS_ENDPOINT_URL = "http://localhost:12345"; | ||
}; | ||
description = '' | ||
Extra environment variables passed to the `brrr-demo` process. | ||
''; | ||
}; | ||
} |
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,110 @@ | ||
# Copyright © 2024 Brrr Authors | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published | ||
# by the Free Software Foundation, version 3 of the License. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
# Inspired by | ||
# https://blakesmith.me/2024/03/02/running-nixos-tests-with-flakes.html | ||
|
||
{ self, pkgs }: | ||
|
||
# Distributed test across multiple VMs, so there’s still some room for bugs to | ||
# creep into the actual demo. Both are nice to have so we should probably add a | ||
# test that replicates the actual demo as closely as possible to catch any | ||
# errors there. | ||
pkgs.testers.runNixOSTest { | ||
name = "brrr-test"; | ||
|
||
nodes.datastores = { config, pkgs, ... }: { | ||
imports = [ | ||
# Not going to export and dogfood this--it’s just local only | ||
./dynamodb.module.nix | ||
]; | ||
services.redis.servers.main = { | ||
enable = true; | ||
port = 6379; | ||
openFirewall = true; | ||
bind = null; | ||
logLevel = "debug"; | ||
settings.protected-mode = "no"; | ||
}; | ||
services.dynamodb = { | ||
enable = true; | ||
openFirewall = true; | ||
}; | ||
}; | ||
nodes.server = { config, pkgs, ... }: { | ||
imports = [ | ||
self.nixosModules.brrr-demo | ||
]; | ||
networking.firewall.allowedTCPPorts = [ 8080 ]; | ||
services.brrr-demo = { | ||
enable = true; | ||
package = self.packages.${pkgs.system}.brrr-demo; | ||
args = [ "server" ]; | ||
environment = { | ||
BRRR_DEMO_LISTEN_HOST = "0.0.0.0"; | ||
BRRR_DEMO_REDIS_URL = "redis://datastores:6379"; | ||
AWS_DEFAULT_REGION = "foo"; | ||
AWS_ENDPOINT_URL = "http://datastores:8000"; | ||
AWS_ACCESS_KEY_ID = "foo"; | ||
AWS_SECRET_ACCESS_KEY = "bar"; | ||
}; | ||
}; | ||
}; | ||
nodes.worker = { config, pkgs, ... }: { | ||
imports = [ | ||
self.nixosModules.brrr-demo | ||
]; | ||
services.brrr-demo = { | ||
enable = true; | ||
package = self.packages.${pkgs.system}.brrr-demo; | ||
args = [ "worker" ]; | ||
environment = { | ||
BRRR_DEMO_REDIS_URL = "redis://datastores:6379"; | ||
AWS_DEFAULT_REGION = "foo"; | ||
AWS_ENDPOINT_URL = "http://datastores:8000"; | ||
AWS_ACCESS_KEY_ID = "foo"; | ||
AWS_SECRET_ACCESS_KEY = "bar"; | ||
}; | ||
}; | ||
}; | ||
# Separate node entirely just for the actual testing | ||
nodes.tester = { config, pkgs, ... }: { | ||
environment.systemPackages = let | ||
test-script = pkgs.writeShellApplication { | ||
name = "test-brrr-demo"; | ||
runtimeInputs = with pkgs; [ curl jq ]; | ||
# 😂 | ||
text = '' | ||
eval "$(curl --fail -sSL "http://server:8080/hello?greetee=Jim" | jq '. == {status: "ok", result: "Hello, Jim!"}')" | ||
''; | ||
}; | ||
in [ | ||
test-script | ||
]; | ||
}; | ||
|
||
globalTimeout = 2 * 60; | ||
|
||
testScript = '' | ||
# Start first because it's a dependency | ||
datastores.wait_for_unit("default.target") | ||
# Server initializes the stores | ||
server.wait_for_unit("default.target") | ||
worker.wait_for_unit("default.target") | ||
tester.wait_for_unit("default.target") | ||
server.wait_for_open_port(8080) | ||
# N.B. the heresy | ||
tester.wait_until_succeeds("test-brrr-demo") | ||
''; | ||
} |
Oops, something went wrong.