github.com/containerd/nerdctl@v1.7.7/hack/build-integration-kube.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright The containerd 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 # shellcheck disable=SC2034,SC2015 18 set -o errexit -o errtrace -o functrace -o nounset -o pipefail 19 root="$(cd "$(dirname "${BASH_SOURCE[0]:-$PWD}")" 2>/dev/null 1>&2 && pwd)" 20 readonly root 21 # shellcheck source=/dev/null 22 . "$root/scripts/lib.sh" 23 24 GO_VERSION=1.23 25 KIND_VERSION=v0.23.0 26 27 [ "$(uname -m)" == "aarch64" ] && GOARCH=arm64 || GOARCH=amd64 28 29 _rootful= 30 31 configure::rootful(){ 32 log::debug "Configuring rootful to: ${1:+true}" 33 _rootful="${1:+true}" 34 } 35 36 install::kind(){ 37 local version="$1" 38 local temp 39 temp="$(fs::mktemp "install")" 40 41 http::get "$temp"/kind "https://kind.sigs.k8s.io/dl/$version/kind-linux-${GOARCH:-amd64}" 42 host::install "$temp"/kind 43 } 44 45 # shellcheck disable=SC2120 46 install::kubectl(){ 47 local version="${1:-}" 48 [ "$version" ] || version="$(http::get /dev/stdout https://dl.k8s.io/release/stable.txt)" 49 local temp 50 temp="$(fs::mktemp "install")" 51 52 http::get "$temp"/kubectl "https://storage.googleapis.com/kubernetes-release/release/$version/bin/linux/${GOARCH:-amd64}/kubectl" 53 host::install "$temp"/kubectl 54 } 55 56 exec::kind(){ 57 local args=() 58 [ ! "$_rootful" ] || args=(sudo env PATH="$PATH" KIND_EXPERIMENTAL_PROVIDER="$KIND_EXPERIMENTAL_PROVIDER") 59 args+=(kind) 60 61 log::debug "${args[*]} $*" 62 "${args[@]}" "$@" 63 } 64 65 exec::nerdctl(){ 66 local args=() 67 [ ! "$_rootful" ] || args=(sudo env PATH="$PATH") 68 args+=("$(pwd)"/_output/nerdctl) 69 70 log::debug "${args[*]} $*" 71 "${args[@]}" "$@" 72 } 73 74 # Install dependencies 75 main(){ 76 log::info "Configuring rootful" 77 configure::rootful "${ROOTFUL:-}" 78 79 log::info "Installing host dependencies if necessary" 80 host::require kind 2>/dev/null || install::kind "$KIND_VERSION" 81 host::require kubectl 2>/dev/null || install::kubectl 82 83 # Build nerdctl to use for kind 84 make binaries 85 PATH=$(pwd)/_output:"$PATH" 86 export PATH 87 88 # Hack to get go into kind control plane 89 exec::nerdctl rm -f go-kind 2>/dev/null || true 90 exec::nerdctl run -d --name go-kind golang:"$GO_VERSION" sleep Inf 91 exec::nerdctl cp go-kind:/usr/local/go /tmp/go 92 93 # Create fresh cluster 94 log::info "Creating new cluster" 95 export KIND_EXPERIMENTAL_PROVIDER=nerdctl 96 exec::kind delete cluster --name nerdctl-test 2>/dev/null || true 97 exec::kind create cluster --name nerdctl-test --config=./hack/kind.yaml 98 } 99 100 main "$@"