Spaces:
Paused
Paused
File size: 2,289 Bytes
b42dfef db8d4ce b42dfef a922ba4 76d15d9 b42dfef 5678d99 b42dfef 5678d99 0ce2018 db8d4ce 0ce2018 b42dfef 5678d99 b42dfef 5678d99 b42dfef cc612f9 111496f b42dfef 5678d99 b42dfef c102e46 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | # 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
|