From ef64786cda0607231707c29526555948c085a2d7 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Fri, 28 Sep 2018 16:02:51 +0100 Subject: terraform: move providers to terraform-providers Before, providers were only built indirectly. Since proviers don't depend on terraform to build they can be moved into their own collection of packages. This also has the advantage that they can be reached directly using an attribute path (Eg: terraform-providers.nixos). Co-authored-by: Wael Nasreddine --- .../cluster/terraform-providers/update-all | 143 +++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100755 pkgs/applications/networking/cluster/terraform-providers/update-all (limited to 'pkgs/applications/networking/cluster/terraform-providers/update-all') diff --git a/pkgs/applications/networking/cluster/terraform-providers/update-all b/pkgs/applications/networking/cluster/terraform-providers/update-all new file mode 100755 index 000000000000..2009d474db7b --- /dev/null +++ b/pkgs/applications/networking/cluster/terraform-providers/update-all @@ -0,0 +1,143 @@ +#!/usr/bin/env nix-shell +#! nix-shell -i bash -p bash coreutils curl jq nix +# vim: ft=sh sw=2 et +# +# This scripts scans the github terraform-providers repo for new releases, +# generates the corresponding nix code and finally generates an index of +# all the providers given in ./providers.txt. +set -euo pipefail + +# the maximum number of attempts before giving up inside of GET and prefetch_github +readonly maxAttempts=30 + +GET() { + local url=$1 + local retry=1 + echo "fetching $url" >&2 + while ! curl -#fL -u "$GITHUB_AUTH" "$url"; do + echo "The curl command has failed. Attempt $retry/${maxAttempts}" >&2 + if [[ "${retry}" -eq "${maxAttempts}" ]]; then + exit 1 + fi + retry=$(( retry + 1 )) + sleep 5 + done +} + +get_org_repos() { + local org=$1 + local page=1 + GET "https://api.github.com/orgs/$org/repos?per_page=100" | jq -r '.[].name' +} + +get_repo_tags() { + local owner=$1 + local repo=$2 + GET "https://api.github.com/repos/$owner/$repo/git/refs/tags?per_page=100" | \ + jq -r '.[].ref' | \ + grep -v 'v\.' | \ + cut -d '/' -f 3- | \ + sort --version-sort +} + +prefetch_github() { + local owner=$1 + local repo=$2 + local rev=$3 + local retry=1 + while ! nix-prefetch-url --unpack "https://github.com/$owner/$repo/archive/$rev.tar.gz"; do + echo "The nix-prefetch-url command has failed. Attempt $retry/${maxAttempts}" >&2 + if [[ "${retry}" -eq "${maxAttempts}" ]]; then + exit 1 + fi + retry=$(( retry + 1 )) + sleep 5 + done +} + +echo_entry() { + local owner=$1 + local repo=$2 + local version=${3:1} + local sha256=$4 + cat <> data.nix +} + +## Main ## + +cd "$(dirname "$0")" + +if [[ -z "${GITHUB_AUTH:-}" ]]; then + cat <<'HELP' +Missing the GITHUB_AUTH env. This is required to work around the 60 request +per hour rate-limit. + +Go to https://github.com/settings/tokens and create a new token with the +"public_repo" scope. + +Then `export GITHUB_AUTH=:` and run this script again. +HELP + exit 1 +fi + +cat <
data.nix +# Generated with ./update-all +{ +HEADER + +while read line; do + IFS=' ' read -r -a fields <<< "$line" + if [[ "${#fields[@]}" -eq 0 ]]; then + continue + fi + + if [[ "${fields[0]}" = *"/"* ]]; then + org="$(echo "${fields[0]}" | cut -d/ -f1)" + repo="$(echo "${fields[0]}" | cut -d/ -f2)" + add_repo "${org}" "${repo}" + else + org="${fields[0]}" + repos=$(get_org_repos "$org") + if [[ "${#fields[@]}" -ge 2 ]] && [[ -n "${fields[1]}" ]]; then + repos="$( echo "${repos[@]}" | grep "${fields[1]}" )" + fi + if [[ "${#fields[@]}" -eq 3 ]] && [[ -n "${fields[2]}" ]]; then + repos="$( echo "${repos[@]}" | grep -v "${fields[2]}" )" + fi + repos="$( echo "${repos[@]}" | sort )" + + for repo in $repos; do + add_repo "$org" "$repo" + done + fi +done < <(grep -v '^#\|^$' providers.txt) + +cat <