Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

ci: Add installation scripts #71

Merged
merged 1 commit into from
Feb 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .ci/install_agent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
#
# Copyright (c) 2017-2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#

set -e

cidir=$(dirname "$0")

source "${cidir}/lib.sh"

clone_build_and_install "github.com/kata-containers/agent"
40 changes: 40 additions & 0 deletions .ci/install_kata_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
#
# Copyright (c) 2017-2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#

set -e

cidir=$(dirname "$0")

OSBUILDER_DISTRO=${OSBUILDER_DISTRO:-clearlinux}
image_name="kata-containers.img"

# Build Kata agent
bash -f ${cidir}/install_agent.sh

osbuilder_repo="github.com/kata-containers/osbuilder"

# Clone os-builder repository
go get -d ${osbuilder_repo} || true

pushd "${GOPATH}/src/${osbuilder_repo}/rootfs-builder"
sudo -E GOPATH=$GOPATH USE_DOCKER=true ./rootfs.sh ${OSBUILDER_DISTRO}
popd

# Build the image
pushd "${GOPATH}/src/${osbuilder_repo}/image-builder"
sudo -E USE_DOCKER=true ./image_builder.sh ../rootfs-builder/rootfs

# Install the image
agent_commit=$("$GOPATH/src/github.com/kata-containers/agent/kata-agent" --version | awk '{print $NF}')
commit=$(git log --format=%h -1 HEAD)
date=$(date +%Y-%m-%d-%T.%N%z)
image="kata-containers-${date}-osbuilder-${commit}-agent-${agent_commit}"

sudo install -o root -g root -m 0640 -D ${image_name} "/usr/share/kata-containers/${image}"
(cd /usr/share/kata-containers && sudo rm -f ${image_name} && sudo ln -s "$image" ${image_name})

popd
92 changes: 92 additions & 0 deletions .ci/install_kata_kernel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash
#
# Copyright (c) 2017-2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#

# Currently we will use this repository until this issue is solved
# See https://github.com/kata-containers/packaging/issues/1

set -e

cidir=$(dirname "$0")
source "${cidir}/lib.sh"

repo_owner="clearcontainers"
repo_name="linux"

linux_releases_url="https://github.com/${repo_owner}/${repo_name}/releases"
#fake repository dir to query kernel version from remote
fake_repo_dir=$(mktemp -t -d kata-kernel.XXXX)

function cleanup {
rm -rf "${fake_repo_dir}"
}

trap cleanup EXIT

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: double blank line.

function usage() {
cat << EOT
Usage: $0 <version>
Install the containers clear kernel image <version> from "${repo_owner}/${repo_name}".
version: Use 'latest' to pull latest kernel or a version from "${cc_linux_releases_url}"
EOT

exit 1
}

#Get latest version by checking remote tags
#We dont ask to github api directly because force a user to provide a GITHUB token
function get_latest_version {
pushd "${fake_repo_dir}" >> /dev/null
git init -q
git remote add origin https://github.com/"${repo_owner}/${repo_name}".git

cc_release=$(git ls-remote --tags 2>/dev/null \
| grep -oP '\-\d+\.container' \
| grep -oP '\d+' \
| sort -n | \
tail -1 )

tag=$(git ls-remote --tags 2>/dev/null \
| grep -oP "v\d+\.\d+\.\d+\-${cc_release}.container" \
| tail -1)

popd >> /dev/null
echo "${tag}"
}

function download_kernel() {
local version="$1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a local arch="$2 here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, make this function check arch (or maybe go env GOARCH) and download the correct architecture version.

See:

/cc @jcvenegas.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue is still outstanding.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arch=$(arch)
[ -n "${version}" ] || die "version not provided"
[ "${version}" == "latest" ] && version=$(get_latest_version)
echo "version to install ${version}"
local binaries_dir="${version}-binaries"
local binaries_tarball="${binaries_dir}.tar.gz"
local shasum_file="SHA512SUMS"
if [ "$arch" = x86_64 ]; then
curl -OL "${linux_releases_url}/download/${version}/${binaries_tarball}"
curl -OL "${linux_releases_url}/download/${version}/${shasum_file}"
sha512sum -c "${shasum_file}"
tar xf "${binaries_tarball}"
else
die "Unsupported architecture: $arch"
fi

pushd "${binaries_dir}"
sudo make install
popd
}

cc_kernel_version="$1"

[ -z "${cc_kernel_version}" ] && usage
download_kernel "${cc_kernel_version}"

# Make symbolic link to kata-containers
# FIXME: see https://github.com/kata-containers/packaging/issues/1
sudo ln -s /usr/share/clear-containers/vmlinux.container /usr/share/kata-containers/
sudo ln -s /usr/share/clear-containers/vmlinuz.container /usr/share/kata-containers/
14 changes: 14 additions & 0 deletions .ci/install_proxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
#
# Copyright (c) 2017-2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#

set -e

cidir=$(dirname "$0")

source "${cidir}/lib.sh"

clone_build_and_install "github.com/kata-containers/proxy"
38 changes: 38 additions & 0 deletions .ci/install_qemu_lite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
#
# Copyright (c) 2017-2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#

set -e

arch=$(arch)

if [ "$#" -ne 3 ]; then
echo "Usage: $0 <CLEAR_RELEASE> <QEMU_LITE_VERSION> <DISTRO>"
echo " Install the QEMU_LITE_VERSION from clear CLEAR_RELEASE."
exit 1
fi

