diff --git a/Dockerfile b/Dockerfile index 9bf4e5fd..c73403e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/Makefile b/Makefile index 40d6a15d..97d39da4 100644 --- a/Makefile +++ b/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 diff --git a/Makefile.docker b/Makefile.docker index b0ff821a..e162f925 100644 --- a/Makefile.docker +++ b/Makefile.docker @@ -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 diff --git a/build.conf b/build.conf new file mode 100644 index 00000000..f1213d64 --- /dev/null +++ b/build.conf @@ -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 diff --git a/common.make b/common.make deleted file mode 100644 index 264bfecf..00000000 --- a/common.make +++ /dev/null @@ -1,3 +0,0 @@ - -FORCE_PULL := 0 -include scripts/version diff --git a/scripts/ci b/scripts/ci index 0a2d2382..037af254 100755 --- a/scripts/ci +++ b/scripts/ci @@ -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 diff --git a/scripts/docker-run.sh b/scripts/docker-run.sh index 4993ab9b..37479f47 100755 --- a/scripts/docker-run.sh +++ b/scripts/docker-run.sh @@ -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 "$@" diff --git a/scripts/installer/bootstrap b/scripts/installer/bootstrap deleted file mode 100755 index 426ed80f..00000000 --- a/scripts/installer/bootstrap +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -export DEBIAN_FRONTEND=noninteractive - -apt-get update -apt-get install -y grub2 parted diff --git a/scripts/installer/lay-down-os b/scripts/installer/lay-down-os index 2213380b..88e6d41c 100755 --- a/scripts/installer/lay-down-os +++ b/scripts/installer/lay-down-os @@ -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 diff --git a/scripts/version b/scripts/version deleted file mode 100644 index d502fae2..00000000 --- a/scripts/version +++ /dev/null @@ -1 +0,0 @@ -VERSION=v0.4.0-dev diff --git a/tests/integration/assets/test_02/build.conf b/tests/integration/assets/test_02/build.conf new file mode 100644 index 00000000..6b559412 --- /dev/null +++ b/tests/integration/assets/test_02/build.conf @@ -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 diff --git a/tests/integration/assets/test_02/test-custom-kernel.sh b/tests/integration/assets/test_02/test-custom-kernel.sh new file mode 100755 index 00000000..857ad992 --- /dev/null +++ b/tests/integration/assets/test_02/test-custom-kernel.sh @@ -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 diff --git a/tests/integration/rancherostest/test_00_system.py b/tests/integration/rancherostest/test_00_system.py index 32ab6dea..c4f0c5ff 100644 --- a/tests/integration/rancherostest/test_00_system.py +++ b/tests/integration/rancherostest/test_00_system.py @@ -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 diff --git a/tests/integration/rancherostest/test_02_custom_kernel.py b/tests/integration/rancherostest/test_02_custom_kernel.py new file mode 100644 index 00000000..817064f0 --- /dev/null +++ b/tests/integration/rancherostest/test_02_custom_kernel.py @@ -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 diff --git a/tests/integration/rancherostest/util.py b/tests/integration/rancherostest/util.py index f17f85ee..394bb359 100644 --- a/tests/integration/rancherostest/util.py +++ b/tests/integration/rancherostest/util.py @@ -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=[]):