-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add support for pip packages with git+ssh sources #8
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
Conversation
See more: - https://docs.astral.sh/uv/concepts/authentication/#git-authentication - https://docs.docker.com/reference/cli/docker/buildx/build/#ssh + Now it is possible to use this as base image even if missing pyproject.toml, uv.lock and .python-version files. + set `VIRTUAL_ENV` env var in the hopes that some tooling find the right Python
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @jhassine, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request enhances the Dockerfile to support installing Python packages from "git+ssh" sources, which is crucial for private repository access. It achieves this by enabling Docker BuildKit's SSH mounting feature and configuring the SSH environment within the build process. Additionally, the changes improve the Docker image's reusability and flexibility by making the presence of "pyproject.toml", "uv.lock", and ".python-version" files optional for the build, and by explicitly setting the "VIRTUAL_ENV" environment variable to assist Python tooling.
Highlights
- SSH Support for Git Packages: The Dockerfile now supports installing pip packages from Git repositories using SSH authentication, leveraging Docker BuildKit's SSH mounting capabilities.
- Improved Image Flexibility: The Docker image is made more flexible, allowing it to be used as a base even if "pyproject.toml", "uv.lock", or ".python-version" files are missing, by conditionally running "uv sync".
- Virtual Environment Discovery: The "VIRTUAL_ENV" environment variable is now explicitly set within the Docker image, which helps various Python tooling automatically discover and utilize the correct virtual environment.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
There was a problem hiding this 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 adds support for pip packages with git+ssh sources by enabling SSH agent forwarding in Docker builds and making the base image more flexible for projects without complete uv configuration files.
Key changes:
- Enables SSH authentication for git repositories during package installation
- Makes pyproject.toml, uv.lock, and .python-version files optional by copying them conditionally
- Sets VIRTUAL_ENV environment variable for better Python tooling compatibility
| uv venv \ | ||
| && uv sync --frozen --no-install-project | ||
| ONBUILD RUN --mount=type=ssh \ | ||
| mkdir -p ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts \ |
Copilot
AI
Aug 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard-coding GitHub's host keys in the Dockerfile creates a security risk. If GitHub's host keys change, builds will fail, and there's no verification of the keys being added. Consider using a more secure approach like ssh-keyscan -H github.com for hashed known_hosts or allowing users to mount their own known_hosts file.
| mkdir -p ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts \ | |
| mkdir -p ~/.ssh && \ | |
| if [ -f /tmp/known_hosts ]; then \ | |
| cp /tmp/known_hosts ~/.ssh/known_hosts; \ | |
| else \ | |
| echo "WARNING: No known_hosts file provided, using ssh-keyscan (less secure)"; \ | |
| ssh-keyscan -H github.com >> ~/.ssh/known_hosts; \ | |
| fi \ |
| mkdir -p ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts \ | ||
| && uv venv \ | ||
| && if [ -f "pyproject.toml" ] && [ -f "uv.lock" ]; then \ | ||
| uv sync --frozen --no-install-project --no-cache; \ |
Copilot
AI
Aug 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using --no-cache disables uv's caching mechanism, which will make subsequent builds slower. Since this is in an ONBUILD instruction that runs for every derived image, consider removing --no-cache to allow uv to cache downloaded packages and improve build performance.
| uv sync --frozen --no-install-project --no-cache; \ | |
| uv sync --frozen --no-install-project; \ |
| && if [ -f "pyproject.toml" ] && [ -f "uv.lock" ]; then \ | ||
| uv sync --frozen --no-install-project --no-cache; \ | ||
| fi \ | ||
| && rm -rf /app/.python-version* /app/pyproject.toml* /app/uv.lock* |
Copilot
AI
Aug 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the copied configuration files at the end of the RUN instruction defeats the purpose of copying them in the ONBUILD COPY step. If these files are needed for the uv sync operation, they should remain available for potential future operations in derived images. Consider whether this cleanup is necessary or if it should be conditional.
| && rm -rf /app/.python-version* /app/pyproject.toml* /app/uv.lock* |
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request enhances the Docker image by adding support for installing pip packages from git+ssh sources, which is a great feature for private dependencies. It also makes the presence of pyproject.toml and uv.lock optional, increasing the image's flexibility.
My review includes two main suggestions:
- Making the
ssh-keyscanhost configurable to support git providers other than GitHub. - Re-enabling the
uvcache to avoid a performance regression during builds.
The changes are well-structured and address the stated goals effectively. Addressing these points will make the image even more robust and performant.
| ONBUILD RUN --mount=type=ssh \ | ||
| mkdir -p ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts \ | ||
| && uv venv \ | ||
| && if [ -f "pyproject.toml" ] && [ -f "uv.lock" ]; then \ | ||
| uv sync --frozen --no-install-project --no-cache; \ | ||
| fi \ | ||
| && rm -rf /app/.python-version* /app/pyproject.toml* /app/uv.lock* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The uv cache mount has been removed and uv sync is now run with --no-cache. This will significantly slow down builds by preventing dependency caching. It's recommended to reintroduce the cache mount for uv and remove the --no-cache flag to leverage Docker's build cache for faster dependency installation on subsequent builds.
ONBUILD RUN --mount=type=ssh --mount=type=cache,target=/root/.cache/uv \
mkdir -p ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts \
&& uv venv \
&& if [ -f "pyproject.toml" ] && [ -f "uv.lock" ]; then \
uv sync --frozen --no-install-project; \
fi \
&& rm -rf /app/.python-version* /app/pyproject.toml* /app/uv.lock*
| uv venv \ | ||
| && uv sync --frozen --no-install-project | ||
| ONBUILD RUN --mount=type=ssh \ | ||
| mkdir -p ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoding github.com in ssh-keyscan limits this feature to GitHub-hosted repositories. To make this image more versatile for git+ssh dependencies from other providers (e.g., GitLab, Bitbucket, or private servers), consider allowing the host(s) to be configurable via a build argument.
For example:
ARG GIT_SSH_HOSTS="github.com"
...
ONBUILD RUN --mount=type=ssh \
mkdir -p ~/.ssh && for host in $GIT_SSH_HOSTS; do ssh-keyscan "$host" >> ~/.ssh/known_hosts; done \
...
phuongfi91
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
User description
See more:
VIRTUAL_ENVenv var in the hopes that some tooling find the right PythonPR Type
Enhancement
Description
Add SSH support for git+ssh pip packages
Enable usage without required project files
Set VIRTUAL_ENV environment variable
Improve Docker build flexibility
Diagram Walkthrough
File Walkthrough
Dockerfile
Enable SSH git packages and optional filesDockerfile