11# Use a Python image with uv pre-installed
22FROM ghcr.io/astral-sh/uv:python3.11-bookworm
33
4+ # Create a non-root user
5+ RUN useradd -m -u 1000 appuser
6+
47# Install the project into `/app`
58WORKDIR /app
69
@@ -12,15 +15,15 @@ ENV UV_LINK_MODE=copy
1215
1316# Install the project's dependencies using the lockfile and settings
1417RUN --mount=type=cache,target=/root/.cache/uv \
15- --mount=type=bind,source=uv.lock,target=uv.lock \
16- --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
17- uv sync --frozen --no-install-project --no-dev
18+ --mount=type=bind,source=uv.lock,target=uv.lock \
19+ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
20+ uv sync --frozen --no-install-project --no-dev
1821
1922# Then, add the rest of the project source code and install it
2023# Installing separately from its dependencies allows optimal layer caching
2124ADD . /app
2225RUN --mount=type=cache,target=/root/.cache/uv \
23- uv sync --frozen --no-dev
26+ uv sync --frozen --no-dev
2427
2528# Place executables in the environment at the front of the path
2629ENV PATH="/app/.venv/bin:$PATH"
@@ -29,9 +32,16 @@ ENV PATH="/app/.venv/bin:$PATH"
2932ENTRYPOINT []
3033
3134# Run setup.py
32-
3335RUN python setup.py
3436
37+ # Create cache directory and set permissions
38+ RUN mkdir -p /.cache/selenium && \
39+ chown -R appuser:appuser /.cache/selenium && \
40+ chmod 755 /.cache/selenium
41+
42+ # Set user
43+ USER appuser
44+
3545EXPOSE 7860
3646# Run the FastAPI application by default
3747# Uses `fastapi dev` to enable hot-reloading when the `watch` sync occurs
0 commit comments