python.pkgs.pyqt5: 5.14.2 -> 5.15.0
[NixPkgs.git] / nixos / tests / traefik.nix
blob0e21a7cf8437f43d1c0ebe5db5b81b5a956d5928
1 # Test Traefik as a reverse proxy of a local web service
2 # and a Docker container.
3 import ./make-test-python.nix ({ pkgs, ... }: {
4   name = "traefik";
5   meta = with pkgs.stdenv.lib.maintainers; {
6     maintainers = [ joko ];
7   };
9   nodes = {
10     client = { config, pkgs, ... }: {
11       environment.systemPackages = [ pkgs.curl ];
12     };
13     traefik = { config, pkgs, ... }: {
14       docker-containers.nginx = {
15         extraDockerOptions = [
16           "-l" "traefik.enable=true"
17           "-l" "traefik.http.routers.nginx.entrypoints=web"
18           "-l" "traefik.http.routers.nginx.rule=Host(`nginx.traefik.test`)"
19         ];
20         image = "nginx-container";
21         imageFile = pkgs.dockerTools.examples.nginx;
22       };
24       networking.firewall.allowedTCPPorts = [ 80 ];
26       services.traefik = {
27         enable = true;
29         dynamicConfigOptions = {
30           http.routers.simplehttp = {
31             rule = "Host(`simplehttp.traefik.test`)";
32             entryPoints = [ "web" ];
33             service = "simplehttp";
34           };
36           http.services.simplehttp = {
37             loadBalancer.servers = [{
38               url = "http://127.0.0.1:8000";
39             }];
40           };
41         };
43         staticConfigOptions = {
44           global = {
45             checkNewVersion = false;
46             sendAnonymousUsage = false;
47           };
49           entryPoints.web.address = ":80";
51           providers.docker.exposedByDefault = false;
52         };
53       };
55       systemd.services.simplehttp = {
56         script = "${pkgs.python3}/bin/python -m http.server 8000";
57         serviceConfig.Type = "simple";
58         wantedBy = [ "multi-user.target" ];
59       };
61       users.users.traefik.extraGroups = [ "docker" ];
62     };
63   };
65   testScript = ''
66     start_all()
68     traefik.wait_for_unit("docker-nginx.service")
69     traefik.wait_until_succeeds("docker ps | grep nginx-container")
70     traefik.wait_for_unit("simplehttp.service")
71     traefik.wait_for_unit("traefik.service")
72     traefik.wait_for_open_port(80)
73     traefik.wait_for_unit("multi-user.target")
75     client.wait_for_unit("multi-user.target")
77     with subtest("Check that a container can be reached via Traefik"):
78         assert "Hello from NGINX" in client.succeed(
79             "curl -sSf -H Host:nginx.traefik.test http://traefik/"
80         )
82     with subtest("Check that dynamic configuration works"):
83         assert "Directory listing for " in client.succeed(
84             "curl -sSf -H Host:simplehttp.traefik.test http://traefik/"
85         )
86   '';