get-build.sh 2.4 KB

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