summaryrefslogtreecommitdiffstats
path: root/nixos/tests/git-pages.nix
blob: c7e19b7cf846451f30ad6e3322a1bc5de3dc58ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{ pkgs, ... }:
{
  name = "git-pages-modular-service";

  nodes.machine = { pkgs, ... }: {
    environment.systemPackages = [ pkgs.curl ];

    system.services.git-pages = {
      imports = [ pkgs.git-pages.services.default ];
      git-pages = {
        settings.server = {
          pages = "tcp/:3000";
          caddy = "tcp/:3001";
          metrics = "tcp/:3002";
        };
      };
      systemd.service.environment.PAGES_INSECURE = "1";
    };

    services.caddy = {
      enable = true;
      configFile = pkgs.writeText "Caddyfile" ''
        {
            admin off
            persist_config off
            auto_https disable_redirects
            on_demand_tls {
                permission http http://localhost:3001
            }
        }
        https://, http:// {
          tls {
              on_demand
          }
          reverse_proxy http://localhost:3000
        }
      '';
    };

    networking.firewall.allowedTCPPorts = [ 80 ];
  };

  testScript =
    let
      testSite = pkgs.runCommand "git-pages-testsite.tar" { } ''
        echo It works! > index.html
        tar cvf $out index.html
      '';
    in
    ''
      start_all()

      machine.wait_for_unit("caddy.service")
      machine.wait_for_open_port(80)
      machine.wait_for_unit("git-pages.service")
      machine.wait_for_open_port(3001)
      machine.wait_for_open_port(3002)
      machine.fail("curl -f http://localhost/.git-pages/health")
      machine.succeed("curl -f http://localhost/ -X PUT --data-binary @${testSite} --header 'Content-Type: application/x-tar'")
      machine.wait_until_succeeds("test -f /var/lib/git-pages/data/site/localhost/.index")
      machine.succeed("curl -f http://localhost/.git-pages/health")
      machine.succeed("curl -f http://localhost/ | grep -F 'It works!'")
      machine.succeed("curl -f http://localhost:3002/metrics")
    '';
}