Skip to content

fix: improve Dockerfile for non-root user, permissions, and python version alignment #479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

IJOL
Copy link

@IJOL IJOL commented Jun 5, 2025

fix: improve Dockerfile for non-root user, permissions, and python version alignment

Switches to a non-root user for better security
Adjusts file and directory permissions as needed
Aligns Python version to match application requirements
These changes enhance security and ensure compatibility in containerized environments.

@Copilot Copilot AI review requested due to automatic review settings June 5, 2025 09:57
@IJOL IJOL requested a review from a team as a code owner June 5, 2025 09:57
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the Dockerfile to use a multi-stage Python build with uv, aligns the Python version, and aims to enforce non-root execution and proper permissions.

  • Introduces a uv-based build stage for dependency installation.
  • Switches the final image to Python 3.12 slim and copies in a virtualenv.
  • (Intended) switch to a non-root user and set ownership on installed files.

RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev --no-editable

FROM python:3.12-slim-bookworm
Copy link
Preview

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description mentions switching to a non-root user for security, but no user is created or switched to. Add a dedicated app user (e.g., RUN groupadd -r app && useradd -r -g app app) and a USER app directive.

Copilot uses AI. Check for mistakes.


# Then, add the rest of the project source code and install it
# Installing separately from its dependencies allows optimal layer caching
ADD . /app
Copy link
Preview

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use COPY instead of ADD for copying local files, since ADD has extra behaviors like tar extraction that aren't needed here.

Suggested change
ADD . /app
COPY . /app

Copilot uses AI. Check for mistakes.


WORKDIR /app

COPY --from=uv /root/.local /root/.local
Copy link
Preview

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This copies /root/.local into the final image, but the PATH is set to /app/.venv/bin. If /root/.local isn't used at runtime, consider removing this layer to shrink the image.

Suggested change
COPY --from=uv /root/.local /root/.local

Copilot uses AI. Check for mistakes.

Comment on lines +27 to +28
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*

Copy link
Preview

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Installing git in the final image increases size and surface area. If git isn't required at runtime, remove this step or move it only into the build stage.

Suggested change
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*

Copilot uses AI. Check for mistakes.

@IJOL
Copy link
Author

IJOL commented Jun 5, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants