|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Copyright (c) 2023 Intel Corporation |
| 4 | +# |
| 5 | +# SPDX-License-Identifier: Apache-2.0 |
| 6 | +# |
| 7 | + |
| 8 | +set -o errexit |
| 9 | +set -o nounset |
| 10 | +set -o pipefail |
| 11 | + |
| 12 | +cidir=$(dirname "$0") |
| 13 | +source "${cidir}/../lib/common.bash" |
| 14 | + |
| 15 | +# Nydus related configurations |
| 16 | +NYDUS_SNAPSHOTTER_BINARY="/usr/local/bin/containerd-nydus-grpc" |
| 17 | +NYDUS_SNAPSHOTTER_TARFS_CONFIG="/usr/local/share/nydus-snapshotter/config-coco-host-sharing.toml" |
| 18 | +NYDUS_SNAPSHOTTER_GUEST_CONFIG="/usr/local/share/nydus-snapshotter/config-coco-guest-pulling.toml" |
| 19 | +NYDUS_SNAPSHOTTER_CONFIG="${NYDUS_SNAPSHOTTER_CONFIG:-${NYDUS_SNAPSHOTTER_TARFS_CONFIG}}" |
| 20 | +NYDUS_SNAPSHOTTER_TARFS_EXPORT_MODE="${NYDUS_SNAPSHOTTER_TARFS_EXPORT_MODE:-image_block}" |
| 21 | + |
| 22 | +echo "Configure nydus snapshotter" |
| 23 | +if [ "${IMAGE_OFFLOAD_TO_GUEST:-"no"}" == "yes" ]; then |
| 24 | + NYDUS_SNAPSHOTTER_CONFIG="${NYDUS_SNAPSHOTTER_GUEST_CONFIG}" |
| 25 | +else |
| 26 | + NYDUS_SNAPSHOTTER_CONFIG="${NYDUS_SNAPSHOTTER_TARFS_CONFIG}" |
| 27 | + sudo sed -i "s/export_mode = .*/export_mode = \"${NYDUS_SNAPSHOTTER_TARFS_EXPORT_MODE}\"/" "$NYDUS_SNAPSHOTTER_CONFIG" |
| 28 | +fi |
| 29 | + |
| 30 | +echo "Start nydus snapshotter" |
| 31 | +sudo "${NYDUS_SNAPSHOTTER_BINARY}" --config "${NYDUS_SNAPSHOTTER_CONFIG}" >/dev/stdout 2>&1 & |
| 32 | + |
| 33 | +echo "Configure containerd to use the nydus snapshotter" |
| 34 | + |
| 35 | +containerd_config_dir="/etc/containerd" |
| 36 | +containerd_config_file="${containerd_config_dir}/config.toml" |
| 37 | + |
| 38 | +snapshotter_socket="/run/containerd-nydus/containerd-nydus-grpc.sock" |
| 39 | +proxy_config=" [proxy_plugins.nydus]\n type = \"snapshot\"\n address = \"${snapshotter_socket}\"" |
| 40 | +snapshotter_config=" disable_snapshot_annotations = false\n snapshotter = \"nydus\"" |
| 41 | + |
| 42 | +# We're assuming here to be working on a clean VM. |
| 43 | +echo -e "[proxy_plugins]" | sudo tee -a "${containerd_config_file}" |
| 44 | +echo -e "${proxy_config}" | sudo tee -a "${containerd_config_file}" |
| 45 | +sudo sed -i '/\[plugins.cri.containerd\]/a\'"${snapshotter_config}" "${containerd_config_file}" |
| 46 | + |
| 47 | +restart_containerd_service |
0 commit comments