npv2k1 commited on
Commit
1aa5770
·
1 Parent(s): 83a1ece

Add non-root user and configure cache directory in Dockerfile

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