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.stdenv.lib.maintainers; {
6 maintainers = [ joko ];
10 client = { config, pkgs, ... }: {
11 environment.systemPackages = [ pkgs.curl ];
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`)"
20 image = "nginx-container";
21 imageFile = pkgs.dockerTools.examples.nginx;
24 networking.firewall.allowedTCPPorts = [ 80 ];
29 dynamicConfigOptions = {
30 http.routers.simplehttp = {
31 rule = "Host(`simplehttp.traefik.test`)";
32 entryPoints = [ "web" ];
33 service = "simplehttp";
36 http.services.simplehttp = {
37 loadBalancer.servers = [{
38 url = "http://127.0.0.1:8000";
43 staticConfigOptions = {
45 checkNewVersion = false;
46 sendAnonymousUsage = false;
49 entryPoints.web.address = ":80";
51 providers.docker.exposedByDefault = false;
55 systemd.services.simplehttp = {
56 script = "${pkgs.python3}/bin/python -m http.server 8000";
57 serviceConfig.Type = "simple";
58 wantedBy = [ "multi-user.target" ];
61 users.users.traefik.extraGroups = [ "docker" ];
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/"
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/"