clear_release="$1"
qemu_lite_version="$2"
distro="$3"
qemu_lite_bin="qemu-lite-bin-${qemu_lite_version}.${arch}.rpm"
qemu_lite_data="qemu-lite-data-${qemu_lite_version}.${arch}.rpm"

echo -e "Install qemu-lite ${qemu_lite_version}"

# download packages
curl -LO "https://download.clearlinux.org/releases/${clear_release}/clear/${arch}/os/Packages/${qemu_lite_bin}"
curl -LO "https://download.clearlinux.org/releases/${clear_release}/clear/${arch}/os/Packages/${qemu_lite_data}"

# install packages
if [ "$distro" == "ubuntu" ]; then
sudo alien -i "./${qemu_lite_bin}"
sudo alien -i "./${qemu_lite_data}"
fi

# cleanup
rm -f "./${qemu_lite_bin}"
rm -f "./${qemu_lite_data}"
53 changes: 53 additions & 0 deletions .ci/install_runtime.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
#
# Copyright (c) 2017-2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#

set -e

cidir=$(dirname "$0")

source "${cidir}/lib.sh"

# Modify the runtimes build-time defaults

# enable verbose build
export V=1

# tell the runtime build to use sane defaults
export SYSTEM_BUILD_TYPE=kata

# The runtimes config file should live here
export SYSCONFDIR=/etc

# Artifacts (kernel + image) live below here
export SHAREDIR=/usr/share

runtime_config_path="${SYSCONFDIR}/kata-containers/configuration.toml"

PKGDEFAULTSDIR="${SHAREDIR}/defaults/kata-containers"
NEW_RUNTIME_CONFIG="${PKGDEFAULTSDIR}/configuration.toml"
# Note: This will also install the config file.
clone_build_and_install "github.com/kata-containers/runtime"

# Check system supports running Kata Containers
kata-runtime kata-check

if [ -e "${NEW_RUNTIME_CONFIG}" ]; then
# Remove the legacy config file
sudo rm -f "${runtime_config_path}"

# Use the new path
runtime_config_path="${NEW_RUNTIME_CONFIG}"
fi

echo "Enabling all debug options in file ${runtime_config_path}"
sudo sed -i -e 's/^#\(enable_debug\).*=.*$/\1 = true/g' "${runtime_config_path}"

echo "Add runtime as a new/default Docker runtime. Docker version \"$(docker --version)\" could change according to updates."
docker_options="-D --add-runtime kata-runtime=/usr/local/bin/kata-runtime"

echo "Add kata-runtime as a new/default Docker runtime."
"${cidir}/../cmd/container-manager/manage_ctr_mgr.sh" docker configure -r kata-runtime -f
14 changes: 14 additions & 0 deletions .ci/install_shim.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
#
# Copyright (c) 2017-2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#

set -e

cidir=$(dirname "$0")

source "${cidir}/lib.sh"

clone_build_and_install "github.com/kata-containers/shim"
61 changes: 61 additions & 0 deletions .ci/lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
#
# Copyright (c) 2017-2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#

set -e

_runtime_repo="github.com/kata-containers/runtime"
# FIXME: Issue https://github.com/kata-containers/packaging/issues/1
_versions_file="$GOPATH/src/github.com/clearcontainers/runtime/versions.txt"

export KATA_RUNTIME=${KATA_RUNTIME:-cc}

# If we fail for any reason a message will be displayed
die(){
msg="$*"
echo "ERROR: $msg" >&2
exit 1
}

function clone_and_build() {
github_project="$1"
make_target="$2"
project_dir="${GOPATH}/src/${github_project}"

echo "Retrieve repository ${github_project}"
go get -d ${github_project} || true

# fixme: once tool to parse and get branches from github is
# completed, add it here to fetch branches under testing

pushd ${project_dir}

echo "Build ${github_project}"
if [ ! -f Makefile ]; then
echo "Run autogen.sh to generate Makefile"
bash -f autogen.sh
fi

make

popd
}

function clone_build_and_install() {
clone_and_build $1 $2
pushd "${GOPATH}/src/${1}"
echo "Install repository ${1}"
sudo -E PATH=$PATH KATA_RUNTIME=${KATA_RUNTIME} make install
popd
}

function get_cc_versions(){
# This is needed in order to retrieve the version for qemu-lite
cc_runtime_repo="github.com/clearcontainers/runtime"
go get -d -u -v "$cc_runtime_repo" || true
[ ! -f "$_versions_file" ] && { echo >&2 "ERROR: cannot find $_versions_file"; exit 1; }
source "$_versions_file"
}
33 changes: 33 additions & 0 deletions .ci/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
#
# Copyright (c) 2017-2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#

set -e

cidir=$(dirname "$0")
source /etc/os-release
source "${cidir}/lib.sh"

echo "Set up environment"
if [ "$ID" == ubuntu ];then
bash -f "${cidir}/setup_env_ubuntu.sh"
else
die "ERROR: Unrecognised distribution."
exit 1
fi

echo "Install shim"
bash -f ${cidir}/install_shim.sh

echo "Install proxy"
bash -f ${cidir}/install_proxy.sh

echo "Install runtime"
bash -f ${cidir}/install_runtime.sh

echo "Drop caches"
sync
sudo -E PATH=$PATH bash -c "echo 3 > /proc/sys/vm/drop_caches"
Loading