# apache-guacamole - https://github.com/code-loading/guacamole-docker-compose/blob/main/docker-compose.yaml
services:
  # ---------------------------------------------------------
  # Guacamole Daemon (guacd)
  # ---------------------------------------------------------
  guacd:
    image: guacamole/guacd:1.6.0  # Guacd daemon handles RDP, SSH, VNC protocols
    container_name: guacd
    restart: unless-stopped
    networks:
        - guac_network

  # ---------------------------------------------------------
  # PostgreSQL Database Service
  # ---------------------------------------------------------
  guac-postgresql:
    image: postgres:15
    container_name: guac-postgresql
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${POSTGRESQL_DATABASE}  # Database name (from .env file)
      POSTGRES_USER: ${POSTGRESQL_USERNAME}  # Database username
      POSTGRES_PASSWORD: ${POSTGRESQL_PASSWORD}  # Database password
    volumes:
        # Mount startup script from guacamole container into postgres container to initialize DB schema
        - "initdb:/docker-entrypoint-initdb.d:ro"
        # (optional) Persist database data on host to survive container rebuilds:
       # - "${HOME}/guacamole/postgres-data:/var/lib/postgresql/data"
    networks:
        - guac_network

  # ---------------------------------------------------------
  # Guacamole Web Application
  # ---------------------------------------------------------
  guacamole:
    image: guacamole/guacamole:1.6.0  # Guacamole web app image
    container_name: guacamole
    restart: unless-stopped
    environment:
      POSTGRESQL_DATABASE: ${POSTGRESQL_DATABASE}  # guacamole container also needs to be provided with DB name, user and password
      POSTGRESQL_USERNAME: ${POSTGRESQL_USERNAME}
      POSTGRESQL_PASSWORD: ${POSTGRESQL_PASSWORD}
      POSTGRESQL_HOSTNAME: guac-postgresql  # Must match service name above of postgres
      POSTGRESQL_ENABLED: "true"  # Enable PostgreSQL authentication backend
      GUACD_HOSTNAME: guacd  # Must match service name below of guacd
    ports:
        - ${GUAC_HTTP_PORT}:8080
    volumes:
        # Mount startup script from guacamole container into postgres container to initialize DB schema
        - "initdb:/opt/guacamole/extensions/guacamole-auth-jdbc/postgresql/schema:ro"
    depends_on:
      - guacd
      - guac-postgresql
    networks:
      - guac_network
    labels:
      # Nginx Proxy Manager Automation
      - "npm.proxy.domains=guac.wompmacho.com"
      - "npm.proxy.host=${DOCKER_HOST_IP}"
      - "npm.proxy.port=${GUAC_HTTP_PORT}"
      - "npm.proxy.scheme=http"
      - "npm.proxy.ssl_verify=false"
      - "npm.proxy.websockets=true"
      - "npm.proxy.ssl.force=true"
      - "npm.proxy.ssl.certificate.id=2"
      - "npm.proxy.advanced.config=location = / { return 301 /guacamole/; }"
      # Pi-hole Automation (Point to Docker Host/Proxy IP)
      - "pihole.custom-record=[[\"guac.wompmacho.com\", \"${DOCKER_HOST_IP}\"]]"

# ---------------------------------------------------------
# Named Volume
# ---------------------------------------------------------
volumes:
    initdb:

# ---------------------------------------------------------
# Shared Network
# ---------------------------------------------------------
networks:
  guac_network: