mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-11 21:02:34 +00:00
Merge pull request #29 from jcvenegas/travis
ci: Add travis basic testing
This commit is contained in:
commit
052b8af497
15
.ci/run.sh
Executable file
15
.ci/run.sh
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Copyright (c) 2018 Intel Corporation
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
export GOPATH="${GOPATH:-/tmp/go}"
|
||||||
|
|
||||||
|
script_dir="$(dirname $(readlink -f $0))"
|
||||||
|
|
||||||
|
sudo -E PATH="$PATH" bats "${script_dir}/../tests/image_creation.bats"
|
20
.ci/setup.sh
Executable file
20
.ci/setup.sh
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Copyright (c) 2018 Intel Corporation
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
#Note: If add clearlinux as supported CI use a stateless os-release file
|
||||||
|
source /etc/os-release
|
||||||
|
|
||||||
|
if [ "$ID" == fedora ];then
|
||||||
|
sudo -E dnf -y install automake bats
|
||||||
|
elif [ "$ID" == ubuntu ];then
|
||||||
|
#bats isn't available for Ubuntu trusty, need for travis
|
||||||
|
sudo add-apt-repository -y ppa:duggan/bats
|
||||||
|
sudo apt-get -qq update
|
||||||
|
sudo apt-get install -y -qq automake bats qemu-utils
|
||||||
|
else
|
||||||
|
echo "Linux distribution not supported"
|
||||||
|
fi
|
19
.travis.yml
Normal file
19
.travis.yml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#
|
||||||
|
# Copyright (c) 2018 Intel Corporation
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
sudo: required
|
||||||
|
dist: trusty
|
||||||
|
|
||||||
|
language: bash
|
||||||
|
|
||||||
|
services:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- ".ci/setup.sh"
|
||||||
|
|
||||||
|
script:
|
||||||
|
- ".ci/run.sh"
|
3
image-builder/Dockerfile
Normal file
3
image-builder/Dockerfile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
From fedora:latest
|
||||||
|
|
||||||
|
RUN dnf install -y qemu-img parted gdisk e2fsprogs
|
@ -5,6 +5,10 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
script_name="${0##*/}"
|
||||||
|
script_dir="$(dirname $(readlink -f $0))"
|
||||||
|
|
||||||
if [ -n "$DEBUG" ] ; then
|
if [ -n "$DEBUG" ] ; then
|
||||||
set -x
|
set -x
|
||||||
fi
|
fi
|
||||||
@ -46,7 +50,9 @@ Options:
|
|||||||
-s Image size in MB (default $IMG_SIZE) ENV: IMG_SIZE
|
-s Image size in MB (default $IMG_SIZE) ENV: IMG_SIZE
|
||||||
|
|
||||||
Extra environment variables:
|
Extra environment variables:
|
||||||
AGENT_BIN: use it to change the expected agent binary name"
|
AGENT_BIN: use it to change the expected agent binary name"
|
||||||
|
USE_DOCKER: If set will build image in a Docker Container (requries docker)
|
||||||
|
DEFAULT: not set
|
||||||
EOT
|
EOT
|
||||||
exit "${error}"
|
exit "${error}"
|
||||||
}
|
}
|
||||||
@ -64,14 +70,45 @@ shift $(( $OPTIND - 1 ))
|
|||||||
|
|
||||||
ROOTFS="$1"
|
ROOTFS="$1"
|
||||||
|
|
||||||
|
|
||||||
[ -n "${ROOTFS}" ] || usage
|
[ -n "${ROOTFS}" ] || usage
|
||||||
[ -d "${ROOTFS}" ] || die "${ROOTFS} is not a directory"
|
[ -d "${ROOTFS}" ] || die "${ROOTFS} is not a directory"
|
||||||
|
|
||||||
|
ROOTFS=$(readlink -f ${ROOTFS})
|
||||||
|
IMAGE_DIR=$(dirname ${IMAGE})
|
||||||
|
IMAGE_DIR=$(readlink -f ${IMAGE_DIR})
|
||||||
|
IMAGE_NAME=$(basename ${IMAGE})
|
||||||
|
|
||||||
|
if [ -n "${USE_DOCKER}" ] ; then
|
||||||
|
image_name="image-builder-osbuilder"
|
||||||
|
|
||||||
|
docker build \
|
||||||
|
--build-arg http_proxy="${http_proxy}" \
|
||||||
|
--build-arg https_proxy="${https_proxy}" \
|
||||||
|
-t "${image_name}" "${script_dir}"
|
||||||
|
|
||||||
|
#Make sure we use a compatible runtime to build rootfs
|
||||||
|
# In case Clear Containers Runtime is installed we dont want to hit issue:
|
||||||
|
#https://github.com/clearcontainers/runtime/issues/828
|
||||||
|
docker run \
|
||||||
|
--runtime runc \
|
||||||
|
--privileged \
|
||||||
|
--env IMG_SIZE="${IMG_SIZE}" \
|
||||||
|
-v /dev:/dev \
|
||||||
|
-v "${script_dir}":"/osbuilder" \
|
||||||
|
-v "${ROOTFS}":"/rootfs" \
|
||||||
|
-v "${IMAGE_DIR}":"/image" \
|
||||||
|
${image_name} \
|
||||||
|
bash "/osbuilder/${script_name}" -o "/image/${IMAGE_NAME}" /rootfs
|
||||||
|
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
# The kata rootfs image expect init and kata-agent to be installed
|
# The kata rootfs image expect init and kata-agent to be installed
|
||||||
init="${ROOTFS_DIR}/sbin/init"
|
init="${ROOTFS}/sbin/init"
|
||||||
[ -x "${init}" ] || [ -L ${init} ] || die "/sbin/init is not installed in ${ROOTFS_DIR}"
|
[ -x "${init}" ] || [ -L ${init} ] || die "/sbin/init is not installed in ${ROOTFS_DIR}"
|
||||||
OK "init is installed"
|
OK "init is installed"
|
||||||
[ -x "${ROOTFS}/bin/${AGENT_BIN}" ] || \
|
[ -x "${ROOTFS}/bin/${AGENT_BIN}" ] || \
|
||||||
die "/bin/${AGENT_BIN} is not installed in ${ROOTFS_DIR}
|
die "/bin/${AGENT_BIN} is not installed in ${ROOTFS}
|
||||||
use AGENT_BIN env variable to change the expected agent binary name"
|
use AGENT_BIN env variable to change the expected agent binary name"
|
||||||
OK "Agent installed"
|
OK "Agent installed"
|
||||||
[ "$(id -u)" -eq 0 ] || die "$0: must be run as root"
|
[ "$(id -u)" -eq 0 ] || die "$0: must be run as root"
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
script_name="${0##*/}"
|
script_name="${0##*/}"
|
||||||
script_dir="$(dirname $(realpath -s $0))"
|
script_dir="$(dirname $(readlink -f $0))"
|
||||||
ROOTFS_DIR=${ROOTFS_DIR:-${PWD}/rootfs}
|
ROOTFS_DIR=${ROOTFS_DIR:-${PWD}/rootfs}
|
||||||
AGENT_VERSION=${AGENT_VERSION:-master}
|
AGENT_VERSION=${AGENT_VERSION:-master}
|
||||||
GO_AGENT_PKG=${GO_AGENT_PKG:-github.com/kata-containers/agent}
|
GO_AGENT_PKG=${GO_AGENT_PKG:-github.com/kata-containers/agent}
|
||||||
|
49
tests/image_creation.bats
Normal file
49
tests/image_creation.bats
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
#
|
||||||
|
# Copyright (c) 2018 Intel Corporation
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
|
||||||
|
rootfs_sh="$BATS_TEST_DIRNAME/../rootfs-builder/rootfs.sh"
|
||||||
|
image_builder_sh="$BATS_TEST_DIRNAME/../image-builder/image_builder.sh"
|
||||||
|
readonly tmp_dir=$(mktemp -t -d osbuilder-test.XXXXXXX)
|
||||||
|
#FIXME: Remove image size after https://github.com/kata-containers/osbuilder/issues/25 is fixed
|
||||||
|
readonly image_size=400
|
||||||
|
|
||||||
|
|
||||||
|
setup()
|
||||||
|
{
|
||||||
|
export USE_DOCKER=true
|
||||||
|
}
|
||||||
|
|
||||||
|
teardown(){
|
||||||
|
# Rootfs is own by root change it to remove it
|
||||||
|
sudo rm -rf "${tmp_dir}/rootfs-osbuilder"
|
||||||
|
rm -rf "${tmp_dir}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function build_image()
|
||||||
|
{
|
||||||
|
distro="$1"
|
||||||
|
[ -n "$distro" ]
|
||||||
|
local rootfs="${tmp_dir}/rootfs-osbuilder"
|
||||||
|
sudo -E ${rootfs_sh} -r "${rootfs}" fedora
|
||||||
|
sudo ${image_builder_sh} -s ${image_size} -o "${tmp_dir}/image.img" "${rootfs}"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Can create fedora image" {
|
||||||
|
build_image fedora
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Can create clearlinux image" {
|
||||||
|
build_image clearlinux
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Can create centos image" {
|
||||||
|
build_image centos
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Can create euleros image" {
|
||||||
|
build_image euleros
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user