services:
  db:
    image: postgres:17
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-amnezia}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-amnezia}
      POSTGRES_DB: ${POSTGRES_DB:-amnezia_panel}
    volumes:
      - amnezia_pgdata:/var/lib/postgresql/data
    restart: unless-stopped
    networks:
      - internal
    healthcheck:
      test:
        [
          "CMD-SHELL",
          "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB} && PGPASSWORD=$${POSTGRES_PASSWORD} psql -U $${POSTGRES_USER} -d $${POSTGRES_DB} -c 'SELECT 1' >/dev/null",
        ]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 20s

  amnezia_panel:
    build:
      context: .
      dockerfile: Dockerfile
    image: amnezia-panel:local
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "${APP_PORT:-5000}:5000"
    environment:
      DATABASE_URL: postgresql://${POSTGRES_USER:-amnezia}:${POSTGRES_PASSWORD:-amnezia}@db:5432/${POSTGRES_DB:-amnezia_panel}
      POSTGRES_USER: ${POSTGRES_USER:-amnezia}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-amnezia}
      POSTGRES_DB: ${POSTGRES_DB:-amnezia_panel}
      POSTGRES_PORT: "5432"
      SECRET_KEY: ${SECRET_KEY:-}
      APP_PORT: "5000"
      PORT: "5000"
      PANEL_IN_DOCKER: "1"
      PANEL_BEHIND_PROXY: "1"
    volumes:
      - amnezia_data:/app/data
    restart: unless-stopped
    networks:
      - internal
      - dokploy-network
    labels:
      - traefik.enable=true
      - traefik.docker.network=dokploy-network
      - traefik.http.services.amnezia_panel.loadbalancer.server.port=5000
    expose:
      - "5000"
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:5000/health >/dev/null || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

networks:
  internal:
  dokploy-network:
    external: true
    name: dokploy-network

volumes:
  amnezia_data:
  amnezia_pgdata:
