get-build.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/usr/bin/env bash
  2. # Copyright 2015 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. # This script runs `curl` command to get the kubernetes build file.
  16. # Version number or publication is either a proper version number'
  17. # (e.g. "v1.0.6", "v1.2.0-alpha.1.881+376438b69c7612") or a version'
  18. # publication of the form <bucket>/<version> (e.g. "release/stable",'
  19. # "ci/latest-1").'
  20. # Usage `hack/get-build.sh [Version]`.
  21. # Example `hack/get-build.sh v1.16.4`.
  22. set -o errexit
  23. set -o nounset
  24. set -o pipefail
  25. KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
  26. source "${KUBE_ROOT}/cluster/common.sh"
  27. declare -r KUBE_RELEASE_BUCKET_URL="https://storage.googleapis.com/kubernetes-release"
  28. declare -r KUBE_DEV_RELEASE_BUCKET_URL="https://storage.googleapis.com/kubernetes-release-dev"
  29. declare -r KUBE_TAR_NAME="kubernetes.tar.gz"
  30. usage() {
  31. echo "${0} [-v] <version number or publication>"
  32. echo " -v: Don't get tars, just print the version number"
  33. echo ""
  34. echo ' Version number or publication is either a proper version number'
  35. echo ' (e.g. "v1.0.6", "v1.2.0-alpha.1.881+376438b69c7612") or a version'
  36. echo ' publication of the form <bucket>/<version> (e.g. "release/stable",'
  37. echo ' "ci/latest-1"). Some common ones are:'
  38. echo ' - "release/stable"'
  39. echo ' - "release/latest"'
  40. echo ' - "ci/latest"'
  41. echo ' See the docs on getting builds for more information about version'
  42. echo ' publication.'
  43. }
  44. print_version=false
  45. while getopts ":vh" opt; do
  46. case ${opt} in
  47. v)
  48. print_version="true"
  49. ;;
  50. h)
  51. usage
  52. exit 0
  53. ;;
  54. \?)
  55. echo "Invalid option: -$OPTARG" >&2
  56. usage
  57. exit 1
  58. ;;
  59. esac
  60. done
  61. shift $((OPTIND-1))
  62. if [[ $# -ne 1 ]]; then
  63. usage
  64. exit 1
  65. fi
  66. set_binary_version "${1}"
  67. if [[ "${print_version}" == "true" ]]; then
  68. echo "${KUBE_VERSION}"
  69. else
  70. echo "Using version at ${1}: ${KUBE_VERSION}" >&2
  71. if [[ ${KUBE_VERSION} =~ ${KUBE_RELEASE_VERSION_REGEX} ]]; then
  72. curl --fail -o "kubernetes-${KUBE_VERSION}.tar.gz" "${KUBE_RELEASE_BUCKET_URL}/release/${KUBE_VERSION}/${KUBE_TAR_NAME}"
  73. elif [[ ${KUBE_VERSION} =~ ${KUBE_CI_VERSION_REGEX} ]]; then
  74. curl --fail -o "kubernetes-${KUBE_VERSION}.tar.gz" "${KUBE_DEV_RELEASE_BUCKET_URL}/ci/${KUBE_VERSION}/${KUBE_TAR_NAME}"
  75. else
  76. echo "Version doesn't match regexp" >&2
  77. exit 1
  78. fi
  79. fi