Skip to content

Docker: Init python venv with non-root user #2769

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

Merged
merged 2 commits into from
Apr 9, 2025
Merged

Docker: Init python venv with non-root user #2769

merged 2 commits into from
Apr 9, 2025

Conversation

VietND96
Copy link
Member

@VietND96 VietND96 commented Apr 8, 2025

User description

Thanks for contributing to the Docker-Selenium project!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines, applied for this repository.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Fixes #2768

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Bug fix, Enhancement


Description

  • Fixed permission issues with /opt/venv directory by initializing Python venv as a non-root user.

  • Moved Python venv initialization to run under non-privileged user.

  • Updated environment variables to include VENV_PATH and adjusted PATH accordingly.

  • Improved Dockerfile structure for Python venv setup and dependency installation.


Changes walkthrough 📝

Relevant files
Bug fix
Dockerfile
Fixed Python venv setup and permissions in Dockerfile       

Base/Dockerfile

  • Added VENV_PATH environment variable and updated PATH.
  • Moved Python venv initialization to non-root user section.
  • Adjusted Python dependency installation to align with non-root user
    permissions.
  • Removed redundant commands and improved Dockerfile structure.
  • +15/-16 

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
    Copy link

    qodo-merge-pro bot commented Apr 8, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🎫 Ticket compliance analysis ✅

    2768 - Fully compliant

    Compliant requirements:

    • Fix permission issues with the /opt/venv directory that is causing Poetry installs to fail
    • Address the problem where the /opt/venv directory is owned by the root user, causing permission denied errors
    • Ensure Python virtual environment setup works correctly for non-root users

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Dependency Changes

    The PR removes python3-setuptools from the apt-get install list. Verify this won't cause issues with Python package installations.

    python3 python3-pip python3-venv \
    && rm -rf /var/lib/apt/lists/* /var/cache/apt/* \

    Copy link

    qodo-merge-pro bot commented Apr 8, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Fix missing command continuation
    Suggestion Impact:The commit implemented exactly what was suggested - adding the '&&' operator before the echo command to properly continue the RUN instruction, which prevents a build failure

    code diff:

    -    echo "source $VENV_PATH/bin/activate" >> /etc/bash.bashrc
    +    && echo "source $VENV_PATH/bin/activate" >> /etc/bash.bashrc

    The command is missing a backslash continuation character after the package
    installation line, which will cause the echo command to fail. Add a backslash
    after the apt cleanup command.

    Base/Dockerfile [76-81]

     RUN apt-get -qqy update \
         && apt-get upgrade -yq \
         && apt-get -qqy --no-install-recommends install \
         python3 python3-pip python3-venv \
         && rm -rf /var/lib/apt/lists/* /var/cache/apt/* \
    -    echo "source $VENV_PATH/bin/activate" >> /etc/bash.bashrc
    +    && echo "source $VENV_PATH/bin/activate" >> /etc/bash.bashrc

    [Suggestion has been applied]

    Suggestion importance[1-10]: 10

    __

    Why: The suggestion correctly identifies a critical syntax error in the Dockerfile. Without the '&&' operator before the echo command, the build would fail as the echo command would be executed as a separate command outside the RUN instruction, causing a syntax error. This is a high-impact fix that prevents build failure.

    High
    • Update

    @VietND96 VietND96 requested a review from Copilot April 8, 2025 19:22
    Copy link

    @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.

    Copilot wasn't able to review any files in this pull request.

    Files not reviewed (1)
    • Base/Dockerfile: Language not supported

    Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
    @VietND96 VietND96 merged commit 64633d9 into trunk Apr 9, 2025
    28 checks passed
    @VietND96 VietND96 deleted the python-venv branch April 9, 2025 01:41
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    [🐛 Bug]: Poetry installs are failing due to /opt/venv directory existing.
    1 participant