version: '3.8'

services:
  postgres:
    image: pgvector/pgvector:pg17
    container_name: colanode_postgres
    restart: always
    environment:
      POSTGRES_USER: colanode_user
      POSTGRES_PASSWORD: postgrespass123
      POSTGRES_DB: colanode_db
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - '5432:5432'
    networks:
      - colanode_network

  valkey:
    image: valkey/valkey:8.1
    container_name: colanode_valkey
    restart: always
    command: ['valkey-server', '--requirepass', 'your_valkey_password']
    volumes:
      - valkey_data:/data
    ports:
      - '6379:6379'
    networks:
      - colanode_network

  # ---------------------------------------------------------------
  # Optional MinIO Object Storage (Enable when using S3 storage)
  # ---------------------------------------------------------------
  minio:
    profiles:
      - s3
    image: minio/minio:RELEASE.2025-04-08T15-41-24Z
    container_name: colanode_minio
    restart: always
    environment:
      MINIO_ROOT_USER: minioadmin
      MINIO_ROOT_PASSWORD: your_minio_password
      MINIO_BROWSER: 'on'
      MINIO_DOMAIN: minio
      MINIO_ADDRESS: ':9000'
      MINIO_CONSOLE_ADDRESS: ':9001'
    volumes:
      - minio_data:/data
    ports:
      - '9000:9000'
      - '9001:9001'
    entrypoint: sh
    command: -c 'mkdir -p /data/colanode && minio server /data --address ":9000" --console-address ":9001"'
    networks:
      - colanode_network

  # ---------------------------------------------------------------
  # Optional SMTP Server (Mailpit) for Local Email Testing
  # ---------------------------------------------------------------
  # This service runs Mailpit, a local SMTP testing tool.
  # If you want to test how emails are sent in the 'server' service,
  # uncomment the 'smtp' service block, set email.enabled=true in config.json,
  # point the email provider to "smtp", and define EMAIL_HOST /
  # EMAIL_SMTP_USER / EMAIL_SMTP_PASSWORD env vars (and any others) so the
  # SMTP provider block in config.json resolves via env:// pointers.
  #
  # Access the Mailpit UI at http://localhost:8025
  # ---------------------------------------------------------------
  # smtp:
  #  image: axllent/mailpit:v1.24.1
  #  container_name: colanode_smtp
  #  restart: always
  #  ports:
  #    - '1025:1025' # SMTP IN (Connect server service to this port)
  #    - '8025:8025' # Web UI
  #  networks:
  #    - colanode_network

  server:
    image: ghcr.io/colanode/server:latest
    container_name: colanode_server
    restart: always
    depends_on:
      - postgres
      - valkey
      # - smtp # Optional
    environment:
      # ------------------------------------------------------------------
      # Configuration Strategy
      # ------------------------------------------------------------------
      # - All defaults live in config.json mounted at /app/apps/server/config.json
      # - config.json references secrets via env://VAR or read values from files via file://path
      # - The variables below are only those secrets; every other setting
      #   must be changed inside the JSON file
      # ------------------------------------------------------------------
      NODE_ENV: production

      # Required env:// secrets (default configuration references these as env://VAR)
      POSTGRES_URL: postgres://colanode_user:postgrespass123@postgres:5432/colanode_db
      REDIS_URL: redis://:your_valkey_password@valkey:6379/0

      # If you want to override the default configuration mount a config.json as explained below
      # and add the config.json path as an environment variable:
      # CONFIG: /config.json

    ports:
      - '3000:3000'
    volumes:
      - server_storage:/var/lib/colanode/storage
      # Mount a config.json sitting next to this compose file to override defaults.
      # - ./config.json:/config.json:ro
    networks:
      - colanode_network

  web:
    image: ghcr.io/colanode/web:latest
    container_name: colanode_web
    restart: always
    ports:
      - '4000:80'
    networks:
      - colanode_network

volumes:
  postgres_data:
  valkey_data:
  minio_data:
  server_storage:

networks:
  colanode_network:
    driver: bridge
