x-env_file: &env
  - path: .env
    required: true
  - path: .env.local
    required: false

name: aviation
services:
  postgres:
    image: postgis/postgis:17-3.5
    container_name: aviation-postgres
    env_file: *env
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_NAME}
    volumes:
     - postgres:/var/lib/postgresql/data
     - postgres_logs:/var/log
    ports:
      - "${POSTGRES_PORT:-5432}:5432"
    networks:
      - backend
    profiles:
      - backend
    restart: unless-stopped

  redis:
    image: redis:8.0-M03 # Replace with valkey?
    container_name: aviation-redis
    volumes:
      - redis:/data
    ports:
      - ${REDIS_PORT:-6379}:6379
    healthcheck:
      test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
      interval: 10s
      timeout: 5s
      retries: 3
    networks:
      - backend
    profiles:
      - backend
    restart: unless-stopped

  minio:
    image: minio/minio:RELEASE.2025-02-28T09-55-16Z
    container_name: aviation-minio
    environment:
      MINIO_ROOT_USER: ${MINIO_ROOT_USER}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
    volumes:
      - minio:/data
    ports:
      - ${MINIO_PORT:-9000}:9000
      - ${MINIO_PORT_INTERNAL:-9001}:9001
    networks:
      - backend
    profiles:
      - backend
    command: server --console-address ":9001" /data
    restart: unless-stopped

  api:
    container_name: aviation-api
    env_file: *env
    ports:
      - "${API_PORT:-5000}:5000"
    build:
      context: api
    depends_on:
      - postgres
      - redis
      - minio
    networks:
      - frontend
      - backend
    profiles:
      - api
    restart: unless-stopped

  ui:
    container_name: aviation-ui
    env_file: *env
    environment:
      - NODE_ENV=${NODE_ENV:-development}
    ports:
      - ${UI_PORT:-3000}:3000
    build:
      context: ./ui/
      target: dev
    volumes:
      - ./ui/src:/app/src
      - ./ui/public:/app/public
      - ./ui/styles:/app/styles
    networks:
      - frontend
    profiles:
      - frontend
    command: ["npm", "run", "dev"]
    restart: unless-stopped

volumes:
  postgres:
  postgres_logs:
  redis:
  minio:

networks:
  frontend:
  backend:
