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

Conversation

GabyCT
Copy link
Contributor

@GabyCT GabyCT commented Feb 1, 2018

This will install runtime, shim, agent, proxy, qemu, and all dependencies
to run kata-containers.

Fixes #70

Signed-off-by: Gabriela Cervantes [email protected]

go get -d ${osbuilder_repo} || true

pushd "${GOPATH}/src/${osbuilder_repo}/rootfs-builder"
script -fec 'sudo -E GOPATH=$GOPATH USE_DOCKER=true ./rootfs.sh clearlinux'
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Can you remove the script -fec calls they don't really add much when called from the CI.

  • Could you make a variable for clearlinux as I think these scripts should be callable by developers.
    Something like:

    OSBUILDER_DISTRO=${OSBUILDER_DISTRO:-clearlinux}
    

# Install the image
commit=$(git log --format=%h -1 HEAD)
date=$(date +%Y-%m-%d-%T.%N%z)
image="kata-containers-${date}-${commit}"
Copy link
Contributor

Choose a reason for hiding this comment

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

My naming might be overkill here :-), but if we are going to use this, assuming users might want to run this script, how about making it:

agent_commit=$("$GOPATH/src/github.com/kata-containers/agent/kata-agent" --version | awk '{print $NF}')

image="kata-containers-${date}-osbuilder-${commit}-agent-${agent_commit}"

Admittedly, that's going to give a pretty long filename, but it captures some useful information (particularly since the agent is crucial and that agent version will include "dirty" if the code has been locally-modified).

Note that we could simplify this a lot if we implemented:

date=$(date +%Y-%m-%d-%T.%N%z)
image="kata-containers-${date}-${commit}"

sudo install -o root -g root -m 0640 -D kata-containers.img "/usr/share/kata-containers/${image}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you create a variable for kata-containers.img as it's used multiple times?

repo_name="linux"
cc_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 cc-kernel.XXXX)
Copy link
Contributor

Choose a reason for hiding this comment

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

I appreciate we're using the CC kernel for now, but I'd still drop the cc- here (or change it to kata-).

# SPDX-License-Identifier: Apache-2.0
#

repo_owner="clearcontainers"
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs a comment explaining that we're using CC kernels for now as we haven't started creating kata kernels yet.

I've raised an issue on the new Kata packaging repo for this btw (kata-containers/packaging#1), so could you add a "see $url" for that issue?


if [ "$VERSION_ID" == "16.04" ]; then
echo "Install os-tree"
sudo -E add-apt-repository ppa:alexlarsson/flatpak -y
Copy link
Contributor

Choose a reason for hiding this comment

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

I just checked and this is available for all arches ;)

sudo -E apt install -y libostree-dev

if ! command -v docker > /dev/null; then
"${cidir}/../cmd/container-manager/manage_ctr_mgr.sh" docker install
Copy link
Contributor

Choose a reason for hiding this comment

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

This tool needs to be imported into kata, but note that a fix for the following is going to be required:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jodh-intel , I removed the comment about this issue

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 this is the last issue then as this won't work currently afaics?

local binaries_dir="${version}-binaries"
local binaries_tarball="${binaries_dir}.tar.gz"
local shasum_file="SHA512SUMS"
curl -OL "${cc_linux_releases_url}/download/${version}/${binaries_tarball}"
Copy link
Contributor

Choose a reason for hiding this comment

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

This is architecture-specific and will break if arch != x86_64.

@jcvenegas - could you raise a bug and update your tooling so that the binaries file includes x86_64 in the name please?

qemu_lite_version="$2"
distro="$3"
qemu_lite_bin="qemu-lite-bin-${qemu_lite_version}.x86_64.rpm"
qemu_lite_data="qemu-lite-data-${qemu_lite_version}.x86_64.rpm"
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, use $arch here.

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

# download packages
curl -LO "https://download.clearlinux.org/releases/${clear_release}/clear/x86_64/os/Packages/${qemu_lite_bin}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Two more places to use $arch.

@GabyCT GabyCT force-pushed the topic/ci branch 2 times, most recently from 224105b to 8e1120a Compare February 2, 2018 16:34
@GabyCT
Copy link
Contributor Author

GabyCT commented Feb 2, 2018

@jodh-intel changes applied

}

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.

export V=1

# tell the runtime build to use sane defaults
export CC_SYSTEM_BUILD="yes"
Copy link
Contributor

