# Nginx Proxy Manager & MariaDB Stack
services:
  db:
    image: jc21/mariadb-aria:latest
    container_name: npm-db
    restart: unless-stopped
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_DATABASE=${MYSQL_DATABASE}
      - MYSQL_USER=${MYSQL_USER}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
      - MARIADB_AUTO_UPGRADE=1
      - TZ=${TZ}
    volumes:
      - ${DATA_PATH}/mysql:/var/lib/mysql
    networks:
      - internal
    healthcheck:
      test: ["CMD-SHELL", "mariadb-admin ping -h 127.0.0.1 -u root -p$$MYSQL_ROOT_PASSWORD || exit 1"]
      interval: 20s
      timeout: 5s
      retries: 5
      start_period: 30s

  nginx-proxy-manager:
    image: jc21/nginx-proxy-manager:latest
    container_name: nginx-proxy-manager
    restart: unless-stopped
    environment:
      - TZ=${TZ}
      - DB_MYSQL_HOST=db
      - DB_MYSQL_PORT=3306
      - DB_MYSQL_USER=${MYSQL_USER}
      - DB_MYSQL_PASSWORD=${MYSQL_PASSWORD}
      - DB_MYSQL_NAME=${MYSQL_DATABASE}
    ports:
      - '80:80'
      - '81:81'
      - '443:443'
    volumes:
      - ${DATA_PATH}/npm:/data
      - ${DATA_PATH}/letsencrypt:/etc/letsencrypt
    depends_on:
      db:
        condition: service_healthy
        restart: true
    networks:
      - internal
      - external
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:81/"]
      interval: 20s
      timeout: 5s
      retries: 5
      start_period: 40s

networks:
  internal:
    external: true
  external:
    external: true
