github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/tools/installers/containerd.sh (about) 1 #!/bin/bash 2 3 # Copyright 2019 The gVisor 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 set -xeo pipefail 18 19 declare -r CONTAINERD_VERSION=${1:-1.3.0} 20 declare -r CONTAINERD_MAJOR="$(echo ${CONTAINERD_VERSION} | awk -F '.' '{ print $1; }')" 21 declare -r CONTAINERD_MINOR="$(echo ${CONTAINERD_VERSION} | awk -F '.' '{ print $2; }')" 22 23 # Default to an older version for crictl for containerd <= 1.2. 24 if [[ "${CONTAINERD_MAJOR}" -eq 1 ]] && [[ "${CONTAINERD_MINOR}" -le 2 ]]; then 25 declare -r CRITOOLS_VERSION=${CRITOOLS_VERSION:-1.13.0} 26 else 27 declare -r CRITOOLS_VERSION=${CRITOOLS_VERSION:-1.18.0} 28 fi 29 30 # Helper for Go packages below. 31 install_helper() { 32 PACKAGE="${1}" 33 TAG="${2}" 34 35 # Clone the repository. 36 mkdir -p "${GOPATH}"/src/$(dirname "${PACKAGE}") && \ 37 git clone https://"${PACKAGE}" "${GOPATH}"/src/"${PACKAGE}" 38 39 # Checkout and build the repository. 40 (cd "${GOPATH}"/src/"${PACKAGE}" && \ 41 git checkout "${TAG}" && \ 42 make && \ 43 make install) 44 } 45 46 # Figure out were btrfs headers are. 47 # 48 # Ubuntu 16.04 has only btrfs-tools, while 18.04 has a transitional package, 49 # and later versions no longer have the transitional package. 50 source /etc/os-release 51 declare BTRFS_DEV 52 if [[ "${VERSION_ID%.*}" -le "18" ]]; then 53 BTRFS_DEV="btrfs-tools" 54 else 55 BTRFS_DEV="libbtrfs-dev" 56 fi 57 readonly BTRFS_DEV 58 59 # Install dependencies for the crictl tests. 60 while true; do 61 if (apt-get update && apt-get install -y \ 62 "${BTRFS_DEV}" \ 63 libseccomp-dev); then 64 break 65 fi 66 result=$? 67 if [[ $result -ne 100 ]]; then 68 exit $result 69 fi 70 done 71 72 # Install containerd & cri-tools. 73 declare -rx GOPATH=$(mktemp -d --tmpdir gopathXXXXX) 74 install_helper github.com/containerd/containerd "v${CONTAINERD_VERSION}" "${GOPATH}" 75 install_helper github.com/kubernetes-sigs/cri-tools "v${CRITOOLS_VERSION}" "${GOPATH}" 76 77 # Configure containerd-shim. 78 declare -r shim_config_path=/etc/containerd/runsc/config.toml 79 mkdir -p $(dirname ${shim_config_path}) 80 cat > ${shim_config_path} <<-EOF 81 log_path = "/tmp/shim-logs/" 82 log_level = "debug" 83 84 [runsc_config] 85 debug = "true" 86 debug-log = "/tmp/runsc-logs/" 87 strace = "true" 88 file-access = "shared" 89 EOF 90 91 # Configure CNI. 92 (cd "${GOPATH}" && src/github.com/containerd/containerd/script/setup/install-cni) 93 cat <<EOF | sudo tee /etc/cni/net.d/10-bridge.conf 94 { 95 "cniVersion": "0.3.1", 96 "name": "bridge", 97 "type": "bridge", 98 "bridge": "cnio0", 99 "isGateway": true, 100 "ipMasq": true, 101 "ipam": { 102 "type": "host-local", 103 "ranges": [ 104 [{"subnet": "10.200.0.0/24"}] 105 ], 106 "routes": [{"dst": "0.0.0.0/0"}] 107 } 108 } 109 EOF 110 cat <<EOF | sudo tee /etc/cni/net.d/99-loopback.conf 111 { 112 "cniVersion": "0.3.1", 113 "type": "loopback" 114 } 115 EOF 116 117 # Configure crictl. 118 cat <<EOF | sudo tee /etc/crictl.yaml 119 runtime-endpoint: unix:///run/containerd/containerd.sock 120 EOF 121 122 # Cleanup. 123 rm -rf "${GOPATH}"