Skip to content

Commit 5e716dc

Browse files
authored
Merge pull request #192 from crazy-max/support-ghes
enforce baseUrl to api.github.com if action used on GHES
2 parents a024221 + a83788e commit 5e716dc

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ___
2828
* [Notes](#notes)
2929
* [`nodes` output](#nodes-output)
3030
* [BuildKit container logs](#buildkit-container-logs)
31+
* [Using on GHES](#using-on-ghes)
3132
* [Contributing](#contributing)
3233

3334
## Usage
@@ -174,6 +175,35 @@ The following [official docker environment variables](https://docs.docker.com/en
174175

175176
See https://docs.docker.com/build/ci/github-actions/configure-builder/#buildkit-container-logs
176177

178+
## Using on GHES
179+
180+
GitHub Runners come [pre-installed with Docker Buildx](https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2204-Readme.md)
181+
following your virtual environment. If you specify a version or `latest` of
182+
Docker Buildx in your workflow, the version will be downloaded from [GitHub Releases in `docker/buildx`](https://github.com/docker/buildx/releases)
183+
repository. These calls to `docker/buildx` are made via unauthenticated requests,
184+
which are limited to [60 requests per hour per IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting).
185+
186+
If more requests are made within the time frame, then you will start to see
187+
rate-limit errors during downloading that looks like:
188+
189+
```
190+
##[error]API rate limit exceeded for...
191+
```
192+
193+
To get a higher rate limit, you can [generate a personal access token on github.com](https://github.com/settings/tokens/new)
194+
and pass it as the `github_token` input for the action:
195+
196+
```yaml
197+
uses: docker/setup-buildx-action@v3
198+
with:
199+
github_token: ${{ secrets.GH_DOTCOM_TOKEN }}
200+
version: v0.10.1
201+
```
202+
203+
If the runner is not able to access `github.com`, it will take the default one
204+
available on the GitHub Runner or runner's tool cache. See "[Setting up the tool cache on self-hosted runners without internet access](https://docs.github.com/en/[email protected]/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access)"
205+
for more information.
206+
177207
## Contributing
178208

179209
Want to contribute? Awesome! You can find information about contributing to

action.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ inputs:
4545
description: 'Append additional nodes to the builder'
4646
required: false
4747
github_token:
48-
description: 'The GitHub token used to create an authenticated client for GitHub API'
49-
default: ${{ github.token }}
50-
required: false
48+
# https://github.com/actions/setup-go/blob/21459d0b7b1d63741429b748885bf5a4974593b4/action.yml#L12-L14
49+
description: >
50+
Used to verifiy the Git tag exists on docker/buildx repo. Since there's a
51+
default, this is typically not supplied by the user. When running this
52+
action on github.com, the default value is sufficient. When running on
53+
GHES, you can pass a personal access token for github.com if you are
54+
experiencing rate limiting.
55+
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
5156

5257
outputs:
5358
name:

dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/github.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ const [owner, repo] = 'docker/buildx'.split('/');
1010
export const getReleaseTag = async (tag: string, githubToken: string): Promise<Release> => {
1111
return (
1212
await github
13-
.getOctokit(githubToken)
13+
.getOctokit(githubToken, {
14+
baseUrl: 'https://api.github.com'
15+
})
1416
.rest.repos.getReleaseByTag({
1517
owner,
1618
repo,
@@ -25,7 +27,9 @@ export const getReleaseTag = async (tag: string, githubToken: string): Promise<R
2527
export const getLatestRelease = async (githubToken: string): Promise<Release> => {
2628
return (
2729
await github
28-
.getOctokit(githubToken)
30+
.getOctokit(githubToken, {
31+
baseUrl: 'https://api.github.com'
32+
})
2933
.rest.repos.getLatestRelease({
3034
owner,
3135
repo

0 commit comments

Comments
 (0)