# ================================================
# Urban Lifeline - All-in-One 前端镜像
# 使用 Node.js 静态服务器，端口可配置
# 
# 构建: docker build -t urban-lifeline-web:latest -f Dockerfile.web .
# ================================================
FROM node:20-alpine

ENV TZ=Asia/Shanghai

RUN apk add --no-cache tzdata curl bash sed gettext \
    && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone

# 安装静态文件服务器
RUN npm install -g serve

WORKDIR /app

# 复制管理脚本
COPY docker/urbanLifeline/web/web-manager.sh /app/web-manager.sh
RUN chmod +x /app/web-manager.sh

# 复制 shared 公共模块 (Module Federation 远程模块，必须最先启动)
COPY urbanLifelineWeb/packages/shared/dist/ /app/sites/shared/

# 复制所有前端构建产物
COPY urbanLifelineWeb/packages/platform/dist/ /app/sites/platform/
COPY urbanLifelineWeb/packages/workcase/dist/ /app/sites/workcase/
COPY urbanLifelineWeb/packages/bidding/dist/ /app/sites/bidding/
# COPY urbanLifelineWeb/packages/workcase_wechat/dist/ /app/sites/workcase_wechat/

# ============================================
# 端口配置 (可通过环境变量覆盖)
# ============================================
ENV SHARED_PORT=8000 \
    PLATFORM_PORT=8001 \
    WORKCASE_PORT=8002 \
    BIDDING_PORT=8003
    # WORKCASE_WECHAT_PORT=8004

# ============================================
# 应用配置环境变量（可通过 docker-compose 覆盖）
# ============================================
ENV APP_ENV=production \
    API_BASE_URL=/api \
    PUBLIC_PATH=/ \
    SSO_PLATFORM_URL=/ \
    SSO_WORKCASE_URL=/workcase \
    SSO_BIDDING_URL=/bidding \
    AES_SECRET_KEY=MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI= \
    JITSI_SERVER_URL=https://meet.example.com \
    AI_DEFAULT_AGENT_ID=17664699513920001 \
    FILE_MAX_SIZE=100 \
    ENABLE_DEBUG=false

# 配置和日志目录 (可外挂)
VOLUME ["/app/config", "/app/logs"]

EXPOSE 8000 8001 8002 8003 8004

HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
    CMD curl -f http://localhost:${SHARED_PORT}/ || exit 1

ENTRYPOINT ["/app/web-manager.sh"]
CMD ["start-all"]
