feat: Consolidate Nginx and Python backend into a single Docker image, managed by a new entrypoint script, and update Nginx proxy configuration.
This commit is contained in:
parent
8ee91428cd
commit
ff89fd1e87
39
Dockerfile
39
Dockerfile
|
|
@ -8,35 +8,36 @@ RUN npm install
|
|||
COPY frontend/ ./
|
||||
RUN npm run build
|
||||
|
||||
# Stage 2: Setup Backend
|
||||
FROM python:3.11-slim AS backend
|
||||
WORKDIR /app/backend
|
||||
COPY backend/requirements.txt ./
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
COPY backend/ ./
|
||||
# Stage 2: Final Image (Python + Nginx)
|
||||
# Use Python base image to ensure binary compatibility for pandas/numpy
|
||||
FROM python:3.11-slim
|
||||
|
||||
# Install Nginx
|
||||
RUN apt-get update && \
|
||||
apt-get install -y nginx && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Stage 3: Final - Nginx + Backend
|
||||
FROM nginx:alpine
|
||||
WORKDIR /app
|
||||
|
||||
# Install Python and dependencies in final stage
|
||||
RUN apk add --no-cache python3 py3-pip
|
||||
# Install Backend Dependencies
|
||||
COPY backend/requirements.txt /app/backend/requirements.txt
|
||||
RUN pip install --no-cache-dir -r /app/backend/requirements.txt
|
||||
|
||||
# Copy backend
|
||||
COPY --from=backend /app/backend /app/backend
|
||||
COPY --from=backend /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
|
||||
# Copy Backend Code
|
||||
COPY backend /app/backend
|
||||
|
||||
# Copy frontend build to Nginx
|
||||
# Copy Frontend Build from Stage 1
|
||||
COPY --from=frontend-build /app/frontend/dist /usr/share/nginx/html
|
||||
|
||||
# Copy Nginx configuration
|
||||
# Copy Nginx Config
|
||||
COPY nginx.conf /etc/nginx/nginx.conf
|
||||
|
||||
# Expose ports
|
||||
EXPOSE 80
|
||||
|
||||
# Start script
|
||||
# Copy Entrypoint Script
|
||||
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
||||
RUN chmod +x /docker-entrypoint.sh
|
||||
|
||||
# Expose Port
|
||||
EXPOSE 80
|
||||
|
||||
# Start Services
|
||||
CMD ["/docker-entrypoint.sh"]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Start Nginx
|
||||
echo "Starting Nginx..."
|
||||
service nginx start
|
||||
|
||||
# Start Backend
|
||||
echo "Starting Backend..."
|
||||
cd /app/backend
|
||||
exec uvicorn main:app --host 0.0.0.0 --port 8000
|
||||
|
|
@ -7,7 +7,7 @@ http {
|
|||
default_type application/octet-stream;
|
||||
|
||||
upstream backend {
|
||||
server backend:8000;
|
||||
server 127.0.0.1:8000;
|
||||
}
|
||||
|
||||
server {
|
||||
|
|
|
|||
Loading…
Reference in New Issue