-
-
Notifications
You must be signed in to change notification settings - Fork 579
feat(docker): Allow authenticated calls to GitHub API during docker build
#947
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
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 📝 WalkthroughSummary by CodeRabbit
WalkthroughAdded optional build-time GitHub token support: Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant DockerBuild as Docker Build
participant InstallScript as tools/install/_common.sh
participant GitHubAPI as GitHub API
User->>DockerBuild: docker build --build-arg GITHUB_TOKEN=ghp_***
DockerBuild->>InstallScript: ARG GITHUB_TOKEN available at build-time
InstallScript->>InstallScript: detect if GITHUB_TOKEN set
alt token present
InstallScript->>GitHubAPI: curl -H "Authorization: Bearer <token>" -L ...
else no token
InstallScript->>GitHubAPI: curl -L ...
end
GitHubAPI-->>InstallScript: release JSON / redirect URL
InstallScript-->>DockerBuild: resolved release URL
DockerBuild-->>User: image built
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 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.
Pull Request Overview
This PR adds support for authenticated GitHub API calls during Docker image builds by accepting a GITHUB_TOKEN build argument. This addresses API rate limiting issues when installing tools from GitHub releases.
Key Changes:
- Modified the
common::install_from_gh_releasefunction to conditionally include GitHub token authentication in curl requests - Added
GITHUB_TOKENas a build argument and environment variable in the Dockerfile - Updated documentation with instructions for using the GitHub token during builds
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tools/install/_common.sh | Modified curl commands to conditionally include Authorization header when GITHUB_TOKEN is set |
| Dockerfile | Added GITHUB_TOKEN as a build argument and environment variable |
| README.md | Added documentation note explaining how to use GITHUB_TOKEN for authenticated API calls |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tools/install/_common.sh
Outdated
| local -r RELEASES="https://api.github.com/repos/${GH_ORG}/${TOOL}/releases" | ||
| local CURL_OPTS=() | ||
|
|
||
| [[ "$GITHUB_TOKEN" ]] && CURL_OPTS+=('-H' "Authorization: Bearer $GITHUB_TOKEN") |
Copilot
AI
Nov 16, 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 GITHUB_TOKEN is not quoted in the Authorization header value. If the token contains spaces or special characters, this could lead to unexpected behavior or header injection. Wrap the variable in quotes: \"Authorization: Bearer ${GITHUB_TOKEN}\"
| [[ "$GITHUB_TOKEN" ]] && CURL_OPTS+=('-H' "Authorization: Bearer $GITHUB_TOKEN") | |
| [[ "$GITHUB_TOKEN" ]] && CURL_OPTS+=('-H' "Authorization: Bearer \"$GITHUB_TOKEN\"") |
71f262d to
2e88a8a
Compare
2e88a8a to
7058185
Compare
|
I don't understand the CI logs, nor do I see how that's related to my changes. |
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.
LGTM
@wI2L Have you tested it works as expected with both set and unset GITHUB_TOKEN env var (and respectively with both --build-arg GITHUB_TOKEN present and absent)? Thanks
|
@yermulnik Yes I did, with a |
7058185 to
76b30ac
Compare
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
Dockerfile (1)
68-69: Correct token propagation to build environment.The
ARGandENVdeclarations properly propagate the GitHub token into the builder stage environment where the install scripts will access it. The empty default ensures backward compatibility.Operational note: For enhanced security in CI/CD pipelines, consider using Docker BuildKit secrets (
--secret GITHUB_TOKEN) instead of build arguments, which prevents the token from being visible in layer metadata. This approach keeps the token out of image history while still making it available during builds.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
Dockerfile(1 hunks)README.md(1 hunks)tools/install/_common.sh(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- README.md
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-12T19:43:31.295Z
Learnt from: actuarysailor
Repo: antonbabenko/pre-commit-terraform PR: 925
File: Dockerfile.tools:92-108
Timestamp: 2025-08-12T19:43:31.295Z
Learning: In Dockerfile.tools, the version checking script at the end of the builder stage is intentionally designed to download the latest versions of tools when not specified in build args and echo the installed versions for verification/debugging purposes during the build process. This behavior is by design to track what actual tool versions end up in the container.
Applied to files:
tools/install/_common.shDockerfile
🔇 Additional comments (2)
tools/install/_common.sh (2)
65-69: Proper token-aware curl construction.The CURL_OPTS array pattern correctly builds curl options conditionally based on GITHUB_TOKEN presence, and the Authorization header format is correct for GitHub API authentication. The quoting approach aligns with previous feedback.
72-72: Correct nested curl invocations with token support.The nested curl pattern is correct: inner call retrieves the release asset URL (with auth header if token present), outer call downloads the asset. The array expansion
"${CURL_CMD[@]}"properly passes all curl options including the Authorization header to both calls.Also applies to: 74-74
tools/install/_common.sh
Outdated
| ;; | ||
| esac | ||
|
|
||
| set -eux |
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.
Remove debug flag: set -eux should be deleted.
The set -eux flag enables verbose command output (-x) which will clutter build logs during tool installations. The PR description states you previously added this for debugging and then removed it, but it's still present in the code. Remove this line to keep build output clean.
- set -eux
-
# Download tool📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| set -eux |
🤖 Prompt for AI Agents
In tools/install/_common.sh around line 61, remove the debug flag invocation
"set -eux" (or replace it with a minimal safe set like "set -e" if you want to
keep exit-on-error), so that the script no longer enables verbose command
tracing (-x) which clutters build logs; update the file to delete that line and
run a quick lint/run of the installer to confirm no unintended side effects.
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.
Will amend to remove that.
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.
@wI2L, thank you for confirming! Looking forward to seeing the updated code. 👍
|
Here are the build logs, for 3 different scenarios. I have added a temporary
|
76b30ac to
90abf9c
Compare
Looks great. Thank you. Hopefully @MaxymVlasov will have a chance to review shortly. |
yermulnik
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.
LGTM. Differing approval to @MaxymVlasov
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.
Regarding failed checks, they are not related to your PR.
Checking with @webknjaz how to fix it, as previously it worked fine.
Sadly, but we will not be able to merge it w/o bypassing branch-protection requirements, so we'll try to figure it out quickly
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.
No worries, I'm not in a hurry 👍
90abf9c to
cc97605
Compare
cc97605 to
a30feaf
Compare
Accept build arg `GITHUB_TOKEN` to authenticate calls made to GitHub API in `common::install_from_gh_release` function. Closes antonbabenko#946
a30feaf to
4619ea1
Compare
docker build
|
Thank you @MaxymVlasov for the followup |
# [1.104.0](v1.103.0...v1.104.0) (2025-11-20) ### Features * **docker:** Allow authenticated calls to GitHub API ([#947](#947)) ([6deaf20](6deaf20))
|
This PR is included in version 1.104.0 🎉 |
Accept build arg
GITHUB_TOKENto authenticate calls made to GitHub API incommon::install_from_gh_releasefunction.Closes #946
Put an
xinto the box if that apply:Description of your changes
Accept build arg
GITHUB_TOKENto authenticate calls made to GitHub API incommon::install_from_gh_releasefunction.How can we test changes
Generate a GitHub PAT and export it in your env.
Run
docker build -t pre-commit-terraform --build-arg GITHUB_TOKEN --build-arg INSTALL_ALL=true .to build thepre-commit, using the PAT during build time to authenticate calls.