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/ ./
|
COPY frontend/ ./
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Stage 2: Setup Backend
|
# Stage 2: Final Image (Python + Nginx)
|
||||||
FROM python:3.11-slim AS backend
|
# Use Python base image to ensure binary compatibility for pandas/numpy
|
||||||
WORKDIR /app/backend
|
FROM python:3.11-slim
|
||||||
COPY backend/requirements.txt ./
|
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
# Install Nginx
|
||||||
COPY backend/ ./
|
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
|
WORKDIR /app
|
||||||
|
|
||||||
# Install Python and dependencies in final stage
|
# Install Backend Dependencies
|
||||||
RUN apk add --no-cache python3 py3-pip
|
COPY backend/requirements.txt /app/backend/requirements.txt
|
||||||
|
RUN pip install --no-cache-dir -r /app/backend/requirements.txt
|
||||||
|
|
||||||
# Copy backend
|
# Copy Backend Code
|
||||||
COPY --from=backend /app/backend /app/backend
|
COPY backend /app/backend
|
||||||
COPY --from=backend /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
|
|
||||||
|
|
||||||
# Copy frontend build to Nginx
|
# Copy Frontend Build from Stage 1
|
||||||
COPY --from=frontend-build /app/frontend/dist /usr/share/nginx/html
|
COPY --from=frontend-build /app/frontend/dist /usr/share/nginx/html
|
||||||
|
|
||||||
# Copy Nginx configuration
|
# Copy Nginx Config
|
||||||
COPY nginx.conf /etc/nginx/nginx.conf
|
COPY nginx.conf /etc/nginx/nginx.conf
|
||||||
|
|
||||||
# Expose ports
|
# Copy Entrypoint Script
|
||||||
EXPOSE 80
|
|
||||||
|
|
||||||
# Start script
|
|
||||||
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
||||||
RUN chmod +x /docker-entrypoint.sh
|
RUN chmod +x /docker-entrypoint.sh
|
||||||
|
|
||||||
|
# Expose Port
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
# Start Services
|
||||||
CMD ["/docker-entrypoint.sh"]
|
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;
|
default_type application/octet-stream;
|
||||||
|
|
||||||
upstream backend {
|
upstream backend {
|
||||||
server backend:8000;
|
server 127.0.0.1:8000;
|
||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue