| 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 | # |
| 18 | # Builds and installs runc to /usr/local/go/bin based off |
| 19 | # the commit defined in go.mod |
| 20 | # |
| 21 | set -eu -o pipefail |
| 22 | |
| 23 | script_dir="$(cd -- "$(dirname -- "$0")" > /dev/null 2>&1; pwd -P)" |
| 24 | |
| 25 | # e2e and Cirrus will fail with "sudo: command not found" |
| 26 | SUDO='' |
| 27 | if (( $EUID != 0 )); then |
| 28 | SUDO='sudo' |
| 29 | fi |
| 30 | |
| 31 | function install_runc() { |
| 32 | # When updating runc-version, consider updating the runc module in go.mod as well |
| 33 | : "${RUNC_VERSION:=$(cat "${script_dir}/runc-version")}" |
| 34 | : "${RUNC_REPO:=https://github.com/opencontainers/runc.git}" |
| 35 | |
| 36 | TMPROOT=$(mktemp -d) |
| 37 | trap "rm -fR ${TMPROOT}" EXIT |
| 38 | git clone "${RUNC_REPO}" "${TMPROOT}"/runc |
| 39 | pushd "${TMPROOT}"/runc |
| 40 | git checkout "${RUNC_VERSION}" |
| 41 | env -u VERSION make BUILDTAGS='seccomp' runc |
| 42 | $SUDO make install |
| 43 | popd |
| 44 | } |
| 45 | |
| 46 | function install_crun() { |
| 47 | : "${CRUN_VERSION:=$(cat "${script_dir}/crun-version")}" |
| 48 | : "${CRUN_REPO:=https://github.com/containers/crun}" |
| 49 | $SUDO curl -S -o /usr/local/sbin/runc -L "${CRUN_REPO}"/releases/download/"${CRUN_VERSION}"/crun-"${CRUN_VERSION}"-linux-"$(go env GOARCH)" |
| 50 | $SUDO chmod +x /usr/local/sbin/runc |
| 51 | } |
| 52 | |
| 53 | : "${RUNC_FLAVOR:=runc}" |
| 54 | case ${RUNC_FLAVOR} in |
| 55 | runc) install_runc ;; |
| 56 | crun) install_crun ;; |
| 57 | *) |
| 58 | echo >&2 "unknown runc flavor: ${RUNC_FLAVOR}" |
| 59 | exit 1 |
| 60 | ;; |
| 61 | esac |