# Full-stack dev environment for Daytona / Codespaces / devcontainers.
#
# Runs the real Electron app with a virtual display accessible via noVNC.
#
# Services:
#   - MySQL 8.4 for the Den database
#   - Workspace container with Node 20, Electron deps, Xvfb, noVNC
#
# Ports:
#   - 5173  App Vite dev server (HMR)
#   - 3005  Den Web dashboard
#   - 6080  noVNC — see the Electron app in your browser
#   - 8788  Den API
#   - 9825  CDP remote debugging (for Chrome MCP / automation)

services:
  mysql:
    image: mysql:8.4
    command:
      - --performance_schema=OFF
      - --innodb-buffer-pool-size=64M
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: openwork_den
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -ppassword --silent"]
      interval: 5s
      timeout: 5s
      retries: 30
      start_period: 10s
    volumes:
      - mysql-data:/var/lib/mysql

  workspace:
    build:
      context: .
      dockerfile: Dockerfile
    depends_on:
      mysql:
        condition: service_healthy
    volumes:
      - ..:/workspace:cached
    ports:
      - "5173:5173"
      - "3005:3005"
      - "6080:6080"
      - "8788:8788"
      - "9825:9825"
    environment:
      # Display
      DISPLAY: ":99"
      ELECTRON_DISABLE_SANDBOX: "1"
      # Electron CDP debugging
      OPENWORK_ELECTRON_REMOTE_DEBUG_PORT: "9825"
      # Den API config
      DATABASE_URL: mysql://root:password@mysql:3306/openwork_den
      DEN_DB_ENCRYPTION_KEY: local-dev-db-encryption-key-please-change-1234567890
      BETTER_AUTH_SECRET: local-dev-secret-not-for-production-use!!
      BETTER_AUTH_URL: http://localhost:3005
      OPENWORK_DEV_MODE: "1"
      PORT: "8788"
      PROVISIONER_MODE: stub
      # Den Web config
      DEN_API_BASE: http://localhost:8788
      DEN_AUTH_ORIGIN: http://localhost:3005
      DEN_AUTH_FALLBACK_BASE: http://localhost:8788
      DEN_WEB_PORT: "3005"
      DEN_API_PORT: "8788"
      # CORS
      CORS_ORIGINS: http://localhost:3005,http://localhost:5173,http://localhost:8788
      DEN_BETTER_AUTH_TRUSTED_ORIGINS: http://localhost:3005,http://localhost:5173,http://localhost:8788
    command: sleep infinity

volumes:
  mysql-data:
