From ff89fd1e879e99edd29e72a5dba4ea26630c9d45 Mon Sep 17 00:00:00 2001 From: hissin Date: Thu, 20 Nov 2025 14:57:44 +0800 Subject: [PATCH] feat: Consolidate Nginx and Python backend into a single Docker image, managed by a new entrypoint script, and update Nginx proxy configuration. --- Dockerfile | 39 ++++++++++++++++++++------------------- docker-entrypoint.sh | 11 +++++++++++ nginx.conf | 2 +- 3 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 3e80a1c..fc0d8ee 100644 --- a/Dockerfile +++ b/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"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..57a42e4 --- /dev/null +++ b/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 diff --git a/nginx.conf b/nginx.conf index 303365d..196505f 100644 --- a/nginx.conf +++ b/nginx.conf @@ -7,7 +7,7 @@ http { default_type application/octet-stream; upstream backend { - server backend:8000; + server 127.0.0.1:8000; } server {