From c193374444c5bda827f00519aac0153ecc9016c8 Mon Sep 17 00:00:00 2001 From: TuDatTr Date: Thu, 27 Apr 2023 10:52:49 +0200 Subject: [PATCH] Moved docker tasks and made more dynamic Signed-off-by: TuDatTr --- roles/docker/tasks/aya01_compose.yml | 10 -- roles/docker/tasks/main.yml | 39 ++++-- roles/docker/tasks/mii_compose.yml | 6 - roles/docker/tasks/pi_compose.yml | 13 -- roles/docker/templates/aya01/compose.yaml | 130 +++++++++++------- roles/docker/templates/mii/compose.yaml | 2 +- .../mii/swag/site-confs/plex.subdomain.conf | 3 +- roles/docker/templates/pi/compose.yaml | 79 ++++++----- 8 files changed, 152 insertions(+), 130 deletions(-) diff --git a/roles/docker/tasks/aya01_compose.yml b/roles/docker/tasks/aya01_compose.yml index 7788d8d..866704d 100644 --- a/roles/docker/tasks/aya01_compose.yml +++ b/roles/docker/tasks/aya01_compose.yml @@ -66,13 +66,3 @@ dest: "{{ docker_compose_dir }}/compose.yaml" register: compose -- name: Shut down docker - shell: - cmd: "docker compose down --remove-orphans" - chdir: "{{ docker_compose_dir }}" - when: compose.changed - -- name: Run docker compose - shell: - cmd: "docker compose up -d" - chdir: "{{ docker_compose_dir }}" diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml index c696500..343faf7 100644 --- a/roles/docker/tasks/main.yml +++ b/roles/docker/tasks/main.yml @@ -1,15 +1,34 @@ --- - include_tasks: install.yml - include_tasks: user_group_setup.yml -- include_tasks: pi_compose.yml - when: inventory_hostname == "pi" - tags: - - reload_compose -- include_tasks: aya01_compose.yml - when: inventory_hostname == "aya01" - tags: - - reload_compose -- include_tasks: mii_compose.yml - when: inventory_hostname == "mii" +# - include_tasks: pi_compose.yml +# when: inventory_hostname == "pi" +# tags: +# - reload_compose +# - include_tasks: aya01_compose.yml +# when: inventory_hostname == "aya01" +# tags: +# - reload_compose +#- include_tasks: mii_compose.yml +# when: inventory_hostname == "mii" +# tags: +# - reload_compose + +- include_tasks: "{{ inventory_hostname }}_compose.yml" tags: - reload_compose + +- name: Shut down docker + shell: + cmd: "docker compose down --remove-orphans" + chdir: "{{ docker_compose_dir }}" + +- name: Update Docker Images + shell: + cmd: "docker compose pull" + chdir: "{{ docker_compose_dir }}" + +- name: Restart Docker + shell: + cmd: "docker compose up -d" + chdir: "{{ docker_compose_dir }}" diff --git a/roles/docker/tasks/mii_compose.yml b/roles/docker/tasks/mii_compose.yml index 19be82c..8b5d8a8 100644 --- a/roles/docker/tasks/mii_compose.yml +++ b/roles/docker/tasks/mii_compose.yml @@ -10,9 +10,3 @@ tags: - reload_compose -- name: Run docker compose - shell: - cmd: "docker compose up -d" - chdir: "{{ docker_compose_dir }}" - tags: - - reload_compose diff --git a/roles/docker/tasks/pi_compose.yml b/roles/docker/tasks/pi_compose.yml index b8116cc..9f2079a 100644 --- a/roles/docker/tasks/pi_compose.yml +++ b/roles/docker/tasks/pi_compose.yml @@ -16,22 +16,9 @@ tags: - pihole -# Todo, check if docker compose is running -# - name: Shut down docker -# shell: -# cmd: "docker compose down --remove-orphans" -# chdir: "{{ docker_compose_dir }}" - - name: Copy the compose file template: src: templates/pi/compose.yaml dest: "{{ docker_compose_dir }}/compose.yaml" tags: - reload_compose - -- name: Run docker compose - shell: - cmd: "docker compose up -d" - chdir: "{{ docker_compose_dir }}" - tags: - - reload_compose diff --git a/roles/docker/templates/aya01/compose.yaml b/roles/docker/templates/aya01/compose.yaml index b2518e5..36a2a66 100644 --- a/roles/docker/templates/aya01/compose.yaml +++ b/roles/docker/templates/aya01/compose.yaml @@ -15,61 +15,12 @@ services: - "{{ traefik_user_port}}:80" - "{{ traefik_admin_port}}:8080" - db: - image: mariadb - container_name: zoneminder_db - restart: unless-stopped - networks: - - zoneminder - volumes: - - "/etc/localtime:/etc/localtime:ro" - - "{{ zoneminder_db }}:/var/lib/mysql" - environment: - - "MYSQL_DATABASE={{ zoneminder_host }}" - - "MYSQL_ROOT_PASSWORD={{ vault_mysql_root_password }}" - - "MYSQL_USER={{ mysql_user }}" - - "MYSQL_PASSWORD={{ vault_mysql_user_password }}" - - "MAX_LOG_SIZE_BYTES=1000000" - - "MAX_LOG_NUMBER=20" - - "TZ=Europe/Berlin" - zoneminder: - image: ghcr.io/zoneminder-containers/zoneminder-base:latest - container_name: zoneminder - restart: unless-stopped - stop_grace_period: 45s - depends_on: - - db - networks: - - zoneminder - - net - ports: - - "{{ zoneminder_port }}:80" - volumes: - - "/etc/localtime:/etc/localtime:ro" - - "{{ zoneminder_data }}:/data" - - "{{ zoneminder_config }}:/config" - - "{{ zoneminder_log}}:/log" - - type: tmpfs - target: /dev/shm - tmpfs: - size: 1000000000 - environment: - - "MYSQL_DATABASE={{ zoneminder_host }}" - - "MYSQL_ROOT_PASSWORD={{ vault_mysql_root_password }}" - - "MYSQL_USER={{ mysql_user }}" - - "MYSQL_PASSWORD={{ vault_mysql_user_password }}" - - "MAX_LOG_SIZE_BYTES=1000000" - - "MAX_LOG_NUMBER=20" - - "TZ=Europe/Berlin" - labels: - - "traefik.enable=true" - - "traefik.http.routers.{{ zoneminder_host }}.rule=Host(`{{ zoneminder_host}}.{{ aya01_host }}.{{ local_domain }}`)" - - "traefik.http.services.{{ zoneminder_host }}.loadbalancer.server.port=80" - pihole: image: pihole/pihole:latest container_name: pihole restart: unless-stopped + depends_on: + - traefik networks: - net ports: @@ -100,10 +51,65 @@ services: - "traefik.http.routers.{{ pihole_host }}.rule=Host(`{{ pihole_host }}.{{ aya01_host }}.{{ local_domain }}`)" - "traefik.http.services.{{ pihole_host }}.loadbalancer.server.port=80" + db: + image: mariadb + container_name: zoneminder_db + restart: unless-stopped + networks: + - zoneminder + volumes: + - "/etc/localtime:/etc/localtime:ro" + - "{{ zoneminder_db }}:/var/lib/mysql" + environment: + - "MYSQL_DATABASE={{ zoneminder_host }}" + - "MYSQL_ROOT_PASSWORD={{ vault_mysql_root_password }}" + - "MYSQL_USER={{ mysql_user }}" + - "MYSQL_PASSWORD={{ vault_mysql_user_password }}" + - "MAX_LOG_SIZE_BYTES=1000000" + - "MAX_LOG_NUMBER=20" + - "TZ=Europe/Berlin" + zoneminder: + image: ghcr.io/zoneminder-containers/zoneminder-base:latest + container_name: zoneminder + restart: unless-stopped + stop_grace_period: 45s + depends_on: + - db + - traefik + networks: + - zoneminder + - net + ports: + - "{{ zoneminder_port }}:80" + volumes: + - "/etc/localtime:/etc/localtime:ro" + - "{{ zoneminder_data }}:/data" + - "{{ zoneminder_config }}:/config" + - "{{ zoneminder_log}}:/log" + - type: tmpfs + target: /dev/shm + tmpfs: + size: 1000000000 + environment: + - "MYSQL_DATABASE={{ zoneminder_host }}" + - "MYSQL_ROOT_PASSWORD={{ vault_mysql_root_password }}" + - "MYSQL_USER={{ mysql_user }}" + - "MYSQL_PASSWORD={{ vault_mysql_user_password }}" + - "MAX_LOG_SIZE_BYTES=1000000" + - "MAX_LOG_NUMBER=20" + - "TZ=Europe/Berlin" + labels: + - "traefik.enable=true" + - "traefik.http.routers.{{ zoneminder_host }}.rule=Host(`{{ zoneminder_host}}.{{ aya01_host }}.{{ local_domain }}`)" + - "traefik.http.services.{{ zoneminder_host }}.loadbalancer.server.port=80" + + syncthing: image: syncthing/syncthing container_name: syncthing restart: unless-stopped + depends_on: + - pihole networks: - net ports: @@ -127,6 +133,8 @@ services: container_name: soft-serve image: charmcli/soft-serve:latest restart: unless-stopped + depends_on: + - pihole networks: - net environment: @@ -142,6 +150,8 @@ services: container_name: cupsd image: olbat/cupsd restart: unless-stopped + depends_on: + - pihole networks: - net environment: @@ -162,6 +172,8 @@ services: container_name: kuma image: louislam/uptime-kuma:1 restart: unless-stopped + depends_on: + - pihole networks: - net environment: @@ -181,6 +193,8 @@ services: image: lscr.io/linuxserver/plex:latest container_name: plex restart: unless-stopped + depends_on: + - pihole networks: - net ports: @@ -211,6 +225,8 @@ services: image: lscr.io/linuxserver/sonarr:latest container_name: sonarr restart: unless-stopped + depends_on: + - pihole networks: - net environment: @@ -232,6 +248,8 @@ services: image: lscr.io/linuxserver/radarr:latest container_name: radarr restart: unless-stopped + depends_on: + - pihole networks: - net environment: @@ -253,6 +271,8 @@ services: image: lscr.io/linuxserver/lidarr:latest container_name: lidarr restart: unless-stopped + depends_on: + - pihole networks: - net environment: @@ -274,6 +294,8 @@ services: image: lscr.io/linuxserver/prowlarr:latest container_name: prowlarr restart: unless-stopped + depends_on: + - pihole networks: - net environment: @@ -293,6 +315,8 @@ services: image: wantguns/bin container_name: pastebin restart: unless-stopped + depends_on: + - pihole networks: - net ports: @@ -315,6 +339,8 @@ services: container_name: {{ qbit_host }} restart: unless-stopped privileged: true + depends_on: + - pihole networks: - net ports: @@ -341,6 +367,8 @@ services: image: lscr.io/linuxserver/tautulli:latest container_name: tautulli restart: unless-stopped + depends_on: + - pihole networks: - net environment: diff --git a/roles/docker/templates/mii/compose.yaml b/roles/docker/templates/mii/compose.yaml index df7d738..c0b8567 100644 --- a/roles/docker/templates/mii/compose.yaml +++ b/roles/docker/templates/mii/compose.yaml @@ -3,6 +3,7 @@ services: swag: image: lscr.io/linuxserver/swag:latest container_name: swag + restart: unless-stopped networks: net: {} dns: @@ -30,7 +31,6 @@ services: ports: - "{{ swag_port }}:443" - 80:80 #optional - restart: unless-stopped networks: net: diff --git a/roles/docker/templates/mii/swag/site-confs/plex.subdomain.conf b/roles/docker/templates/mii/swag/site-confs/plex.subdomain.conf index e1321dd..1476e97 100644 --- a/roles/docker/templates/mii/swag/site-confs/plex.subdomain.conf +++ b/roles/docker/templates/mii/swag/site-confs/plex.subdomain.conf @@ -12,7 +12,8 @@ server { location / { include /config/nginx/resolver.conf; - proxy_pass http://{{ aya01_ip | replace('.', '-') }}.{{ vault_plex_server_id }}.plex.direct:{{ plex_port }}/; + proxy_pass http://{{ plex_host }}.{{ aya01_host }}.{{ local_domain }}; + proxy_set_header X-Plex-Client-Identifier $http_x_plex_client_identifier; proxy_set_header X-Plex-Device $http_x_plex_device; diff --git a/roles/docker/templates/pi/compose.yaml b/roles/docker/templates/pi/compose.yaml index 0905b8f..769536d 100644 --- a/roles/docker/templates/pi/compose.yaml +++ b/roles/docker/templates/pi/compose.yaml @@ -3,7 +3,7 @@ services: traefik: container_name: traefik image: traefik:latest - restart: always + restart: unless-stopped networks: net: {} volumes: @@ -14,46 +14,10 @@ services: ports: - "{{ traefik_user_port }}:80" - "{{ traefik_admin_port }}:8080" - - ddns-updater: - container_name: ddns-updater - image: "ghcr.io/qdm12/ddns-updater" - restart: always - networks: - net: {} - volumes: - - "{{ ddns_data }}:/updater/data/" - ports: - - "{{ ddns_port }}:8000/tcp" - labels: - - "traefik.enable=true" - - "traefik.http.routers.ddns-updater.rule=Host(`{{ ddns_host }}.{{ pi_host }}.{{local_domain}}`)" - - "traefik.http.services.ddns-updater.loadbalancer.server.port={{ ddns_port }}" - - homeassistant: - container_name: homeassistant - image: "ghcr.io/home-assistant/home-assistant:stable" - restart: always - networks: - net: {} - volumes: - - "/etc/localtime:/etc/localtime:ro" - - "{{ ha_config }}:/config/" - privileged: true - ports: - - "{{ ha_port }}:8123" - - 4357:4357 - - 5683:5683 - - 5683:5683/udp - labels: - - "traefik.enable=true" - - "traefik.http.routers.homeassistant.rule=Host(`{{ ha_host }}.{{ pi_host }}.{{ local_domain }}`)" - - "traefik.http.services.homeassistant.loadbalancer.server.port={{ ha_port }}" - pihole: container_name: pihole image: pihole/pihole:latest - restart: always + restart: unless-stopped networks: net: {} ports: @@ -81,6 +45,45 @@ services: - "traefik.http.routers.pihole.rule=Host(`{{ pihole_host }}.{{ pi_host }}.{{ local_domain }}`)" - "traefik.http.services.pihole.loadbalancer.server.port={{ 80 }}" + ddns-updater: + container_name: ddns-updater + image: "ghcr.io/qdm12/ddns-updater" + restart: unless-stopped + depends_on: + - pihole + networks: + net: {} + volumes: + - "{{ ddns_data }}:/updater/data/" + ports: + - "{{ ddns_port }}:8000/tcp" + labels: + - "traefik.enable=true" + - "traefik.http.routers.ddns-updater.rule=Host(`{{ ddns_host }}.{{ pi_host }}.{{local_domain}}`)" + - "traefik.http.services.ddns-updater.loadbalancer.server.port={{ ddns_port }}" + + homeassistant: + container_name: homeassistant + image: "ghcr.io/home-assistant/home-assistant:stable" + restart: unless-stopped + depends_on: + - pihole + networks: + net: {} + volumes: + - "/etc/localtime:/etc/localtime:ro" + - "{{ ha_config }}:/config/" + privileged: true + ports: + - "{{ ha_port }}:8123" + - 4357:4357 + - 5683:5683 + - 5683:5683/udp + labels: + - "traefik.enable=true" + - "traefik.http.routers.homeassistant.rule=Host(`{{ ha_host }}.{{ pi_host }}.{{ local_domain }}`)" + - "traefik.http.services.homeassistant.loadbalancer.server.port={{ ha_port }}" + networks: net: driver: bridge