From c0cdc045a58f3519f18482b197cf8c897d06fdf7 Mon Sep 17 00:00:00 2001 From: Eric Ernst Date: Tue, 22 Jan 2019 22:24:38 +0000 Subject: [PATCH] kata-deploy: add script for configuring Docker Before the kata-deploy container image was intended to be used with only Kubernetes. This commit adds a script for configuring Kata to run with Docker. This assumes > release 1.5 of Kata, as Firecracker is being configured as well as QEMU based Kata. Note, in order for this to work, Docker must be configured to use a block-based storage driver. To succeed, it the following directories must be mounted: - /opt/kata - this is the location that the kata artifacts are stored - /run/systemd - for reloading the docker service - /var/run/dbus - for reloading the docker service - /etc/docker - for updating the docker configuration (daemon.json) usage: kata-deploy-kata [install | remove] Signed-off-by: Eric Ernst --- kata-deploy/Dockerfile | 3 + kata-deploy/scripts/kata-deploy-docker.sh | 111 ++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100755 kata-deploy/scripts/kata-deploy-docker.sh diff --git a/kata-deploy/Dockerfile b/kata-deploy/Dockerfile index 189d5c9f8..179517942 100644 --- a/kata-deploy/Dockerfile +++ b/kata-deploy/Dockerfile @@ -18,3 +18,6 @@ curl -Lso /bin/kubectl https://storage.googleapis.com/kubernetes-release/release chmod +x /bin/kubectl COPY scripts /opt/kata-artifacts/scripts +RUN \ +ln -s /opt/kata-artifacts/scripts/kata-deploy-docker.sh /usr/bin/kata-deploy-docker && \ +ln -s /opt/kata-artifacts/scripts/kata-deploy.sh /usr/bin/kata-deploy diff --git a/kata-deploy/scripts/kata-deploy-docker.sh b/kata-deploy/scripts/kata-deploy-docker.sh new file mode 100755 index 000000000..9987cdf99 --- /dev/null +++ b/kata-deploy/scripts/kata-deploy-docker.sh @@ -0,0 +1,111 @@ +#!/usr/bin/env bash +# Copyright (c) 2019 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 +# + +set -o errexit +set -o pipefail +set -o nounset + +conf_file="/etc/docker/daemon.json" +conf_file_backup="${conf_file}.bak" +snippet="${conf_file}.snip" +tmp_file="${conf_file}.tmp" + +# If we fail for any reason a message will be displayed +die() { + msg="$*" + echo "ERROR: $msg" >&2 + exit 1 +} + +function print_usage() { + echo "Usage: $0 [install/remove]" +} + +function install_artifacts() { + echo "copying kata artifacts onto host" + cp -a /opt/kata-artifacts/opt/kata/* /opt/kata/ + chmod +x /opt/kata/bin/* +} + +function configure_docker() { + echo "configuring docker" + + cat < "${tmp_file}" + mv "${tmp_file}" "${conf_file}" + rm "${snippet}" + else + mv "${snippet}" "${conf_file}" + fi + + systemctl daemon-reload + systemctl reload docker +} + +function remove_artifacts() { + echo "deleting kata artifacts" + rm -rf /opt/kata/ +} + +function cleanup_runtime() { + echo "cleanup docker" + rm -f "${conf_file}" + + if [ -f "${conf_file_backup}" ]; then + cp "${conf_file_backup}" "${conf_file}" + fi + systemctl daemon-reload + systemctl reload docker +} + +function main() { + # script requires that user is root + euid=`id -u` + if [[ $euid -ne 0 ]]; then + die "This script must be run as root" + fi + + action=${1:-} + if [ -z $action ]; then + print_usage + die "invalid arguments" + fi + + case $action in + install) + install_artifacts + configure_docker + ;; + remove) + cleanup_runtime + remove_artifacts + ;; + *) + echo invalid arguments + print_usage + ;; + esac +} + + +main $@