# GChain Docker Compose Configuration
# Usage: docker-compose up -d

version: '3.8'

services:
  # MariaDB Database
  db:
    image: mariadb:11
    container_name: gchain-db
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-rootpassword}
      MYSQL_DATABASE: gchain_db
      MYSQL_USER: ${DB_USER:-gchain_admin}
      MYSQL_PASSWORD: ${DB_PASSWORD:-gchainpass}
    volumes:
      - gchain-db-data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 30s
    networks:
      - gchain-network

  # GChain Application
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: gchain-app
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    environment:
      NODE_ENV: production
      PORT: 5000
      DB_HOST: db
      DB_USER: ${DB_USER:-gchain_admin}
      DB_PASSWORD: ${DB_PASSWORD:-gchainpass}
      DB_NAME: gchain_db
      JWT_SECRET: ${JWT_SECRET:?JWT_SECRET is required}
      CORS_ORIGIN: ${CORS_ORIGIN:-http://localhost:3000}
    ports:
      - "${APP_PORT:-5000}:5000"
    volumes:
      - gchain-uploads:/app/uploads
    healthcheck:
      test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:5000/api/health/live"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
    networks:
      - gchain-network

volumes:
  gchain-db-data:
    driver: local
  gchain-uploads:
    driver: local

networks:
  gchain-network:
    driver: bridge
