Spaces:
Sleeping
Sleeping
| # Stage 1: Build | |
| FROM python:3.11-slim as builder | |
| WORKDIR /app | |
| # Copy requirements.txt | |
| COPY requirements.txt . | |
| # Install dependencies | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy everything | |
| COPY app app | |
| # Stage 2: Production | |
| FROM python:3.11-slim as production | |
| WORKDIR /app | |
| # Copy installed modules from the builder stage | |
| COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages | |
| # Install playwright dependencies | |
| RUN python -m playwright install-deps && \ | |
| # Clean up | |
| rm -f /usr/lib/x86_64-linux-gnu/libmfxhw* /usr/lib/x86_64-linux-gnu/mfx/* && \ | |
| # Create non-root user | |
| useradd --home-dir /app --shell /bin/sh zaws && \ | |
| chown -R zaws:zaws . | |
| # Switch to non-root user | |
| USER zaws | |
| # Installfirefox inside non-root | |
| # Do not install firefox in root to avoid permission error otherwise you need to give zaws permission to access installation path | |
| RUN python -m playwright install firefox | |
| # Copy application code from the builder stage | |
| COPY --from=builder /app /app | |
| # Run application | |
| CMD ["python", "app/main.py"] |