Skip to content

Commit a5df87b

Browse files
committed
Refactor Dockerfile: streamline uv sync commands and update user permissions for improved security
1 parent d38b5fd commit a5df87b

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

Dockerfile

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
1212

1313
WORKDIR /app
1414

15-
# Copy uv from official image for better security and updates
1615
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
1716

1817
COPY pyproject.toml uv.lock ./
1918

2019
RUN --mount=type=cache,target=/root/.cache/uv \
21-
uv sync --locked --no-install-project
20+
uv sync --locked --no-dev --no-install-project
2221

2322
COPY . .
2423

2524
RUN --mount=type=cache,target=/root/.cache/uv \
26-
uv sync --locked
25+
uv sync --locked --no-dev
2726

2827
# --- Runtime stage ---
2928
FROM python:${PYTHON_VERSION}-slim
@@ -37,23 +36,20 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
3736

3837
WORKDIR /app
3938

40-
RUN groupadd -r appuser && \
41-
useradd -r -g appuser -u 1000 -s /sbin/nologin appuser
39+
RUN groupadd --system flowdacity && \
40+
useradd --system --gid flowdacity --uid 1000 --create-home --shell /usr/sbin/nologin flowdacity
4241

43-
COPY --from=builder --chown=appuser:appuser /app/.venv /app/.venv
42+
COPY --from=builder --chown=flowdacity:flowdacity /app/.venv /app/.venv
43+
COPY --from=builder --chown=flowdacity:flowdacity /app /app
4444

45-
COPY --chown=appuser:appuser . .
45+
RUN chmod -R a-w /app && \
46+
chmod -R u+rwX /app
4647

47-
RUN chmod -R 555 /app/fq_server && \
48-
chmod 555 /app/*.py && \
49-
chmod 444 /app/default.conf /app/pyproject.toml
50-
51-
USER appuser
48+
USER flowdacity
5249

5350
EXPOSE ${PORT}
5451

5552
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
56-
CMD python -c "import os, httpx; port = os.environ.get('PORT', '8080'); httpx.get(f'http://127.0.0.1:{port}/metrics/')" || exit 1
53+
CMD python -c "import os, httpx; port = os.environ.get('PORT', '8080'); r = httpx.get(f'http://127.0.0.1:{port}/metrics/'); raise SystemExit(0 if r.status_code < 400 else 1)"
5754

58-
ENTRYPOINT ["sh", "-c"]
59-
CMD exec uvicorn asgi:app --host 0.0.0.0 --port ${PORT}
55+
CMD ["sh", "-c", "exec uvicorn asgi:app --host 0.0.0.0 --port ${PORT}"]

0 commit comments

Comments
 (0)