1#!/bin/bash 2# Copyright 2020 The gRPC Authors 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16# Script to upload github archives for bazel dependencies to GCS, creating a reliable mirror link. 17# Archives are copied to "grpc-bazel-mirror" GCS bucket (https://console.cloud.google.com/storage/browser/grpc-bazel-mirror?project=grpc-testing) 18# and will by downloadable with the https://storage.googleapis.com/grpc-bazel-mirror/ prefix. 19# 20# This script should be run each time bazel dependencies are updated. 21 22set -e 23 24cd $(dirname $0)/.. 25 26# Create a temp directory to hold the versioned tarball, 27# and clean it up when the script exits. 28tmpdir="$(mktemp -d)" 29function cleanup { 30 rm -rf "$tmpdir" 31} 32trap cleanup EXIT 33 34function upload { 35 local file="$1" 36 37 echo "Downloading https://${file}" 38 curl -L --fail --output "${tmpdir}/archive" "https://${file}" 39 40 echo "Uploading https://${file} to https://storage.googleapis.com/grpc-bazel-mirror/${file}" 41 gsutil cp -n "${tmpdir}/archive" "gs://grpc-bazel-mirror/${file}" # "-n" will skip existing files 42 43 rm -rf "${tmpdir}/archive" 44} 45 46# How to check that all mirror URLs work: 47# 1. clean $HOME/.cache/bazel 48# 2. bazel clean --expunge 49# 3. bazel sync (failed downloads will print warnings) 50 51# A specific link can be upload manually by running e.g. 52# upload "github.com/google/boringssl/archive/1c2769383f027befac5b75b6cedd25daf3bf4dcf.tar.gz" 53 54# bazel binaries used by the tools/bazel wrapper script 55upload github.com/bazelbuild/bazel/releases/download/1.0.0/bazel-1.0.0-linux-x86_64 56upload github.com/bazelbuild/bazel/releases/download/1.0.0/bazel-1.0.0-darwin-x86_64 57upload github.com/bazelbuild/bazel/releases/download/1.0.0/bazel-1.0.0-windows-x86_64.exe 58 59upload github.com/bazelbuild/bazel/releases/download/2.2.0/bazel-2.2.0-linux-x86_64 60upload github.com/bazelbuild/bazel/releases/download/2.2.0/bazel-2.2.0-darwin-x86_64 61upload github.com/bazelbuild/bazel/releases/download/2.2.0/bazel-2.2.0-windows-x86_64.exe 62 63upload github.com/bazelbuild/bazel/releases/download/3.7.1/bazel-3.7.1-linux-x86_64 64upload github.com/bazelbuild/bazel/releases/download/3.7.1/bazel-3.7.1-darwin-x86_64 65upload github.com/bazelbuild/bazel/releases/download/3.7.1/bazel-3.7.1-windows-x86_64.exe 66 67# Collect the github archives to mirror from grpc_deps.bzl 68grep -o '"https://github.com/[^"]*"' bazel/grpc_deps.bzl | sed 's/^"https:\/\///' | sed 's/"$//' | while read -r line ; do 69 echo "Updating mirror for ${line}" 70 upload "${line}" 71done 72