k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/hack/get-build.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2015 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # This script runs `curl` command to get the kubernetes build file. 18 # Version number or publication is either a proper version number' 19 # (e.g. "v1.0.6", "v1.2.0-alpha.1.881+376438b69c7612") or a version' 20 # publication of the form <bucket>/<version> (e.g. "release/stable",' 21 # "ci/latest-1").' 22 23 # Usage `hack/get-build.sh [Version]`. 24 # Example `hack/get-build.sh v1.16.4`. 25 26 set -o errexit 27 set -o nounset 28 set -o pipefail 29 30 KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. 31 32 source "${KUBE_ROOT}/cluster/common.sh" 33 34 declare -r KUBE_RELEASE_BUCKET_URL="https://dl.k8s.io/" 35 declare -r KUBE_DEV_RELEASE_BUCKET_URL="https://storage.googleapis.com/k8s-release-dev" 36 declare -r KUBE_TAR_NAME="kubernetes.tar.gz" 37 38 usage() { 39 echo "${0} [-v] <version number or publication>" 40 echo " -v: Don't get tars, just print the version number" 41 echo "" 42 echo ' Version number or publication is either a proper version number' 43 echo ' (e.g. "v1.0.6", "v1.2.0-alpha.1.881+376438b69c7612") or a version' 44 echo ' publication of the form <bucket>/<version> (e.g. "release/stable",' 45 echo ' "ci/latest-1"). Some common ones are:' 46 echo ' - "release/stable"' 47 echo ' - "release/latest"' 48 echo ' - "ci/latest"' 49 echo ' See the docs on getting builds for more information about version' 50 echo ' publication.' 51 } 52 53 print_version=false 54 55 while getopts ":vh" opt; do 56 case ${opt} in 57 v) 58 print_version="true" 59 ;; 60 h) 61 usage 62 exit 0 63 ;; 64 \?) 65 echo "Invalid option: -$OPTARG" >&2 66 usage 67 exit 1 68 ;; 69 esac 70 done 71 shift $((OPTIND-1)) 72 73 if [[ $# -ne 1 ]]; then 74 usage 75 exit 1 76 fi 77 78 set_binary_version "${1}" 79 80 if [[ "${print_version}" == "true" ]]; then 81 echo "${KUBE_VERSION}" 82 else 83 echo "Using version at ${1}: ${KUBE_VERSION}" >&2 84 if [[ ${KUBE_VERSION} =~ ${KUBE_RELEASE_VERSION_REGEX} ]]; then 85 curl -L --fail -o "kubernetes-${KUBE_VERSION}.tar.gz" "${KUBE_RELEASE_BUCKET_URL}/release/${KUBE_VERSION}/${KUBE_TAR_NAME}" 86 elif [[ ${KUBE_VERSION} =~ ${KUBE_CI_VERSION_REGEX} ]]; then 87 curl --fail -o "kubernetes-${KUBE_VERSION}.tar.gz" "${KUBE_DEV_RELEASE_BUCKET_URL}/ci/${KUBE_VERSION}/${KUBE_TAR_NAME}" 88 else 89 echo "Version doesn't match regexp" >&2 90 exit 1 91 fi 92 fi