Add helper script to install protoc

This commit is contained in:
Jordan Liggitt 2023-01-23 09:11:50 -05:00
parent 238e0226db
commit 3548e7febe
No known key found for this signature in database
3 changed files with 70 additions and 0 deletions

3
.gitignore vendored
View File

@ -64,6 +64,9 @@ network_closure.sh
/third_party/etcd*
/default.etcd
# Also ignore protoc installed by hack/install-protoc.sh
/third_party/protoc*
# User cluster configs
.kubeconfig

27
hack/install-protoc.sh Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env bash
# Copyright 2023 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script is convenience to download and install protoc in third_party.
# Usage: `hack/install-protoc.sh`.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${KUBE_ROOT}/hack/lib/protoc.sh"
kube::protoc::install

View File

@ -94,3 +94,43 @@ function kube::protoc::diff() {
exit 1
fi
}
function kube::protoc::install() {
# run in a subshell to isolate caller from directory changes
(
local os
local arch
local download_folder
local download_file
os=$(kube::util::host_os)
arch=$(kube::util::host_arch)
download_folder="protoc-v${PROTOC_VERSION}-${os}-${arch}"
download_file="${download_folder}.zip"
cd "${KUBE_ROOT}/third_party" || return 1
if [[ $(readlink protoc) != "${download_folder}" ]]; then
local url
if [[ ${os} == "darwin" ]]; then
# TODO: switch to universal binary when updating to 3.20+
url="https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-osx-x86_64.zip"
elif [[ ${os} == "linux" && ${arch} == "amd64" ]]; then
url="https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip"
elif [[ ${os} == "linux" && ${arch} == "arm64" ]]; then
url="https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-aarch_64.zip"
else
kube::log::info "This install script does not support ${os}/${arch}"
return 1
fi
kube::util::download_file "${url}" "${download_file}"
unzip -o "${download_file}" -d "${download_folder}"
ln -fns "${download_folder}" protoc
mv protoc/bin/protoc protoc/protoc
chmod -R +rX protoc/protoc
rm -fr protoc/include
rm "${download_file}"
fi
kube::log::info "protoc v${PROTOC_VERSION} installed. To use:"
kube::log::info "export PATH=\"$(pwd)/protoc:\${PATH}\""
)
}