From 224da824afa246fb8b55d7aa625767b9678af506 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 13 Jan 2024 20:06:08 +0000 Subject: [PATCH] add configurable container name --- README.md | 8 ++++---- src/manage.py | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 34e8fe5..99a237a 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,14 @@ This is a helper container for traefik. It can add, remove and update services. ## Usage -DO NOT CHANGE: `/home/config.yml` +### Add command alias ```bash -docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /home/traefik/data/config.tml:/home/config.yml fascinated/traefik-helper:latest python src/manage.py +alias traefik-helper='docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /home/traefik/data/config.yml:/app/config.yml -e CONTAINER_NAME=traefik fascinated/traefik-helper:latest python src/manage.py' ``` -**Example Add** +### Add service ```bash -docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /home/traefik/data/config.tml:/home/config.yml fascinated/traefik-helper:latest python src/manage.py add test test.fascinated.cc http://10.0.0.10 +traefik-helper add [name] [domain] [service url] ``` diff --git a/src/manage.py b/src/manage.py index 71ed070..59a9264 100644 --- a/src/manage.py +++ b/src/manage.py @@ -5,10 +5,13 @@ import os # Variables configFile = "./config.yml" +containerName = "traefik" # Are we running in a Docker container? if os.environ.get("CONFIG_FILE"): configFile = os.environ.get("CONFIG_FILE") +if os.environ.get("CONTAINER_NAME"): + containerName = os.environ.get("CONTAINER_NAME") # DO NOT TOUCH commands = ["add", "remove", "list"] @@ -32,11 +35,13 @@ routers = http["routers"] services = http["services"] def restartTraefik(): - print("Restarting Traefik...") + print("Restarting Traefik, please wait this can take a while...") # Restart Traefik in the base directory subprocess.run(["docker", "restart", "traefik"]) + print("Traefik restarted!") + def addDomain(name, domain, serviceHost): # Check if name already exists if name in routers: