---
pgadmin_id: "{{ inventory_hostname }}-pgadmin4"
postgres_id: "{{ inventory_hostname }}-postgres"

pgadmin4_docker:
  networks:
    - name: front-tier
      external: true
    - name: back-tier
      external: true
  volumes:
    - name: pgadmin_data
    - name: postgres_15_data
    - name: postgres_16_data
  services:
    - name: "{{ pgadmin_id }}"
      image_name: "{{ pgadmin4_image_name }}"
      image_version: "{{ pgadmin4_version }}"
      labels:
        - '"traefik.enable=true"'
        - '"traefik.http.routers.{{ pgadmin_id }}.service={{ pgadmin_id }}"'
        - '"traefik.http.routers.{{ pgadmin_id }}.rule=Host(`{{ pgadmin_id }}.{{ domain }}`)"'
        - '"traefik.http.routers.{{ pgadmin_id }}.entrypoints=websecure"'
        - '"traefik.http.routers.{{ pgadmin_id }}.tls=true"'
        - '"traefik.http.routers.{{ pgadmin_id }}.tls.certresolver=letsencrypt"'
        - '"traefik.http.services.{{ pgadmin_id }}.loadbalancer.server.port={{ http_port }}"'
      environment:
        - 'PGADMIN_DEFAULT_EMAIL: "{{ pgadmin4_admin_username }}"'
        - 'PGADMIN_DEFAULT_PASSWORD: "{{ pgadmin4_admin_password }}"'
      volumes:
        - "pgadmin_data:/var/lib/pgadmin"
      networks:
        - front-tier
        - back-tier
    - name: "{{ postgres_id }}-15"
      image_name: "postgres"
      image_version: "15"
      environment:
        - 'POSTGRES_DB: "{{ mpmx_postgres_database }}"'
        - 'POSTGRES_USER: "{{ mpmx_postgres_username }}"'
        - 'POSTGRES_PASSWORD: "{{ mpmx_postgres_password }}"'
      volumes:
        - "postgres_15_data:/var/lib/postgresql/data"
      networks:  
        - "back-tier"
    - name: "{{ postgres_id }}-16"
      image_name: "postgres"
      image_version: "16"
      environment:
        - 'POSTGRES_DB: "{{ mpmx_postgres_database }}"'
        - 'POSTGRES_USER: "{{ mpmx_postgres_username }}"'
        - 'POSTGRES_PASSWORD: "{{ mpmx_postgres_password }}"'
      volumes:
        - "postgres_16_data:/var/lib/postgresql/data"
      networks:
        - "back-tier"
