From 32b00781b43f000db745ab14e7c7ead616bd123c Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 21 Jan 2021 23:43:03 +0100 Subject: [PATCH] examples/traefik: Make pure --- examples/traefik/arion-compose.nix | 47 +++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/examples/traefik/arion-compose.nix b/examples/traefik/arion-compose.nix index 03cacb6..b6c6f7d 100644 --- a/examples/traefik/arion-compose.nix +++ b/examples/traefik/arion-compose.nix @@ -1,26 +1,47 @@ -{ pkgs, ... }: { +/* + + An example of + - traefik HTTP reverse proxy + - minimal images + - routing via docker labels + + Run `arion up -d` and open http://nix-docs.localhost/ + + */ +{ lib, pkgs, ... }: { config.services = { - traefik.service = { - image = "traefik:v2.4"; - container_name = "traefik"; - command = [ + traefik = { + image.command = [ + "${pkgs.traefik}/bin/traefik" "--api.insecure=true" "--providers.docker=true" "--providers.docker.exposedbydefault=false" "--entrypoints.web.address=:80" ]; - ports = [ "80:80" "8080:8080" ]; - volumes = [ "/var/run/docker.sock:/var/run/docker.sock:ro" ]; + service = { + container_name = "traefik"; + stop_signal = "SIGINT"; + ports = [ "80:80" "8080:8080" ]; + volumes = [ "/var/run/docker.sock:/var/run/docker.sock:ro" ]; + }; }; - whoami.service = { - image = "traefik/whoami"; - container_name = "simple-service"; - labels = { + nix-docs = { + image.command = ["${pkgs.writeScript "entrypoint" '' + #!${pkgs.bash}/bin/bash + cd ${pkgs.nix.doc}/share/doc/nix/manual + ${pkgs.python3}/bin/python -m http.server + ''}"]; + service.container_name = "simple-service"; + service.ports = [ + "8000:8000" # host:container + ]; + service.stop_signal = "SIGINT"; + service.labels = { "traefik.enable" = "true"; - "traefik.http.routers.whoami.rule" = "Host(`whoami.localhost`)"; - "traefik.http.routers.whoami.entrypoints" = "web"; + "traefik.http.routers.nix-docs.rule" = "Host(`nix-docs.localhost`)"; + "traefik.http.routers.nix-docs.entrypoints" = "web"; }; }; };