Spaces:
Running
Running
File size: 3,301 Bytes
b42dfef a922ba4 76d15d9 b42dfef 0ce2018 b42dfef d1efd8a 511c44b b277d84 511c44b ba8977c cd45927 25c838a b42dfef d84050d b42dfef |
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# Multi-stage build for AnyCoder Docker Space
# Stage 1: Build frontend
FROM node:18-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
# Stage 2: Production image
FROM python:3.11-slim
# Install system dependencies as root (git for pip, nodejs for frontend)
RUN apt-get update && \
apt-get install -y --no-install-recommends \
git \
nodejs \
npm \
&& rm -rf /var/lib/apt/lists/*
# Set up a new user named "user" with user ID 1000
RUN useradd -m -u 1000 user
# Switch to the "user" user
USER user
# Set home to the user's home directory
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH \
PYTHONUNBUFFERED=1
# Set the working directory to the user's home directory
WORKDIR $HOME/app
# Copy Python requirements and install dependencies
COPY --chown=user:user requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY --chown=user:user anycoder_app/ ./anycoder_app/
COPY --chown=user:user backend_api.py .
COPY --chown=user:user backend_models.py .
COPY --chown=user:user backend_docs_manager.py .
COPY --chown=user:user backend_prompts.py .
COPY --chown=user:user backend_parsers.py .
COPY --chown=user:user backend_deploy.py .
COPY --chown=user:user backend_search_replace.py .
COPY --chown=user:user project_importer.py .
COPY --chown=user:user app.py .
# Copy built frontend from builder stage
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/next.config.js ./frontend/
COPY --chown=user:user --from=frontend-builder /build/node_modules ./frontend/node_modules
# Set environment variables for the application
# BACKEND_HOST is used by Next.js server for proxying
# Do NOT set NEXT_PUBLIC_API_URL - let frontend use relative URLs
ENV BACKEND_HOST=http://localhost:8000 \
PORT=7860
# Create startup script that runs both services
# Backend on 8000, Frontend on 7860 (exposed port)
RUN echo '#!/bin/bash\n\
set -e\n\
\n\
echo "π Starting AnyCoder Docker Space..."\n\
\n\
# Start backend on port 8000 in background\n\
echo "π‘ Starting FastAPI backend on port 8000..."\n\
cd $HOME/app\n\
uvicorn backend_api:app --host 0.0.0.0 --port 8000 &\n\
BACKEND_PID=$!\n\
\n\
# Wait for backend to be ready\n\
echo "β³ Waiting for backend to start..."\n\
sleep 5\n\
\n\
# Start frontend on port 7860 (HF Spaces exposed port)\n\
echo "π¨ Starting Next.js frontend on port 7860..."\n\
cd $HOME/app/frontend\n\
PORT=7860 BACKEND_HOST=http://localhost:8000 npm start\n\
' > $HOME/app/start.sh && chmod +x $HOME/app/start.sh
# Expose port 7860 (HF Spaces default)
EXPOSE 7860
# Run the startup script
CMD ["./start.sh"]
|