| 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 |
|
| 22 |
set -e |
| 23 |
|
| 24 |
cd $(dirname $0)/.. |
| 25 |
|
| 26 |
# Create a temp directory to hold the versioned tarball, |
| 27 |
# and clean it up when the script exits. |
| 28 |
tmpdir="$(mktemp -d)" |
| 29 |
function cleanup { |
| 30 |
rm -rf "$tmpdir" |
| 31 |
} |
| 32 |
trap cleanup EXIT |
| 33 |
|
| 34 |
function upload { |
| 35 |
local file="$1" |
| 36 |
|
| 37 |
if gsutil stat "gs://grpc-bazel-mirror/${file}" > /dev/null |
| 38 |
then |
| 39 |
echo "Skipping ${file}" |
| 40 |
else |
| 41 |
echo "Downloading https://${file}" |
| 42 |
curl -L --fail --output "${tmpdir}/archive" "https://${file}" |
| 43 |
|
| 44 |
echo "Uploading https://${file} to https://storage.googleapis.com/grpc-bazel-mirror/${file}" |
| 45 |
gsutil cp "${tmpdir}/archive" "gs://grpc-bazel-mirror/${file}" |
| 46 |
|
| 47 |
rm -rf "${tmpdir}/archive" |
| 48 |
fi |
| 49 |
} |
| 50 |
|
| 51 |
# How to check that all mirror URLs work: |
| 52 |
# 1. clean $HOME/.cache/bazel |
| 53 |
# 2. bazel clean --expunge |
| 54 |
# 3. bazel sync (failed downloads will print warnings) |
| 55 |
|
| 56 |
# A specific link can be upload manually by running e.g. |
| 57 |
# upload "github.com/google/boringssl/archive/1c2769383f027befac5b75b6cedd25daf3bf4dcf.tar.gz" |
| 58 |
|
| 59 |
# bazel binaries used by the tools/bazel wrapper script |
| 60 |
upload github.com/bazelbuild/bazel/releases/download/1.0.0/bazel-1.0.0-linux-x86_64 |
| 61 |
upload github.com/bazelbuild/bazel/releases/download/1.0.0/bazel-1.0.0-darwin-x86_64 |
| 62 |
upload github.com/bazelbuild/bazel/releases/download/1.0.0/bazel-1.0.0-windows-x86_64.exe |
| 63 |
|
| 64 |
upload github.com/bazelbuild/bazel/releases/download/2.2.0/bazel-2.2.0-linux-x86_64 |
| 65 |
upload github.com/bazelbuild/bazel/releases/download/2.2.0/bazel-2.2.0-darwin-x86_64 |
| 66 |
upload github.com/bazelbuild/bazel/releases/download/2.2.0/bazel-2.2.0-windows-x86_64.exe |
| 67 |
|
| 68 |
upload github.com/bazelbuild/bazel/releases/download/3.7.1/bazel-3.7.1-linux-x86_64 |
| 69 |
upload github.com/bazelbuild/bazel/releases/download/3.7.1/bazel-3.7.1-darwin-x86_64 |
| 70 |
upload github.com/bazelbuild/bazel/releases/download/3.7.1/bazel-3.7.1-windows-x86_64.exe |
| 71 |
|
| 72 |
upload github.com/bazelbuild/bazel/releases/download/4.2.1/bazel-4.2.1-linux-x86_64 |
| 73 |
upload github.com/bazelbuild/bazel/releases/download/4.2.1/bazel-4.2.1-darwin-x86_64 |
| 74 |
upload github.com/bazelbuild/bazel/releases/download/4.2.1/bazel-4.2.1-windows-x86_64.exe |
| 75 |
|
| 76 |
upload github.com/bazelbuild/bazel/releases/download/5.3.0/bazel-5.3.0-linux-x86_64 |
| 77 |
upload github.com/bazelbuild/bazel/releases/download/5.3.0/bazel-5.3.0-darwin-x86_64 |
| 78 |
upload github.com/bazelbuild/bazel/releases/download/5.3.0/bazel-5.3.0-windows-x86_64.exe |
| 79 |
|
| 80 |
# Collect the github archives to mirror from grpc_deps.bzl |
| 81 |
grep -o '"https://github.com/[^"]*"' bazel/grpc_deps.bzl | sed 's/^"https:\/\///' | sed 's/"$//' | while read -r line ; do |
| 82 |
echo "Updating mirror for ${line}" |
| 83 |
upload "${line}" |
| 84 |
done |