services:
  postgres:
    image: postgres:17.7-trixie
    platform: linux/amd64
    container_name: dx-postgres
    ports:
      - "6432:5432"
    environment:
      - POSTGRES_DB=dsam000
      - POSTGRES_USER=dx_user
      - POSTGRES_PASSWORD=dx_password
    volumes:
      - postgres-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U dx_user -d dsam000"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - dx-network
    restart: unless-stopped

  datadog-agent:
    image: datadog/agent:7
    platform: linux/amd64
    container_name: dx-datadog-agent
    ports:
      - "8126:8126"  # APM trace agent
      - "8125:8125/udp"  # DogStatsD
    environment:
      # For local testing without sending data to Datadog
      - DD_API_KEY=dummy
      - DD_APM_ENABLED=true
      - DD_APM_NON_LOCAL_TRAFFIC=true
      - DD_LOGS_ENABLED=false
      - DD_PROCESS_AGENT_ENABLED=false
      - DD_SITE=datadoghq.com
      # Disable sending data to Datadog servers for local testing
      - DD_URL=http://localhost:8126
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /proc/:/host/proc/:ro
      - /sys/fs/cgroup/:/host/sys/fs/cgroup:ro
    networks:
      - dx-network
    restart: unless-stopped

  dx-ui-service:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        AWS_ACCOUNT: "086679231553"
        NEXUS_USERNAME: ${NEXUS_USERNAME}
        NEXUS_PASSWORD: ${NEXUS_PASSWORD}
    platform: linux/amd64
    image: dx-ui-service:0.0.1-SNAPSHOT
    container_name: dx-ui-service
    ports:
      - "8081:8080"
    environment:
      - SPRING_PROFILES_ACTIVE=local
      - SERVER_PORT=8080
      - SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/dsam000
      - SPRING_DATASOURCE_USERNAME=dx_user
      - SPRING_DATASOURCE_PASSWORD=dx_password
      # Datadog APM Configuration
      - DD_SERVICE=dx-ui-service
      - DD_ENV=local
      - DD_VERSION=0.0.1-SNAPSHOT
      - DD_AGENT_HOST=datadog-agent
      - DD_TRACE_AGENT_PORT=8126
      - DD_LOGS_INJECTION=true
      - DD_TRACE_SAMPLE_RATE=1.0
      - DD_TRACE_STARTUP_LOGS=true
      - DD_RUNTIME_METRICS_ENABLED=true
      - DD_PROFILING_ENABLED=false
      # USM
      - USM_API_CLIENT_ID=${USM_API_CLIENT_ID}
      - USM_API_CLIENT_SECRET=${USM_API_CLIENT_SECRET}
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/dx-ui-service/api/v1/actuator/health"]
      interval: 30s
      timeout: 3s
      retries: 3
      start_period: 40s
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
      datadog-agent:
        condition: service_started
    networks:
      - dx-network

volumes:
  postgres-data:

networks:
  dx-network:
    driver: bridge
