Spaces:
Paused
Paused
| # Multi-stage build for AnyCoder Docker Space | |
| # Stage 1: Build frontend | |
| FROM node:22-slim AS frontend-builder | |
| WORKDIR /build | |
| # Copy frontend package files | |
| COPY frontend/package*.json ./ | |
| RUN npm ci | |
| # Copy all frontend source files and configs | |
| COPY frontend/src ./src | |
| COPY frontend/public ./public | |
| COPY frontend/next.config.js ./ | |
| COPY frontend/tsconfig.json ./ | |
| COPY frontend/tailwind.config.js ./ | |
| COPY frontend/postcss.config.js ./ | |
| # Note: next-env.d.ts is auto-generated by Next.js, not needed for build | |
| # Build frontend | |
| RUN npm run build | |
| # ... (Giữ nguyên toàn bộ Stage 1: Build frontend) ... | |
| # Stage 2: Production image | |
| FROM python:3.11-slim | |
| # Install system dependencies | |
| RUN apt-get update && \ | |
| apt-get install -y --no-install-recommends curl ca-certificates gnupg git && \ | |
| curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \ | |
| apt-get install -y --no-install-recommends nodejs && \ | |
| rm -rf /var/lib/apt/lists/* | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH \ | |
| PYTHONUNBUFFERED=1 | |
| WORKDIR $HOME/app | |
| COPY --chown=user:user requirements.txt . | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir -r requirements.txt | |
| # Copy tất cả file backend (dùng . để copy toàn bộ file backend hiện có) | |
| COPY --chown=user:user *.py ./ | |
| # Copy built frontend | |
| COPY --chown=user:user --from=frontend-builder /build/.next ./frontend/.next | |
| COPY --chown=user:user --from=frontend-builder /build/public ./frontend/public | |
| COPY --chown=user:user --from=frontend-builder /build/package.json ./frontend/ | |
| COPY --chown=user:user --from=frontend-builder /build/node_modules ./frontend/node_modules | |
| # Sử dụng RUN để thực thi chuỗi lệnh bash an toàn | |
| RUN printf '#!/bin/bash\n\ | |
| set -e\n\ | |
| echo "🚀 Starting AnyCoder..."\n\ | |
| uvicorn backend_api:app --host 0.0.0.0 --port 8000 --log-level debug &\n\ | |
| echo "⏳ Waiting for backend..."\n\ | |
| sleep 15\n\ | |
| echo "🎨 Starting Frontend on port 7860..."\n\ | |
| export PORT=7860\n\ | |
| export HOSTNAME="0.0.0.0"\n\ | |
| cd /home/user/app/frontend && node .next/standalone/server.js\n' > start.sh && chmod +x start.sh | |
| EXPOSE 7860 | |
| CMD ["./start.sh"] | |
| # Thêm dòng này vào Dockerfile trước dòng CMD | |
| RUN chown -R user:user /home/user/app | |