mirror of
https://github.com/rancher/os.git
synced 2025-09-16 15:09:27 +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
|
FROM debian:jessie
|
||||||
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
RUN apt-get update && apt-get install -y grub2 parted
|
||||||
|
|
||||||
COPY ./scripts/installer /scripts
|
COPY ./scripts/installer /scripts
|
||||||
COPY ./scripts/version /scripts/
|
COPY ./build.conf /scripts/
|
||||||
RUN /scripts/bootstrap
|
|
||||||
|
|
||||||
COPY ./dist/artifacts/vmlinuz /dist/vmlinuz
|
COPY ./dist/artifacts/vmlinuz /dist/vmlinuz
|
||||||
COPY ./dist/artifacts/initrd /dist/initrd
|
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
|
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/
|
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:
|
version:
|
||||||
@echo $(VERSION)
|
@echo $(VERSION)
|
||||||
|
|
||||||
@@ -38,4 +43,4 @@ clean:
|
|||||||
rm -rf bin build dist gopath .dockerfile
|
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:
|
bin/rancheros:
|
||||||
mkdir -p $(dir $@)
|
mkdir -p $(dir $@)
|
||||||
@@ -26,7 +24,7 @@ $(DIST)/artifacts/vmlinuz: $(BUILD)/kernel/
|
|||||||
|
|
||||||
|
|
||||||
$(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
|
$(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
|
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
|
./scripts/mk-rancheros-iso.sh
|
||||||
|
|
||||||
|
|
||||||
@@ -49,18 +47,16 @@ $(DIST)/artifacts/iso-checksums.txt: $(DIST)/artifacts/rancheros.iso
|
|||||||
version:
|
version:
|
||||||
@echo $(VERSION)
|
@echo $(VERSION)
|
||||||
|
|
||||||
installer: $(DIST)/artifacts/initrd $(DIST)/artifacts/vmlinuz
|
installer: minimal
|
||||||
docker build -t rancher/os:$(VERSION) .
|
docker build -t $(IMAGE_NAME):$(VERSION) .
|
||||||
|
|
||||||
build-all: \
|
build-all: minimal installer iso
|
||||||
installer \
|
|
||||||
bin/rancheros \
|
minimal: $(DIST)/artifacts/initrd $(DIST)/artifacts/vmlinuz
|
||||||
$(DIST)/artifacts/initrd \
|
|
||||||
$(DIST)/artifacts/vmlinuz \
|
iso: $(DIST)/artifacts/rancheros.iso $(DIST)/artifacts/iso-checksums.txt
|
||||||
$(DIST)/artifacts/rancheros.iso \
|
|
||||||
$(DIST)/artifacts/iso-checksums.txt
|
|
||||||
|
|
||||||
integration-tests:
|
integration-tests:
|
||||||
cd tests/integration && tox
|
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-base -f Dockerfile.build-base .
|
||||||
docker build -t ros-build -f Dockerfile.build .
|
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
|
fi
|
||||||
DOCKER_ARGS="-t -v $BIND_DIR:/go/src/github.com/rancherio/os"
|
DOCKER_ARGS="-t -v $BIND_DIR:/go/src/github.com/rancherio/os"
|
||||||
fi
|
fi
|
||||||
if [ -c /dev/kvm ] || [ "${PRIVILEGED}" == "1" ]; then
|
if [ -c /dev/kvm ] || [ "${KVM}" == "1" ]; then
|
||||||
DOCKER_ARGS="${DOCKER_ARGS} --privileged"
|
DOCKER_ARGS="${DOCKER_ARGS} --device=/dev/kvm:/dev/kvm"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
docker rm -fv ros-build >/dev/null 2>&1 || true
|
NAME=ros-build
|
||||||
exec docker run -i -v /var/run/docker.sock:/var/run/docker.sock $DOCKER_ARGS --name=ros-build 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
|
#!/bin/bash
|
||||||
set -e -x
|
set -e -x
|
||||||
|
|
||||||
. $(dirname $0)/version
|
. $(dirname $0)/build.conf
|
||||||
VERSION=${VERSION:?"VERSION not set"}
|
VERSION=${VERSION:?"VERSION not set"}
|
||||||
|
|
||||||
while getopts "i:f:c:d:t:r:o:p:" OPTION
|
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 pytest
|
||||||
import subprocess
|
import subprocess
|
||||||
import rancherostest.util as u
|
import rancherostest.util as u
|
||||||
@@ -8,25 +10,18 @@ def qemu(request):
|
|||||||
return u.run_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)
|
@pytest.mark.timeout(30)
|
||||||
def test_system_boot(qemu):
|
def test_system_boot(qemu):
|
||||||
version = rancheros_version()
|
version = u.rancheros_version('./build.conf')
|
||||||
print('parsed version: ' + version)
|
print('parsed version: ' + version)
|
||||||
for ln in u.iter_lines(qemu.stdout):
|
|
||||||
ros_booted_substr = str.find(ln, 'RancherOS {v} started'.format(v=version))
|
def has_ros_started_substr(s):
|
||||||
print(str.strip(ln))
|
return str.find(s, 'RancherOS {v} started'.format(v=version)) > -1
|
||||||
if ros_booted_substr > -1:
|
|
||||||
assert True
|
for _ in it.ifilter(has_ros_started_substr,
|
||||||
return
|
it.imap(u.with_effect(print), u.iter_lines(qemu.stdout))):
|
||||||
|
assert True
|
||||||
|
return
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
|
|
||||||
@@ -40,7 +35,7 @@ def test_run_system_container(qemu):
|
|||||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
|
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
|
||||||
|
|
||||||
for ln in u.iter_lines(ssh.stdout):
|
for ln in u.iter_lines(ssh.stdout):
|
||||||
print(str.strip(ln))
|
print(ln)
|
||||||
ssh.wait()
|
ssh.wait()
|
||||||
|
|
||||||
assert ssh.returncode == 0
|
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 pytest
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
def iter_lines(s):
|
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=[]):
|
def run_qemu(request, run_args=[]):
|
||||||
|
Reference in New Issue
Block a user