|
|
|
|
|
FROM node:18-slim as frontend-builder |
|
|
|
|
|
WORKDIR /app/frontend |
|
|
COPY frontend/package*.json ./ |
|
|
RUN npm ci |
|
|
COPY frontend/ ./ |
|
|
RUN npm run build |
|
|
|
|
|
|
|
|
FROM python:3.9-slim |
|
|
|
|
|
WORKDIR /app |
|
|
|
|
|
|
|
|
RUN apt-get update && apt-get install -y \ |
|
|
nginx \ |
|
|
supervisor \ |
|
|
libgomp1 \ |
|
|
libglib2.0-0 \ |
|
|
libsm6 \ |
|
|
libxext6 \ |
|
|
libxrender1 \ |
|
|
curl \ |
|
|
&& rm -rf /var/lib/apt/lists/* |
|
|
|
|
|
|
|
|
COPY backend/requirements.txt ./backend/ |
|
|
RUN pip install --no-cache-dir -r backend/requirements.txt |
|
|
|
|
|
|
|
|
COPY backend/ ./backend/ |
|
|
|
|
|
|
|
|
COPY --from=frontend-builder /app/frontend/dist /usr/share/nginx/html |
|
|
|
|
|
|
|
|
RUN echo 'server { \n\ |
|
|
listen 7860; \n\ |
|
|
root /usr/share/nginx/html; \n\ |
|
|
index index.html; \n\ |
|
|
\n\ |
|
|
location / { \n\ |
|
|
try_files $uri $uri/ /index.html; \n\ |
|
|
} \n\ |
|
|
\n\ |
|
|
location /api/ { \n\ |
|
|
proxy_pass http://127.0.0.1:8000/; \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_set_header X-Real-IP $remote_addr; \n\ |
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; \n\ |
|
|
proxy_set_header X-Forwarded-Proto $scheme; \n\ |
|
|
proxy_buffering off; \n\ |
|
|
} \n\ |
|
|
}' > /etc/nginx/sites-available/default |
|
|
|
|
|
|
|
|
RUN echo '[supervisord] \n\ |
|
|
nodaemon=true \n\ |
|
|
\n\ |
|
|
[program:nginx] \n\ |
|
|
command=nginx -g "daemon off;" \n\ |
|
|
autostart=true \n\ |
|
|
autorestart=true \n\ |
|
|
stderr_logfile=/var/log/nginx.err.log \n\ |
|
|
stdout_logfile=/var/log/nginx.out.log \n\ |
|
|
\n\ |
|
|
[program:backend] \n\ |
|
|
command=python -m uvicorn backend.app.main:app --host 127.0.0.1 --port 8000 \n\ |
|
|
directory=/app \n\ |
|
|
autostart=true \n\ |
|
|
autorestart=true \n\ |
|
|
stderr_logfile=/var/log/backend.err.log \n\ |
|
|
stdout_logfile=/var/log/backend.out.log \n\ |
|
|
environment=USE_EXTREME_OPTIMIZATION="true",MAX_MEMORY_GB="3"' > /etc/supervisor/conf.d/supervisord.conf |
|
|
|
|
|
|
|
|
EXPOSE 7860 |
|
|
|
|
|
|
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ |
|
|
CMD curl -f http://localhost:7860/ || exit 1 |
|
|
|
|
|
|
|
|
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] |