# Compile stage: install build dependencies | |
FROM python:3.12-slim AS builder | |
# Set working directory | |
WORKDIR /app | |
# Install build dependencies | |
RUN apt-get update && \ | |
apt-get install -y --no-install-recommends \ | |
build-essential \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Install Python dependencies | |
COPY requirements.txt . | |
RUN python -m pip install --upgrade pip && \ | |
python -m pip install --no-cache-dir wheel && \ | |
pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt | |
# Final stage: copy only necessary files | |
FROM python:3.12-slim | |
WORKDIR /app | |
# Copy wheels from builder stage | |
COPY --from=builder /app/wheels /wheels | |
# Install Python packages from wheels | |
RUN pip install --no-cache /wheels/* | |
# Copy application files | |
COPY app.py flux.py stablediffusion.py ./ | |
COPY pyproject.toml README.md ./ | |
# Create directories for temporary files | |
RUN mkdir -p /tmp/flux /tmp/flux2 && \ | |
chmod 777 /tmp/flux /tmp/flux2 | |
# Set environment variables | |
ENV PYTHONUNBUFFERED=1 | |
ENV PYTHONDONTWRITEBYTECODE=1 | |
ENV PYTHONPATH=/app | |
# Copy and set permissions for entrypoint script | |
COPY entrypoint.sh . | |
RUN chmod +x entrypoint.sh | |
# Expose the port that Gradio will run on | |
EXPOSE 7860 | |
# Command to run the application | |
ENTRYPOINT ["./entrypoint.sh"] | |