Choose a reason for hiding this comment

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

This should now be,

export SYSTEM_BUILD_TYPE=kata

fi

echo "Enabling global logging for runtime in file ${runtime_config_path}"
sudo sed -i -e 's/^#\(\[runtime\]\|global_log_path =\)/\1/g' "${runtime_config_path}"
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't needed any more as all components now log to the system journal.

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 --default-runtime=kata-runtime"
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed here: #71 (comment)
We can remove the --default-runtime flag

@@ -0,0 +1,69 @@
#!/bin/bash -e
Copy link
Contributor

Choose a reason for hiding this comment

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

What about https://github.com/clearcontainers/tests/blob/master/.ci/setup_env_fedora.sh ? Is the plan to add that after this PR lands maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jodh-intel yes that is the idea :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ack.

.ci/lib.sh Outdated
clone_and_build $1 $2
pushd "${GOPATH}/src/${1}"
echo "Install repository ${1}"
if [ $1 == "github.com/kata-containers/runtime" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, I think this can become one line as this will work for all repos:

sudo -E PATH=$PATH KATA_RUNTIME=${KATA_RUNTIME} make install

.ci/lib.sh Outdated
popd
}

function get_cc_versions(){
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs a comment explaining why we are querying the Clear Containers runtime repo.

sudo modprobe kvm_intel nested=1
fi
else
die "Unsupported architecture: $arch"
Copy link
Contributor

Choose a reason for hiding this comment

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

Not defined? In fact, could you maybe add this function to lib.sh as it's so useful? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jodh-intel, I already did it

Copy link
Contributor

Choose a reason for hiding this comment

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

Great, thanks.

.ci/setup.sh Outdated
if [ "$ID" == ubuntu ];then
bash -f "${cidir}/setup_env_ubuntu.sh"
else
echo >&2 "ERROR: Unrecognised distribution."
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be a die call if you add die to lib.sh and source it before this line.

sudo -E apt install -y libostree-dev

if ! command -v docker > /dev/null; then
# This will be fixed by https://github.com/clearcontainers/tests/issues/881
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need this comment actually. Or if you leave it, could you explain what will be fixed by that issue?

What would be useful to note is that this sets the default Docker runtime to kata-runtime.

/cc @grahamwhaley.

Copy link
Contributor

Choose a reason for hiding this comment

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

So I'll ask the question - should or do we need to have kata-runtime as the default runtime?
Most/many of our tests use the RUNTIME env varialble to determine which runtime to pass to --runtime=xxx on the docker command line - and, if they don't, they should, to make it easier for us to have multiple runtimes installed for checking etc., without having to have them as the default runtime.

I suspect if we change this right now maybe a couple of tests fail - but that's probably the only way we'll find such tests. I propose we do not make our runtime the default runtime, and ensure our test frameworks can cope with being told which runtime they should invoke during testing.

FYI, afaik all the metrics tests pick up RUNTIME from the env. (but I do suspect there might be one or two we don't run often or under automation that still need updating).

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. And in fact if we rely on RUNTIME, we could always run the entire suite of tests multiples times without having to reconfigure Docker/k8s:

for runtime in runc kata-runtime-cc kata-runtime-runv
do
    # run tests...
done

Any further thoughts on this @chavafg ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with this approach.

@jodh-intel
Copy link
Contributor

@jcvenegas, @grahamwhaley - could you take a look at this please?

@GabyCT
Copy link
Contributor Author

GabyCT commented Feb 6, 2018

@jodh-intel changes applied

Copy link
Contributor

@jodh-intel jodh-intel left a comment

Choose a reason for hiding this comment

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

Thanks for updating @GabyCT. There are still a few outstanding issues to look at.

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: missing newline.

function usage() {
cat << EOT
Usage: $0 <version>
Install the containers clear kernel image <version> from "${repo_owner}"/"${repo_name}".
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: You could remove some double-quotes here:

... from "${repo_owner}/${repo_name}".

function get_latest_version {
pushd "${fake_repo_dir}" >> /dev/null
git init -q
git remote add origin https://github.com/clearcontainers/linux.git
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to use $repo_owner and $repo_name.

}

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.

This issue is still outstanding.

docker_https_proxy="HTTPS_PROXY=$https_proxy"
fi

cat << EOF | sudo tee ${config_path}/clear-containers.conf
Copy link
Contributor

Choose a reason for hiding this comment

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

s/clear-containers/kata-containers/.

But shouldn't we be using https://github.com/clearcontainers/tests/blob/master/cmd/container-manager/manage_ctr_mgr.sh here instead (in other words import that cmd on this PR too)?

@@ -0,0 +1,69 @@
#!/bin/bash -e
Copy link
Contributor

Choose a reason for hiding this comment

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

Ack.

sudo modprobe kvm_intel nested=1
fi
else
die "Unsupported architecture: $arch"
Copy link
Contributor

Choose a reason for hiding this comment

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

Great, thanks.

@GabyCT GabyCT force-pushed the topic/ci branch 2 times, most recently from b3bd210 to f6a7270 Compare February 7, 2018 15:54
@GabyCT
Copy link
Contributor Author

GabyCT commented Feb 7, 2018

@jodh-intel changes applied

@GabyCT
Copy link
Contributor Author

GabyCT commented Feb 7, 2018

@jodh-intel I remove the last lines as they did not work (as you mentioned) thanks :)

@jodh-intel
Copy link
Contributor

Hi @GabyCT - I think you just need to add the code for manage_ctr_mgr.sh and remove the manual configuration you're doing for Docker.

@GabyCT
Copy link
Contributor Author

GabyCT commented Feb 7, 2018

@jodh-intel the code for manage_ctr_mgr.sh should be part of the .ci scripts or should I put it in another place? also I see that this code is doing a configuration for swarm should this be removed?

@jodh-intel
Copy link
Contributor

Hi @GabyCT - I think you just need to copy the files in https://github.com/clearcontainers/tests/tree/master/cmd/container-manager into this PR (under the same location [`cmd/container-manager/]). You could do that on a separate commit but as the CI scripts are using the tool, it could be on the single commit you already have I think.

@chavafg - does that sound ok with you?

@chavafg
Copy link
Contributor

chavafg commented Feb 7, 2018

@GabyCT @jodh-intel yes, sounds good, also we would need to open an issue here for the arm support, and close in cc test repo?

@GabyCT
Copy link
Contributor Author

GabyCT commented Feb 7, 2018

@chavafg and @jodh-intel changes applied

@jodh-intel
Copy link
Contributor

Thanks @GabyCT, @chavafg.

lgtm

@jodh-intel
Copy link
Contributor

Hmm, pullapprove isn't seeing my ack. Let's try again...

lgtm

This will install runtime, shim, agent, proxy, qemu, and all dependencies
to run kata-containers.

Fixes kata-containers#70

Signed-off-by: Gabriela Cervantes <[email protected]>
@@ -0,0 +1,64 @@
#!/bin/bash -e
Copy link
Contributor

Choose a reason for hiding this comment

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

While testing this PR found that the -e didn't had any effect when we call the script using:
bash -f ${cidir}/setup_env_ubuntu.sh" , when errors appeared, the setup continued without failing.
So I would recommend that we explicitly add set -e to every script.

Copy link
Contributor

Choose a reason for hiding this comment

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

One thing I've considered doing to the metrics scripts is invoking all (sub)scripts with bash -$- ...., which then passes on the parent script settings to the child. That way if you set, say, -x on the top level script for debug, it will trickle through to all sub-scripts. Maybe that will work well for your -e situation ?

"${cidir}/install_qemu_lite.sh" "${qemu_lite_clear_release}" "${qemu_lite_sha}" "$ID"

echo "Install kata-containers image"
"${cidir}/install_kata_image.sh"
Copy link
Contributor

Choose a reason for hiding this comment

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

When we run this script, we already need docker, and if it is not installed, this will fail. We should install docker using the manage_ctr_mgr.sh script before calling install_kata_image.sh.

@@ -0,0 +1,321 @@
#!/bin/bash -e
Copy link
Contributor

Choose a reason for hiding this comment

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

Add execution permissions to this script

@GabyCT GabyCT force-pushed the topic/ci branch 2 times, most recently from efc859c to 00b4b25 Compare February 8, 2018 16:06
@GabyCT
Copy link
Contributor Author

GabyCT commented Feb 8, 2018

@chavafg changes applied

@chavafg chavafg merged commit 1797f61 into kata-containers:master Feb 8, 2018
@GabyCT GabyCT deleted the topic/ci branch November 5, 2019 15:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants