From 968bb9f10fb6440cd319642037e71e0a678594a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Tue, 28 Aug 2018 09:21:08 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Prevent=20Github=20API=20Rate=20Lim?= =?UTF-8?q?its?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- build-branches.sh | 10 +++++++++- build-latest.sh | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/build-branches.sh b/build-branches.sh index 36c55d7..3bd93a9 100755 --- a/build-branches.sh +++ b/build-branches.sh @@ -3,9 +3,17 @@ 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" 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" diff --git a/build-latest.sh b/build-latest.sh index e996251..d903f8f 100755 --- a/build-latest.sh +++ b/build-latest.sh @@ -3,9 +3,17 @@ 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" 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"