mirror of
https://github.com/rancher/os.git
synced 2025-09-17 15:40:47 +00:00
Merge pull request #558 from imikushin/test-custom-kernel
Test building with custom kernel and docker
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
FROM debian:jessie
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
RUN apt-get update && apt-get install -y grub2 parted
|
||||
|
||||
COPY ./scripts/installer /scripts
|
||||
COPY ./scripts/version /scripts/
|
||||
RUN /scripts/bootstrap
|
||||
COPY ./build.conf /scripts/
|
||||
|
||||
COPY ./dist/artifacts/vmlinuz /dist/vmlinuz
|
||||
COPY ./dist/artifacts/initrd /dist/initrd
|
||||
|
9
Makefile
9
Makefile
@@ -1,4 +1,5 @@
|
||||
include common.make
|
||||
include build.conf
|
||||
FORCE_PULL := 0
|
||||
|
||||
|
||||
compile: bin/rancheros
|
||||
@@ -30,6 +31,10 @@ build-all: ros-build-image
|
||||
docker cp ros-build:/go/src/github.com/rancherio/os/dist/artifacts dist/
|
||||
|
||||
|
||||
installer: ros-build-image
|
||||
./scripts/docker-run.sh --rm make -f Makefile.docker FORCE_PULL=$(FORCE_PULL) $@
|
||||
|
||||
|
||||
version:
|
||||
@echo $(VERSION)
|
||||
|
||||
@@ -38,4 +43,4 @@ clean:
|
||||
rm -rf bin build dist gopath .dockerfile
|
||||
|
||||
|
||||
.PHONY: all compile clean build-all ros-build-image ros-build-base version bin/rancheros
|
||||
.PHONY: all compile clean build-all ros-build-image ros-build-base version bin/rancheros installer
|
||||
|
@@ -1,8 +1,6 @@
|
||||
include common.make
|
||||
include build.conf
|
||||
FORCE_PULL := 0
|
||||
|
||||
DOCKER_BINARY_URL := https://github.com/rancher/docker/releases/download/v1.8.1-ros/docker-1.8.1
|
||||
KERNEL_URL := https://github.com/rancher/os-kernel/releases/download/Ubuntu-3.19.0-27.29-ros1/linux-3.19.8-ckt5-rancher-x86.tar.gz
|
||||
DFS_IMAGE := rancher/docker:1.8.1
|
||||
|
||||
bin/rancheros:
|
||||
mkdir -p $(dir $@)
|
||||
@@ -26,7 +24,7 @@ $(DIST)/artifacts/vmlinuz: $(BUILD)/kernel/
|
||||
|
||||
|
||||
$(BUILD)/kernel/:
|
||||
mkdir -p $@ && curl -L "$(KERNEL_URL)" | tar -xzf - -C $@ --strip=0
|
||||
mkdir -p $@ && curl -L "$(COMPILED_KERNEL_URL)" | tar -xzf - -C $@ --strip=0
|
||||
|
||||
|
||||
$(BUILD)/images.tar: bin/rancheros
|
||||
@@ -38,7 +36,7 @@ $(DIST)/artifacts/initrd: bin/rancheros assets/docker $(BUILD)/kernel/ $(BUILD)/
|
||||
DFS_IMAGE=$(DFS_IMAGE) ./scripts/mk-initrd.sh
|
||||
|
||||
|
||||
$(DIST)/artifacts/rancheros.iso: $(DIST)/artifacts/initrd $(DIST)/artifacts/vmlinuz
|
||||
$(DIST)/artifacts/rancheros.iso: minimal
|
||||
./scripts/mk-rancheros-iso.sh
|
||||
|
||||
|
||||
@@ -49,18 +47,16 @@ $(DIST)/artifacts/iso-checksums.txt: $(DIST)/artifacts/rancheros.iso
|
||||
version:
|
||||
@echo $(VERSION)
|
||||
|
||||
installer: $(DIST)/artifacts/initrd $(DIST)/artifacts/vmlinuz
|
||||
docker build -t rancher/os:$(VERSION) .
|
||||
installer: minimal
|
||||
docker build -t $(IMAGE_NAME):$(VERSION) .
|
||||
|
||||
build-all: \
|
||||
installer \
|
||||
bin/rancheros \
|
||||
$(DIST)/artifacts/initrd \
|
||||
$(DIST)/artifacts/vmlinuz \
|
||||
$(DIST)/artifacts/rancheros.iso \
|
||||
$(DIST)/artifacts/iso-checksums.txt
|
||||
build-all: minimal installer iso
|
||||
|
||||
minimal: $(DIST)/artifacts/initrd $(DIST)/artifacts/vmlinuz
|
||||
|
||||
iso: $(DIST)/artifacts/rancheros.iso $(DIST)/artifacts/iso-checksums.txt
|
||||
|
||||
integration-tests:
|
||||
cd tests/integration && tox
|
||||
|
||||
.PHONY: build-all installer version bin/rancheros integration-tests
|
||||
.PHONY: build-all minimal iso installer version bin/rancheros integration-tests
|
||||
|
6
build.conf
Normal file
6
build.conf
Normal file
@@ -0,0 +1,6 @@
|
||||
IMAGE_NAME=rancher/os
|
||||
VERSION=v0.4.0-dev
|
||||
|
||||
DOCKER_BINARY_URL=https://github.com/rancher/docker/releases/download/v1.8.1-ros/docker-1.8.1
|
||||
COMPILED_KERNEL_URL=https://github.com/rancher/os-kernel/releases/download/Ubuntu-3.19.0-27.29-ros1/linux-3.19.8-ckt5-rancher-x86.tar.gz
|
||||
DFS_IMAGE=rancher/docker:1.8.1
|
@@ -1,3 +0,0 @@
|
||||
|
||||
FORCE_PULL := 0
|
||||
include scripts/version
|
@@ -9,4 +9,4 @@ fi
|
||||
|
||||
docker build -t ros-build-base -f Dockerfile.build-base .
|
||||
docker build -t ros-build -f Dockerfile.build .
|
||||
./scripts/docker-run.sh make -f Makefile.docker build-all integration-tests
|
||||
./scripts/docker-run.sh --name ros-ci make -f Makefile.docker build-all integration-tests
|
||||
|
@@ -8,9 +8,32 @@ if [ -n "$BIND_DIR" ]; then
|
||||
fi
|
||||
DOCKER_ARGS="-t -v $BIND_DIR:/go/src/github.com/rancherio/os"
|
||||
fi
|
||||
if [ -c /dev/kvm ] || [ "${PRIVILEGED}" == "1" ]; then
|
||||
DOCKER_ARGS="${DOCKER_ARGS} --privileged"
|
||||
if [ -c /dev/kvm ] || [ "${KVM}" == "1" ]; then
|
||||
DOCKER_ARGS="${DOCKER_ARGS} --device=/dev/kvm:/dev/kvm"
|
||||
fi
|
||||
|
||||
docker rm -fv ros-build >/dev/null 2>&1 || true
|
||||
exec docker run -i -v /var/run/docker.sock:/var/run/docker.sock $DOCKER_ARGS --name=ros-build ros-build "$@"
|
||||
NAME=ros-build
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case $1 in
|
||||
--name)
|
||||
shift 1
|
||||
NAME="$1"
|
||||
;;
|
||||
--rm)
|
||||
NAME=$(mktemp ${NAME}-XXXXXX)
|
||||
rm $NAME
|
||||
DOCKER_ARGS="${DOCKER_ARGS} --rm"
|
||||
;;
|
||||
-t)
|
||||
DOCKER_ARGS="${DOCKER_ARGS} -t"
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
shift 1
|
||||
done
|
||||
|
||||
DOCKER_ARGS="${DOCKER_ARGS} --name=${NAME}"
|
||||
docker rm -fv ${NAME} >/dev/null 2>&1 || true
|
||||
exec docker run -i -v /var/run/docker.sock:/var/run/docker.sock $DOCKER_ARGS ros-build "$@"
|
||||
|
@@ -1,6 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
apt-get update
|
||||
apt-get install -y grub2 parted
|
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
set -e -x
|
||||
|
||||
. $(dirname $0)/version
|
||||
. $(dirname $0)/build.conf
|
||||
VERSION=${VERSION:?"VERSION not set"}
|
||||
|
||||
while getopts "i:f:c:d:t:r:o:p:" OPTION
|
||||
|
@@ -1 +0,0 @@
|
||||
VERSION=v0.4.0-dev
|
6
tests/integration/assets/test_02/build.conf
Normal file
6
tests/integration/assets/test_02/build.conf
Normal file
@@ -0,0 +1,6 @@
|
||||
IMAGE_NAME=rancher/os
|
||||
VERSION=v0.4.0-test
|
||||
|
||||
DOCKER_BINARY_URL=https://github.com/rancher/docker/releases/download/v1.8.2-rc1-ros/docker-1.8.2-rc1
|
||||
COMPILED_KERNEL_URL=https://github.com/imikushin/os-kernel/releases/download/4.2/linux-4.2.0-rancher-x86.tar.gz
|
||||
DFS_IMAGE=rancher/docker:1.8.1
|
10
tests/integration/assets/test_02/test-custom-kernel.sh
Executable file
10
tests/integration/assets/test_02/test-custom-kernel.sh
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
set -ex
|
||||
|
||||
cd $(dirname $0)/../../../..
|
||||
|
||||
cp ./tests/integration/assets/test_02/build.conf ./
|
||||
|
||||
make -f Makefile.docker minimal
|
||||
|
||||
exec ./scripts/run
|
@@ -1,3 +1,5 @@
|
||||
from __future__ import print_function
|
||||
import itertools as it
|
||||
import pytest
|
||||
import subprocess
|
||||
import rancherostest.util as u
|
||||
@@ -8,25 +10,18 @@ def qemu(request):
|
||||
return u.run_qemu(request)
|
||||
|
||||
|
||||
def rancheros_version():
|
||||
with open('./scripts/version') as f:
|
||||
for ln in f:
|
||||
(k, _, v) = ln.partition('=')
|
||||
if k == 'VERSION' and v.strip() != '':
|
||||
return v.strip()
|
||||
raise RuntimeError("Could not parse RancherOS version")
|
||||
|
||||
|
||||
@pytest.mark.timeout(30)
|
||||
def test_system_boot(qemu):
|
||||
version = rancheros_version()
|
||||
version = u.rancheros_version('./build.conf')
|
||||
print('parsed version: ' + version)
|
||||
for ln in u.iter_lines(qemu.stdout):
|
||||
ros_booted_substr = str.find(ln, 'RancherOS {v} started'.format(v=version))
|
||||
print(str.strip(ln))
|
||||
if ros_booted_substr > -1:
|
||||
assert True
|
||||
return
|
||||
|
||||
def has_ros_started_substr(s):
|
||||
return str.find(s, 'RancherOS {v} started'.format(v=version)) > -1
|
||||
|
||||
for _ in it.ifilter(has_ros_started_substr,
|
||||
it.imap(u.with_effect(print), u.iter_lines(qemu.stdout))):
|
||||
assert True
|
||||
return
|
||||
assert False
|
||||
|
||||
|
||||
@@ -40,7 +35,7 @@ def test_run_system_container(qemu):
|
||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
|
||||
|
||||
for ln in u.iter_lines(ssh.stdout):
|
||||
print(str.strip(ln))
|
||||
print(ln)
|
||||
ssh.wait()
|
||||
|
||||
assert ssh.returncode == 0
|
||||
|
35
tests/integration/rancherostest/test_02_custom_kernel.py
Normal file
35
tests/integration/rancherostest/test_02_custom_kernel.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from __future__ import print_function
|
||||
import itertools as it
|
||||
import pytest
|
||||
import subprocess
|
||||
import rancherostest.util as u
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def build_and_run(request):
|
||||
print('\nBuilding and running RancherOS with custom kernel')
|
||||
p = subprocess.Popen(['./scripts/docker-run.sh', '--rm',
|
||||
'./tests/integration/assets/test_02/test-custom-kernel.sh'],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
|
||||
|
||||
def fin():
|
||||
print('\nTerminating docker-run test-custom-kernel')
|
||||
p.terminate()
|
||||
|
||||
request.addfinalizer(fin)
|
||||
return p
|
||||
|
||||
|
||||
@pytest.mark.timeout(30)
|
||||
def test_system_boot(build_and_run):
|
||||
version = u.rancheros_version('./tests/integration/assets/test_02/build.conf')
|
||||
print('parsed version: ' + version)
|
||||
|
||||
def has_ros_started_substr(s):
|
||||
return str.find(s, 'RancherOS {v} started'.format(v=version)) > -1
|
||||
|
||||
for _ in it.ifilter(has_ros_started_substr,
|
||||
it.imap(u.with_effect(print), u.iter_lines(build_and_run.stdout))):
|
||||
assert True
|
||||
return
|
||||
assert False
|
@@ -1,10 +1,46 @@
|
||||
import itertools as it
|
||||
import pytest
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
|
||||
def iter_lines(s):
|
||||
return iter(s.readline, '')
|
||||
return it.imap(str.rstrip, iter(s.readline, ''))
|
||||
|
||||
|
||||
def strip_comment(prefix):
|
||||
return lambda s: s.partition(prefix)[0].strip()
|
||||
|
||||
|
||||
def non_empty(s):
|
||||
return s != ''
|
||||
|
||||
|
||||
def parse_value(var):
|
||||
def get_value(s):
|
||||
(k, _, v) = s.partition('=')
|
||||
(k, v) = (k.strip(), v.strip())
|
||||
if k == var:
|
||||
return v
|
||||
return ''
|
||||
return get_value
|
||||
|
||||
|
||||
def with_effect(p):
|
||||
def effect(s):
|
||||
p(s)
|
||||
return s
|
||||
return effect
|
||||
|
||||
|
||||
def rancheros_version(build_conf):
|
||||
with open(build_conf) as f:
|
||||
for v in it.ifilter(non_empty,
|
||||
it.imap(parse_value('VERSION'),
|
||||
it.ifilter(non_empty,
|
||||
it.imap(strip_comment('#'), iter_lines(f))))):
|
||||
return v
|
||||
raise RuntimeError("Could not parse RancherOS version")
|
||||
|
||||
|
||||
def run_qemu(request, run_args=[]):
|
||||
|
Reference in New Issue
Block a user