update-workspace-mirror.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/bash
  2. # Copyright 2018 The Kubernetes 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. set -o errexit
  16. set -o nounset
  17. set -o pipefail
  18. if [[ $# -ne 1 ]]; then
  19. echo 'use "bazel run //hack:update-mirror"'
  20. echo "(usage: $0 <file with list of URLs to mirror>)"
  21. exit 1
  22. fi
  23. BUCKET="gs://k8s-bazel-cache"
  24. gsutil acl get "${BUCKET}" > /dev/null
  25. tmpfile=$(mktemp bazel_workspace_mirror.XXXXXX)
  26. trap 'rm ${tmpfile}' EXIT
  27. while read -r url; do
  28. echo "${url}"
  29. if gsutil ls "${BUCKET}/${url}" &> /dev/null; then
  30. echo present
  31. else
  32. echo missing
  33. if curl -fLag "${url}" > "${tmpfile}"; then
  34. gsutil cp -a public-read "${tmpfile}" "${BUCKET}/${url}"
  35. fi
  36. fi
  37. done < "$1"