From 9bc1a334bec34bb6630c48f722c21eb4d256c1e4 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Sat, 10 Sep 2022 18:35:57 +0200 Subject: [PATCH] Separate nginx container --- podman/deploy.py | 40 +++++++++++++++------------------- podman/traefik/etc/dynamic.yml | 2 +- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/podman/deploy.py b/podman/deploy.py index ac4ea3a..aba6e9c 100755 --- a/podman/deploy.py +++ b/podman/deploy.py @@ -16,13 +16,13 @@ ADVLABDB_VOLUMES_DIR = VOLUMES_DIR / "advlabdb" ADVLABDB_REPO_DIR = ADVLABDB_VOLUMES_DIR / "repo" ADVLABDB_LOGS_DIR = ADVLABDB_VOLUMES_DIR / "logs" ADVLABDB_DATA_DIR = ADVLABDB_VOLUMES_DIR / "data" +# Nginx +NGINX_CONF_D_DIR = ADVLABDB_VOLUMES_DIR / "nginx/conf.d" # Traefik TRAEFIK_VOLUMES_DIR = VOLUMES_DIR / "traefik" TRAEFIK_ETC_DIR = TRAEFIK_VOLUMES_DIR / "etc" TRAEFIK_LOGS_DIR = TRAEFIK_VOLUMES_DIR / "logs" TRAEFIK_CERTS_DIR = TRAEFIK_VOLUMES_DIR / "certs" -# Nginx -NGINX_CONF_D_DIR = VOLUMES_DIR / "nginx/conf.d" # Systemd SYSTEMD_USER_DIR = Path.home() / ".config/systemd/user" @@ -37,11 +37,6 @@ parser.add_argument( action="store_true", help="Do not deploy the Traefik container.", ) -parser.add_argument( - "--skip-nginx", - action="store_true", - help="Do not deploy the Nginx container.", -) parser.add_argument( "-n", "--network", @@ -127,14 +122,13 @@ def check_requirements(): if not settings_file.is_file(): sys.exit(f"{settings_file} missing!") + if not NGINX_CONF_D_DIR.is_dir(): + sys.exit(f"{NGINX_CONF_D_DIR} missing!") + if not args.skip_traefik: if not TRAEFIK_ETC_DIR.is_dir(): sys.exit(f"{TRAEFIK_ETC_DIR} missing!") - if not args.skip_nginx: - if not NGINX_CONF_D_DIR.is_dir(): - sys.exit(f"{NGINX_CONF_D_DIR} missing!") - if run(f"podman network exists {args.network}").returncode != 0: if args.skip_traefik: sys.exit(f"Skipped Traefik's deployment although Traefik's network {args.network} does not exist!") @@ -147,6 +141,16 @@ def check_requirements(): ) +def create_nginx_container(): + create_container( + "advlabdb-nginx", + f"""--network {args.network} \ + -v {NGINX_CONF_D_DIR}:/etc/nginx/conf.d:Z,ro \ + --label "io.containers.autoupdate=registry" \ + docker.io/library/nginx:alpine""", + ) + + def create_traefik_container(): if args.verbose: print(f"Making sure that the logs directory {TRAEFIK_LOGS_DIR} exists.") @@ -169,16 +173,6 @@ def create_traefik_container(): ) -def create_nginx_container(): - create_container( - "nginx", - f"""--network {args.network} \ - -v {NGINX_CONF_D_DIR}:/etc/nginx/conf.d:Z,ro \ - --label "io.containers.autoupdate=registry" \ - docker.io/library/nginx:alpine""", - ) - - # Needed for main and create_advlabdb_container advlabdb_container_args = f"""--network {args.network} \ -e ADVLABDB_DATA_DIR=/volumes/data \ @@ -276,8 +270,10 @@ def main(): # Create Nginx container if needed - if not args.skip_nginx and run("systemctl --user is-enabled container-nginx").returncode != 0: + if run("systemctl --user is-enabled container-advlabdb-nginx").returncode != 0: create_nginx_container() + else: + run("systemctl --user restart container-advlabdb-nginx") print("\nDone!\n") diff --git a/podman/traefik/etc/dynamic.yml b/podman/traefik/etc/dynamic.yml index c53fcae..480b427 100644 --- a/podman/traefik/etc/dynamic.yml +++ b/podman/traefik/etc/dynamic.yml @@ -12,4 +12,4 @@ http: advlabdb: loadBalancer: servers: - - url: http://nginx + - url: http://advlabdb-nginx