Spaces:
Sleeping
Sleeping
File size: 2,269 Bytes
c75d6b0 2d41a13 4bd4d1c 2d41a13 c75d6b0 2d41a13 c75d6b0 2d41a13 c75d6b0 2d41a13 a5856e8 2d41a13 c75d6b0 2d41a13 c75d6b0 2d41a13 c75d6b0 2d41a13 a5856e8 2d41a13 c75d6b0 2d41a13 c75d6b0 a5856e8 2d41a13 |
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 |
# Use a single-port approach with nginx reverse proxy
# Stage 1: Build Frontend
FROM node:20-alpine AS frontend-builder
WORKDIR /app/frontend
COPY frontend-next/package*.json ./
RUN npm ci
COPY frontend-next/ ./
RUN npm run build
# Stage 2: Runtime with nginx + Python
FROM python:3.10-slim
WORKDIR /app
# Install nginx and Node.js
RUN apt-get update && apt-get install -y \
nginx \
curl \
&& curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
&& apt-get install -y nodejs \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY backend/requirements.txt ./backend/
RUN pip install --no-cache-dir -r backend/requirements.txt
# Copy backend
COPY backend/ ./backend/
# Copy built frontend
COPY --from=frontend-builder /app/frontend/.next ./frontend/.next
COPY --from=frontend-builder /app/frontend/public ./frontend/public
COPY --from=frontend-builder /app/frontend/package*.json ./frontend/
COPY --from=frontend-builder /app/frontend/node_modules ./frontend/node_modules
COPY --from=frontend-builder /app/frontend/next.config.mjs ./frontend/
COPY --from=frontend-builder /app/frontend/src ./frontend/src
# Configure nginx
RUN echo 'server {\n\
listen 7860;\n\
server_name _;\n\
\n\
# Frontend\n\
location / {\n\
proxy_pass http://localhost:3000;\n\
proxy_http_version 1.1;\n\
proxy_set_header Upgrade $http_upgrade;\n\
proxy_set_header Connection "upgrade";\n\
proxy_set_header Host $host;\n\
proxy_cache_bypass $http_upgrade;\n\
}\n\
\n\
# Backend API\n\
location /api/ {\n\
rewrite ^/api/(.*) /$1 break;\n\
proxy_pass http://localhost:8000;\n\
proxy_http_version 1.1;\n\
proxy_set_header Host $host;\n\
proxy_set_header X-Real-IP $remote_addr;\n\
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
proxy_buffering off;\n\
}\n\
}' > /etc/nginx/sites-available/default
# Create startup script
RUN echo '#!/bin/bash\n\
nginx\n\
cd /app/backend && uvicorn main:app --host 127.0.0.1 --port 8000 &\n\
cd /app/frontend && npm start -- -p 3000 &\n\
wait -n\n\
exit $?' > /app/start.sh && chmod +x /app/start.sh
EXPOSE 7860
ENV PYTHONUNBUFFERED=1
ENV NODE_ENV=production
CMD ["/app/start.sh"]
|