capture-page-tools / Dockerfile
npv2k1's picture
uo
b7805f6
# Use a Python image with uv pre-installed
FROM ghcr.io/astral-sh/uv:python3.11-bookworm
# Install Chrome and its dependencies
RUN apt-get -y update && apt-get install -y wget gnupg2
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
RUN apt-get -y update && apt-get install -y \
google-chrome-stable \
fonts-ipafont-gothic \
fonts-wqy-zenhei \
fonts-thai-tlwg \
fonts-kacst \
fonts-symbola \
fonts-noto \
fonts-freefont-ttf \
libxss1 \
libx11-xcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxi6 \
libxtst6 \
libnss3 \
libcups2 \
libxrandr2 \
libasound2 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libgtk-3-0 \
libgbm1
# Install chromedriver
RUN apt-get install -yqq unzip
RUN CHROMEDRIVER_VERSION=133.0.6943.126 && \
wget -O /tmp/chromedriver-linux64.zip https://storage.googleapis.com/chrome-for-testing-public/${CHROMEDRIVER_VERSION}/linux64/chromedriver-linux64.zip && \
unzip /tmp/chromedriver-linux64.zip -d /tmp && \
mv /tmp/chromedriver-linux64/chromedriver /usr/local/bin/ && \
chmod +x /usr/local/bin/chromedriver && \
rm -rf /tmp/chromedriver-linux64.zip /tmp/chromedriver-linux64
# Set display port and shared memory settings
ENV DISPLAY=:99
ENV DBUS_SESSION_BUS_ADDRESS=/dev/null
# Create a shared memory volume
VOLUME /dev/shm
# Create a non-root user
RUN useradd -m -u 1000 appuser
# Install the project into `/app`
WORKDIR /app
# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1
# Copy from the cache instead of linking since it's a mounted volume
ENV UV_LINK_MODE=copy
# Install the project's dependencies using the lockfile and settings
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project --no-dev
# Then, add the rest of the project source code and install it
# Installing separately from its dependencies allows optimal layer caching
ADD . /app
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev
# Place executables in the environment at the front of the path
ENV PATH="/app/.venv/bin:$PATH"
# Reset the entrypoint, don't invoke `uv`
ENTRYPOINT []
# Run setup.py
RUN python setup.py
# Create cache directories and set permissions
RUN mkdir -p /.cache/selenium && \
mkdir -p /tmp/screenshots && \
chown -R appuser:appuser /.cache/selenium && \
chown -R appuser:appuser /tmp/screenshots && \
chmod 755 /.cache/selenium && \
chmod 755 /tmp/screenshots
# Set temporary directory environment variable
ENV TMPDIR=/tmp/screenshots
# Set user
USER appuser
EXPOSE 7860
# Run the FastAPI application by default
CMD ["python", "main.py"]