webscrapper / Dockerfile
AkshayStark's picture
fix
af04fc7
FROM python:3.12
WORKDIR /app
# Set Playwright's cache directory to a writable location
ENV PLAYWRIGHT_BROWSERS_PATH=/app/playwright-browsers
# Create the Playwright browser cache directory and set correct permissions
RUN mkdir -p $PLAYWRIGHT_BROWSERS_PATH && chmod -R 777 $PLAYWRIGHT_BROWSERS_PATH
# Install required system dependencies for Playwright
RUN apt-get update && apt-get install -y \
libnss3 \
libnspr4 \
libdbus-1-3 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libatspi2.0-0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxrandr2 \
libgbm1 \
libxkbcommon0 \
libasound2 \
libcups2 \
libglib2.0-0 \
libxshmfence1 \
libgdk-pixbuf2.0-0 \
libegl1 \
libopus0 \
libwoff1 \
libharfbuzz-icu0 \
libhyphen0 \
libevent-2.1-7 \
libxcursor1 \
libgtk-3-0 \
&& rm -rf /var/lib/apt/lists/*
# Install Poetry
RUN pip install --no-cache-dir poetry
# Set Poetry virtualenvs to be inside the project
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
# Copy dependency files first (for better caching)
COPY pyproject.toml poetry.lock ./
# Install dependencies
RUN poetry install --no-root
# Install Playwright within Poetry environment
RUN poetry run playwright install --with-deps chromium
# Copy the rest of the application
COPY . .
# Expose port
EXPOSE 7860
# Run application
CMD ["poetry", "run", "uvicorn", "server:app", "--host", "0.0.0.0", "--port", "7860"]