1
1
# Use a Python image with uv pre-installed
2
2
FROM ghcr.io/astral-sh/uv:python3.11-bookworm
3
3
4
+ # Create a non-root user
5
+ RUN useradd -m -u 1000 appuser
6
+
4
7
# Install the project into `/app`
5
8
WORKDIR /app
6
9
@@ -12,15 +15,15 @@ ENV UV_LINK_MODE=copy
12
15
13
16
# Install the project's dependencies using the lockfile and settings
14
17
RUN --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
18
21
19
22
# Then, add the rest of the project source code and install it
20
23
# Installing separately from its dependencies allows optimal layer caching
21
24
ADD . /app
22
25
RUN --mount=type=cache,target=/root/.cache/uv \
23
- uv sync --frozen --no-dev
26
+ uv sync --frozen --no-dev
24
27
25
28
# Place executables in the environment at the front of the path
26
29
ENV PATH="/app/.venv/bin:$PATH"
@@ -29,9 +32,16 @@ ENV PATH="/app/.venv/bin:$PATH"
29
32
ENTRYPOINT []
30
33
31
34
# Run setup.py
32
-
33
35
RUN python setup.py
34
36
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
+
35
45
EXPOSE 7860
36
46
# Run the FastAPI application by default
37
47
# Uses `fastapi dev` to enable hot-reloading when the `watch` sync occurs
0 commit comments