# Docker Compose for AS4 Settlement Development
# Includes: PostgreSQL, Redis, and AS4 services

version: '3.8'

services:
  postgres:
    image: postgres:14
    environment:
      POSTGRES_USER: dbis_user
      POSTGRES_PASSWORD: dbis_password
      POSTGRES_DB: dbis_core
      POSTGRES_HOST_AUTH_METHOD: md5
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./postgres-init:/docker-entrypoint-initdb.d
    command: 
      - "postgres"
      - "-c"
      - "listen_addresses=*"
      - "-c"
      - "max_connections=200"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U dbis_user"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  dbis-core:
    build:
      context: ..
      dockerfile: dbis_core/Dockerfile
    environment:
      DATABASE_URL: postgresql://dbis_user:dbis_password@postgres:5432/dbis_core
      REDIS_URL: redis://redis:6379
      AS4_BASE_URL: http://localhost:3000
      NODE_ENV: development
    ports:
      - "3000:3000"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    volumes:
      - ../dbis_core:/app
      - /app/node_modules

volumes:
  postgres_data:
  redis_data:
