-
Notifications
You must be signed in to change notification settings - Fork 754
Enhanced GitHub Token Integration for Docker Builds #1322
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
base: dev
Are you sure you want to change the base?
Conversation
- Add get_github_token() function with multiple environment variable support - Implement preprocess_dockerfile_for_github_api() for automatic GitHub API call handling - Integrate GitHub token authentication into build_container() function - Replace ADD https://api.github.com calls with COPY instructions using pre-fetched data - Add automatic cleanup of temporary files after builds - Maintain backward compatibility with --no-github-api flag - Add comprehensive documentation and test script - Support multiple token environment variables: GITHUB_TOKEN, GITHUB_PAT, GH_TOKEN This enhancement provides higher rate limits (5000 vs 60 requests/hour) and more reliable builds by pre-fetching GitHub data using authenticated API calls instead of relying on Docker's ADD instruction during build time.
- Add cleanup logic for Dockerfile.minus-github-api files - Ensures both types of temporary files are removed after builds - Prevents accumulation of temporary files in package directories - Maintains clean package directory state after all build scenarios
|
Tested following on |
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 implements enhanced GitHub token integration for Docker builds to address persistent GitHub API rate limiting issues. The solution automatically detects GitHub API calls in Dockerfiles, pre-fetches data using authenticated requests, and provides graceful fallback behavior.
- Adds automatic GitHub token detection from multiple environment variables (GITHUB_TOKEN, GITHUB_PAT, GH_TOKEN)
- Implements Dockerfile preprocessing to replace ADD instructions with COPY using pre-fetched GitHub data
- Provides seamless fallback to existing --no-github-api workaround when token is unavailable or preprocessing fails
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test_github_token_integration.py | Comprehensive test script for validating GitHub token detection and Dockerfile preprocessing functionality |
| jetson_containers/network.py | Core implementation of GitHub token detection and Dockerfile preprocessing logic |
| jetson_containers/container.py | Integration of GitHub API preprocessing into the container build pipeline with cleanup |
| jetson_containers/build.py | Updated help text for --no-github-api flag to reflect enhanced functionality |
| docs/github-token-integration.md | Complete documentation for the new GitHub token integration feature |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| dockerfilepath = os.path.join(pkg['path'], pkg['dockerfile']) | ||
|
|
||
| # Fall back to no_github_api logic if preprocessing failed or was disabled | ||
| if no_github_api or (dockerfilepath == os.path.join(pkg['path'], pkg['dockerfile']) and 'ADD https://api.github.com' in open(dockerfilepath, 'r').read()): |
Copilot
AI
Sep 5, 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.
The file is being opened and read multiple times unnecessarily. The content should be read once and stored in a variable to avoid repeated I/O operations.
| with open(dockerfile_path, 'r') as fp: | ||
| content = fp.read() | ||
|
|
||
| # Find all GitHub API calls |
Copilot
AI
Sep 5, 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.
The regular expression pattern is complex and could benefit from documentation explaining what each capture group represents (owner/repo, branch, destination path).
| try: | ||
| for pkg in packages: | ||
| pkg_info = find_package(pkg) |
Copilot
AI
Sep 5, 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.
The cleanup loop calls find_package() for each package, which may be inefficient if this function performs expensive operations. Consider reusing the package information already loaded during the build process.
| try: | |
| for pkg in packages: | |
| pkg_info = find_package(pkg) | |
| # Cache package info for all packages to avoid repeated find_package() calls | |
| package_infos = {pkg: find_package(pkg) for pkg in packages} | |
| try: | |
| for pkg in packages: | |
| pkg_info = package_infos[pkg] |
Problem Statement
This PR addresses the persistent and frustrating GitHub API rate limiting issue that plagues Docker builds:
Current Impact:
--no-github-apiflag as a workaroundSolution
Implement intelligent GitHub token integration that automatically handles API rate limiting while maintaining all existing functionality.
Key Features
🔑 Enhanced GitHub Token Detection
GITHUB_TOKEN,GITHUB_PAT,GH_TOKEN🎯 Automatic Dockerfile Pre-processing
ADD https://api.github.com/...lines in DockerfilesADDinstructions toCOPYwith pre-fetched data🔄 Seamless Fallback System
--no-github-apiworkaround--no-github-apiflag still works exactly as before♻️ Automatic Cleanup
User Experience
With Valid Token (Recommended)
Without Token (Graceful Fallback)
./build.sh sudonim # Automatically falls back with helpful warningsExplicit Fallback (Always Works)
./build.sh --no-github-api sudonim # Original behavior unchangedTechnical Implementation
Dockerfile Transformation
Before:
ADD https://api.github.com/repos/dusty-nv/sudonim/git/refs/heads/main /tmp/sudonim_version.jsonAfter:
COPY .github-api-temp/dusty-nv_sudonim_main.json /tmp/sudonim_version.jsonBuild Arguments
Automatically adds commit hashes as build arguments: