File size: 1,563 Bytes
bd9a582 05edc02 bd9a582 0863b41 bd9a582 05edc02 bd9a582 0863b41 bd9a582 05edc02 bd9a582 |
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 |
# Stage 1: Build the React frontend
FROM node:18 AS frontend-builder
WORKDIR /app/frontend
COPY frontend/package*.json ./
RUN npm install
COPY frontend/ ./
# Explicitly set NODE_ENV to production to use .env.production
ENV NODE_ENV=production
RUN npm run build
# Stage 2: Set up the Python backend and Nginx
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim
# Install nginx
RUN apt-get update && apt-get install -y nginx && rm -rf /var/lib/apt/lists/*
# Create app directory and set permissions
RUN mkdir /app && \
useradd -m -u 1000 user && \
chown -R user:user /app
# Set the working directory
WORKDIR /app
# Copy the backend app and set permissions
COPY --chown=user . /app
# Copy the built frontend from the previous stage
COPY --from=frontend-builder --chown=user /app/frontend/build /app/static
# Configure nginx
COPY nginx.conf /etc/nginx/nginx.conf
RUN mkdir -p /var/log/nginx && \
chown -R user:user /var/log/nginx && \
chown -R user:user /var/lib/nginx && \
touch /var/run/nginx.pid && \
chown -R user:user /var/run/nginx.pid
# Switch to user
USER user
# Set the environment variables
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH \
UVICORN_WS_PROTOCOL=websockets
# Install the Python dependencies
RUN uv sync
# Create start script
RUN echo '#!/bin/bash\n\
nginx -g "daemon off;" &\n\
source /app/.venv/bin/activate && exec uvicorn api:app --host 0.0.0.0 --port 8000\n\
' > /app/start.sh && chmod +x /app/start.sh
# Expose the Hugging Face port
EXPOSE 7860
# Run the start script
CMD ["./start.sh"] |