1 # Test Traefik as a reverse proxy of a local web service
2 # and a Docker container.
3 import ./make-test-python.nix ({ pkgs, ... }: {
5 meta = with pkgs.lib.maintainers; {
6 maintainers = [ joko ];
10 client = { config, pkgs, ... }: {
11 environment.systemPackages = [ pkgs.curl ];
13 traefik = { config, pkgs, ... }: {
14 virtualisation.oci-containers = {
21 "traefik.http.routers.nginx.entrypoints=web"
23 "traefik.http.routers.nginx.rule=Host(`nginx.traefik.test`)"
25 image = "nginx-container";
26 imageFile = pkgs.dockerTools.examples.nginx;
30 networking.firewall.allowedTCPPorts = [ 80 ];
35 dynamicConfigOptions = {
36 http.routers.simplehttp = {
37 rule = "Host(`simplehttp.traefik.test`)";
38 entryPoints = [ "web" ];
39 service = "simplehttp";
42 http.services.simplehttp = {
43 loadBalancer.servers = [{
44 url = "http://127.0.0.1:8000";
49 staticConfigOptions = {
51 checkNewVersion = false;
52 sendAnonymousUsage = false;
55 entryPoints.web.address = ":80";
57 providers.docker.exposedByDefault = false;
61 systemd.services.simplehttp = {
62 script = "${pkgs.python3}/bin/python -m http.server 8000";
63 serviceConfig.Type = "simple";
64 wantedBy = [ "multi-user.target" ];
67 users.users.traefik.extraGroups = [ "docker" ];
74 traefik.wait_for_unit("docker-nginx.service")
75 traefik.wait_until_succeeds("docker ps | grep nginx-container")
76 traefik.wait_for_unit("simplehttp.service")
77 traefik.wait_for_unit("traefik.service")
78 traefik.wait_for_open_port(80)
79 traefik.wait_for_unit("multi-user.target")
81 client.wait_for_unit("multi-user.target")
83 client.wait_until_succeeds("curl -sSf -H Host:nginx.traefik.test http://traefik/")
85 with subtest("Check that a container can be reached via Traefik"):
86 assert "Hello from NGINX" in client.succeed(
87 "curl -sSf -H Host:nginx.traefik.test http://traefik/"
90 with subtest("Check that dynamic configuration works"):
91 assert "Directory listing for " in client.succeed(
92 "curl -sSf -H Host:simplehttp.traefik.test http://traefik/"