# LifeFrame 个人版自托管一键部署：网站 + PostgreSQL + MinIO
# 用法：执行 docker compose up -d（.env 可选，不创建则全用默认）
# 镜像已统一使用腾讯云 CCR 国内仓库，便于国内用户拉取

services:
  postgres:
    # 需含 pgvector（向量检索迁移依赖）；上游为 pgvector/pgvector:pg16
    image: ccr.ccs.tencentyun.com/lifeframe/pgvector:pg16
    restart: unless-stopped
    environment:
      POSTGRES_USER: lifeframe
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-lifeframe_selfhost}
      POSTGRES_DB: lifeframe
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U lifeframe -d lifeframe"]
      interval: 5s
      timeout: 5s
      retries: 5

  minio:
    image: ccr.ccs.tencentyun.com/lifeframe/minio:RELEASE.2024-09-22T00-33-43Z
    command: server /data --console-address ":9001"
    ports:
      - "9000:9000"
      - "9001:9001"
    environment:
      MINIO_ROOT_USER: ${MINIO_ROOT_USER:-minioadmin}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-minioadmin}
    volumes:
      - minio_data:/data
    restart: unless-stopped

  init-minio-bucket:
    image: ccr.ccs.tencentyun.com/lifeframe/minio-mc:latest
    depends_on:
      minio: { condition: service_started }
    entrypoint: ["/bin/sh", "-c"]
    command:
      - |
        sleep 5
        mc alias set myminio http://minio:9000 $$MINIO_ROOT_USER $$MINIO_ROOT_PASSWORD
        mc mb myminio/$$MINIO_BUCKET 2>/dev/null || true
        exit 0
    environment:
      MINIO_ROOT_USER: ${MINIO_ROOT_USER:-minioadmin}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-minioadmin}
      MINIO_BUCKET: ${MINIO_BUCKET:-lifeframe}

  lifeframe:
    image: ccr.ccs.tencentyun.com/lifeframe/lifeframe:latest
    ports:
      - "3880:3000"   # 宿主机 3880，降低与 3000、8080 等常见端口的冲突
    volumes:
      - lifeframe_data:/app/data
      - lifeframe_uploads:/app/uploads
    environment:
      NODE_ENV: production
      JWT_SECRET: ${JWT_SECRET:-lifeframe-selfhost-change-me-in-production}
      DATABASE_URL: postgresql://lifeframe:${POSTGRES_PASSWORD:-lifeframe_selfhost}@postgres:5432/lifeframe
      UPLOAD_DIR: ./uploads
      STORAGE_PROVIDER: minio
      MINIO_ENDPOINT: http://minio:9000
      MINIO_BUCKET: ${MINIO_BUCKET:-lifeframe}
      MINIO_ACCESS_KEY: ${MINIO_ROOT_USER:-minioadmin}
      MINIO_SECRET_KEY: ${MINIO_ROOT_PASSWORD:-minioadmin}
      MINIO_REGION: ${MINIO_REGION:-us-east-1}
      MINIO_PUBLIC_URL: ${MINIO_PUBLIC_URL:-http://localhost:9000}
      # 宿主机映射为 3880，默认对外地址与端口一致（有域名时请在 .env 覆盖）
      NEXT_PUBLIC_APP_URL: ${NEXT_PUBLIC_APP_URL:-http://localhost:3880}
    depends_on:
      postgres:
        condition: service_healthy
      minio:
        condition: service_started
      init-minio-bucket:
        condition: service_completed_successfully
    restart: unless-stopped

volumes:
  postgres_data:
  minio_data:
  lifeframe_data:
  lifeframe_uploads:
