Skip to content

Commit 1aa5770

Browse files
committed
Add non-root user and configure cache directory in Dockerfile
1 parent 83a1ece commit 1aa5770

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Dockerfile

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Use a Python image with uv pre-installed
22
FROM 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`
58
WORKDIR /app
69

@@ -12,15 +15,15 @@ ENV UV_LINK_MODE=copy
1215

1316
# Install the project's dependencies using the lockfile and settings
1417
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
1821

1922
# Then, add the rest of the project source code and install it
2023
# Installing separately from its dependencies allows optimal layer caching
2124
ADD . /app
2225
RUN --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
2629
ENV PATH="/app/.venv/bin:$PATH"
@@ -29,9 +32,16 @@ ENV PATH="/app/.venv/bin:$PATH"
2932
ENTRYPOINT []
3033

3134
# Run setup.py
32-
3335
RUN 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+
3545
EXPOSE 7860
3646
# Run the FastAPI application by default
3747
# Uses `fastapi dev` to enable hot-reloading when the `watch` sync occurs

0 commit comments

Comments
 (0)