update_mirror.sh 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. # Script to upload github archives for bazel dependencies to GCS, creating a reliable mirror link.
  16. # Archives are copied to "grpc-bazel-mirror" GCS bucket (https://console.cloud.google.com/storage/browser/grpc-bazel-mirror?project=grpc-testing)
  17. # and will by downloadable with the https://storage.googleapis.com/grpc-bazel-mirror/ prefix.
  18. #
  19. # This script should be run each time bazel dependencies are updated.
  20. set -e
  21. cd $(dirname $0)/..
  22. # Create a temp directory to hold the versioned tarball,
  23. # and clean it up when the script exits.
  24. tmpdir="$(mktemp -d)"
  25. function cleanup {
  26. rm -rf "$tmpdir"
  27. }
  28. trap cleanup EXIT
  29. function upload {
  30. local file="$1"
  31. if gsutil stat "gs://grpc-bazel-mirror/${file}" > /dev/null
  32. then
  33. echo "Skipping ${file}"
  34. else
  35. echo "Downloading https://${file}"
  36. curl -L --fail --output "${tmpdir}/archive" "https://${file}"
  37. echo "Uploading https://${file} to https://storage.googleapis.com/grpc-bazel-mirror/${file}"
  38. gsutil cp "${tmpdir}/archive" "gs://grpc-bazel-mirror/${file}"
  39. rm -rf "${tmpdir}/archive"
  40. fi
  41. }
  42. # How to check that all mirror URLs work:
  43. # 1. clean $HOME/.cache/bazel
  44. # 2. bazel clean --expunge
  45. # 3. bazel sync (failed downloads will print warnings)
  46. # A specific link can be upload manually by running e.g.
  47. # upload "github.com/google/boringssl/archive/1c2769383f027befac5b75b6cedd25daf3bf4dcf.tar.gz"
  48. # bazel binaries used by the tools/bazel wrapper script
  49. upload github.com/bazelbuild/bazel/releases/download/1.0.0/bazel-1.0.0-linux-x86_64
  50. upload github.com/bazelbuild/bazel/releases/download/1.0.0/bazel-1.0.0-darwin-x86_64
  51. upload github.com/bazelbuild/bazel/releases/download/1.0.0/bazel-1.0.0-windows-x86_64.exe
  52. upload github.com/bazelbuild/bazel/releases/download/2.2.0/bazel-2.2.0-linux-x86_64
  53. upload github.com/bazelbuild/bazel/releases/download/2.2.0/bazel-2.2.0-darwin-x86_64
  54. upload github.com/bazelbuild/bazel/releases/download/2.2.0/bazel-2.2.0-windows-x86_64.exe
  55. upload github.com/bazelbuild/bazel/releases/download/3.7.1/bazel-3.7.1-linux-x86_64
  56. upload github.com/bazelbuild/bazel/releases/download/3.7.1/bazel-3.7.1-darwin-x86_64
  57. upload github.com/bazelbuild/bazel/releases/download/3.7.1/bazel-3.7.1-windows-x86_64.exe
  58. upload github.com/bazelbuild/bazel/releases/download/4.2.1/bazel-4.2.1-linux-x86_64
  59. upload github.com/bazelbuild/bazel/releases/download/4.2.1/bazel-4.2.1-darwin-x86_64
  60. upload github.com/bazelbuild/bazel/releases/download/4.2.1/bazel-4.2.1-windows-x86_64.exe
  61. # Collect the github archives to mirror from grpc_deps.bzl
  62. grep -o '"https://github.com/[^"]*"' bazel/grpc_deps.bzl | sed 's/^"https:\/\///' | sed 's/"$//' | while read -r line ; do
  63. echo "Updating mirror for ${line}"
  64. upload "${line}"
  65. done