Prevent Github API Rate Limits

When building netbox-docker on Travis, it happened too often that the
build failed because of Github's API rate limits. These apply for all
requests, but if the request is unauthenticated they are applied by IP.

This is bad for netbox-docker, as we build on Travis where the build-
workers are shared with the rest of the world.

This commit adds the possibility to define OAuth credentials as
documented at [1]. Hopefully this leads to more reliable releases of
netbox-docker images.

[1] https://developer.github.com/v3/#increasing-the-unauthenticated-rate-limit-for-oauth-applications
This commit is contained in:
Christian Mäder 2018-08-28 09:21:08 -07:00
parent aafa6483dc
commit 968bb9f10f
No known key found for this signature in database
GPG Key ID: 92FFD0A711F196BB
2 changed files with 18 additions and 2 deletions

View File

@ -3,9 +3,17 @@
echo "▶️ $0 $*" echo "▶️ $0 $*"
if [ ! -z "${GITHUB_OAUTH_CLIENT_ID}" ] && [ ! -z "${GITHUB_OAUTH_CLIENT_SECRET}" ]; then
echo "🗝 Performing authenticated Github API calls."
GITHUB_OAUTH_PARAMS="client_id=${GITHUB_OAUTH_CLIENT_ID}&client_secret=${GITHUB_OAUTH_CLIENT_SECRET}"
else
echo "🕶 Performing unauthenticated Github API calls. This might result in lower Github rate limits!"
GITHUB_OAUTH_PARAMS=""
fi
ORIGINAL_GITHUB_REPO="digitalocean/netbox" ORIGINAL_GITHUB_REPO="digitalocean/netbox"
GITHUB_REPO="${GITHUB_REPO-$ORIGINAL_GITHUB_REPO}" GITHUB_REPO="${GITHUB_REPO-$ORIGINAL_GITHUB_REPO}"
URL_RELEASES="https://api.github.com/repos/${GITHUB_REPO}/branches" URL_RELEASES="https://api.github.com/repos/${GITHUB_REPO}/branches?${GITHUB_OAUTH_PARAMS}"
CURL="curl -sS" CURL="curl -sS"

View File

@ -3,9 +3,17 @@
echo "▶️ $0 $*" echo "▶️ $0 $*"
if [ ! -z "${GITHUB_OAUTH_CLIENT_ID}" ] && [ ! -z "${GITHUB_OAUTH_CLIENT_SECRET}" ]; then
echo "🗝 Performing authenticated Github API calls."
GITHUB_OAUTH_PARAMS="client_id=${GITHUB_OAUTH_CLIENT_ID}&client_secret=${GITHUB_OAUTH_CLIENT_SECRET}"
else
echo "🕶 Performing unauthenticated Github API calls. This might result in lower Github rate limits!"
GITHUB_OAUTH_PARAMS=""
fi
ORIGINAL_GITHUB_REPO="digitalocean/netbox" ORIGINAL_GITHUB_REPO="digitalocean/netbox"
GITHUB_REPO="${GITHUB_REPO-$ORIGINAL_GITHUB_REPO}" GITHUB_REPO="${GITHUB_REPO-$ORIGINAL_GITHUB_REPO}"
URL_RELEASES="https://api.github.com/repos/${GITHUB_REPO}/releases" URL_RELEASES="https://api.github.com/repos/${GITHUB_REPO}/releases?${GITHUB_OAUTH_PARAMS}"
JQ_LATEST="group_by(.prerelease) | .[] | sort_by(.published_at) | reverse | .[0] | select(.prerelease==${PRERELEASE-false}) | .tag_name" JQ_LATEST="group_by(.prerelease) | .[] | sort_by(.published_at) | reverse | .[0] | select(.prerelease==${PRERELEASE-false}) | .tag_name"