Spaces:
Sleeping
Sleeping
Durand D'souza
commited on
Fixing permissions
Browse files- Dockerfile +12 -3
Dockerfile
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
# Use a Python image with uv pre-installed
|
| 2 |
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
# Install the project into `/app`
|
| 5 |
WORKDIR /app
|
| 6 |
|
|
@@ -17,16 +20,22 @@ RUN --mount=type=cache,target=/root/.cache/uv \
|
|
| 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"
|
| 27 |
|
| 28 |
-
# Reset the entrypoint
|
| 29 |
ENTRYPOINT []
|
| 30 |
|
| 31 |
-
# Start the FastAPI app
|
| 32 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
# Use a Python image with uv pre-installed
|
| 2 |
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
|
| 3 |
|
| 4 |
+
# Create a non-root user
|
| 5 |
+
RUN useradd -m -s /bin/bash app_user
|
| 6 |
+
|
| 7 |
# Install the project into `/app`
|
| 8 |
WORKDIR /app
|
| 9 |
|
|
|
|
| 20 |
uv sync --frozen --no-install-project --no-dev
|
| 21 |
|
| 22 |
# Then, add the rest of the project source code and install it
|
|
|
|
| 23 |
ADD . /app
|
| 24 |
RUN --mount=type=cache,target=/root/.cache/uv \
|
| 25 |
uv sync --frozen --no-dev
|
| 26 |
|
| 27 |
+
# Set proper permissions
|
| 28 |
+
RUN chown -R app_user:app_user /app && \
|
| 29 |
+
chmod -R 755 /app
|
| 30 |
+
|
| 31 |
+
# Switch to non-root user
|
| 32 |
+
USER app_user
|
| 33 |
+
|
| 34 |
# Place executables in the environment at the front of the path
|
| 35 |
ENV PATH="/app/.venv/bin:$PATH"
|
| 36 |
|
| 37 |
+
# Reset the entrypoint
|
| 38 |
ENTRYPOINT []
|
| 39 |
|
| 40 |
+
# Start the FastAPI app
|
| 41 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|