summaryrefslogtreecommitdiff
path: root/start-container-schroot.sh
diff options
context:
space:
mode:
authorChristophe Lyon <christophe.lyon@linaro.org>2017-01-27 13:24:19 +0000
committerChristophe Lyon <christophe.lyon@linaro.org>2017-01-27 13:34:49 +0000
commitb1e0f5737e72b654076410469af949931fd2ef7a (patch)
treebd7b785e8217d75fedb6fd5d577b95206e50f7f5 /start-container-schroot.sh
parent927e3cfb59fdb7262ea30b1b2d6b6b66bda18db5 (diff)
Add new scripts to start a container.
The 3 main scripts are: start-container-none.sh start-container-schroot.sh start-container-docker.sh and check-server.exp is a helper for start-container-docker.sh. The 3 main scripts have the same calling convention: start-container-${container_type}.sh arch flavour. Currently, arch can be i386, amd, armhf or arm64, and distro can be trusty or xenial. If successful, the script outputs a few lines of shell that should be executed in the calling script, which: - install a trap handler to remove the container upon exit - define the ${CONTAINER} variable, to be used as a prefix for commands you want to execute in the container - define ${session_host} and ${session_port} that can be used by the parent script to interact with container (for instance to help another (test)-container connect to the newly created container. The docker variant uses an helper expect script to make sure the ssh server running in the docker instance is ready. Change-Id: I2e2baf3ab606dd636fae87d0b0583a3102fb8f95
Diffstat (limited to 'start-container-schroot.sh')
-rwxr-xr-xstart-container-schroot.sh39
1 files changed, 39 insertions, 0 deletions
diff --git a/start-container-schroot.sh b/start-container-schroot.sh
new file mode 100755
index 00000000..c95cae29
--- /dev/null
+++ b/start-container-schroot.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+# Start a local schroot instance with the requested arch and distro
+
+# This script is meant to be executed from Jenkins jobs inside TCWG
+# lab. It prints shell commands meant to be executed in the parent
+# shell, consisting in:
+# - a trap statement, to cleanup the container upon exit
+# - definition of ${CONTAINER}, used to prefix commands that you want
+# to run inside the container.
+# - definition of ${session_host} and ${session_port}, can be used for
+# a remote connexion to the container
+if [ $# -ne 2 ]; then
+ echo Usage: $0 arch flavour
+ echo " arch: architecture (eg: amd64, i386, arm64, armhf)"
+ echo " flavour: distribution (eg: trusty)"
+ exit 1
+fi
+
+container_arch=$1
+distro=$2
+
+session_host="$(hostname).tcwglab"
+session_port=22
+schroot_image="tcwg-build-${container_arch}-${distro}"
+session_id=$(schroot -b -c chroot:$schroot_image --preserve-environment)
+
+if [ x"$session_id" = x ]; then
+ exit 1
+fi
+
+cat <<EOF
+ulimit -u 5000
+# Sometimes /dev/pts can't get unmounted on the first try.
+# Workaround by retrying.
+trap "{ schroot -f -e -c session:$session_id || { sleep 60 ; schroot -f -e -c session:$session_id; } || true; }" EXIT
+CONTAINER="schroot -r -c session:$session_id --preserve-environment -- bash -c"
+session_host=${session_host}
+session_port=${session_port}
+EOF