services:
  metamcp:
    container_name: ${CONTAINER_NAME}
    image: ghcr.io/metatool-ai/metamcp:latest
    pull_policy: always
    ports:
      - "${PANEL_APP_PORT_HTTP}:12008"
    environment:
      # Postgres connection details
      POSTGRES_HOST: postgres
      POSTGRES_PORT: 5432
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
      
      # Database configuration (composed from above vars)
      DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
      
      # Application URL configuration
      APP_URL: ${APP_URL}
      NEXT_PUBLIC_APP_URL: ${NEXT_PUBLIC_APP_URL}
      
      # Auth configuration
      BETTER_AUTH_SECRET: ${BETTER_AUTH_SECRET}
      
      # Docker networking fix
      TRANSFORM_LOCALHOST_TO_DOCKER_INTERNAL: ${TRANSFORM_LOCALHOST_TO_DOCKER_INTERNAL}
    extra_hosts:
      - "host.docker.internal:host-gateway"
    depends_on:
      postgres:
        condition: service_healthy
    restart: always
    networks:
      - 1panel-network
    volumes:
      - ./data:/app/data
    labels:
      createdBy: "Apps"

  postgres:
    image: postgres:16-alpine
    container_name: ${CONTAINER_NAME}-pg
    restart: always
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s
    networks:
      - 1panel-network
    labels:
      createdBy: "Apps"

networks:
  1panel-network:
    external: true
