summaryrefslogtreecommitdiff
path: root/start-container-docker.sh
diff options
context:
space:
mode:
authorChristophe Lyon <christophe.lyon@linaro.org>2018-06-06 13:12:29 +0000
committerChristophe Lyon <christophe.lyon@linaro.org>2018-06-07 06:58:19 +0000
commit6140c2fd1711d12ed2b55addc053c9098b4aa426 (patch)
tree4a8ea8ea93a60d8a8c8c91ded4825cefb48101d5 /start-container-docker.sh
parentc33a59d0cf040a0f43431972123bc8edab5e2d23 (diff)
start-container-docker.sh: Add --dryrun parameter.
This boolean selects whether to actually run commands in the container. If false, we keep the usual behaviour, and if true, the CONTAINER, CONTAINER_RSH and container_exec helpers are modified to only print what they would normally execute. Change-Id: Ia85d528f1f4665c92c6415c053080d4a3c3e018d
Diffstat (limited to 'start-container-docker.sh')
-rwxr-xr-xstart-container-docker.sh19
1 files changed, 15 insertions, 4 deletions
diff --git a/start-container-docker.sh b/start-container-docker.sh
index be210d36..2f94d17b 100755
--- a/start-container-docker.sh
+++ b/start-container-docker.sh
@@ -15,10 +15,11 @@ set -e
# - definition of ${session_host} and ${session_port}, can be used for
# a remote connexion to the container
usage() {
- echo "Usage: $0 [--arch container-arch] [--cp_file from[:to:owner:perms]] --distro flavour [--docker_opts opts] [--label label] [--newuser username:[uid]] [--node node] [--prefix prefix] [--session-host host] [--session-name name] [--task {build|test}] [--user user] [--weight weight]"
+ echo "Usage: $0 [--arch container-arch] [--cp_file from[:to:owner:perms]] --distro flavour [--docker_opts opts] [--dryrun true/false] [--label label] [--newuser username:[uid]] [--node node] [--prefix prefix] [--session-host host] [--session-name name] [--task {build|test}] [--user user] [--weight weight]"
echo
echo " container-arch: architecture (eg: amd64, i386, arm64, armhf)"
echo " distro: distribution (eg: trusty)"
+ echo " dryrun: boolean, just print commands if true"
echo " label: jenkins label; container is started on least-busy node; also sets container architecture"
echo " newuser: new user to create inside container, <username>[:<uid>] specification."
echo " node: jenkins node; container is started on host mapped to the node"
@@ -42,6 +43,7 @@ container_arch="default"
cp_files=()
distro="trusty-tcwg-tested"
docker_opts=
+dryrun=false
label=
node=
newuser=
@@ -75,6 +77,12 @@ do
[ x"${docker_opts}" = x ] && usage
shift 2
;;
+ --dryrun)
+ dryrun=$2
+ [ x${dryrun} = x ] && usage
+ [ $dryrun != false ] && [ $dryrun != true ] && usage
+ shift 2
+ ;;
--label)
label=$2
[ x${label} = x ] && usage
@@ -127,6 +135,9 @@ do
esac
done
+dryruncmd=""
+[ $dryrun ] && dryruncmd="echo"
+
if [ x"$node" = x"" -a x"$label" != x"" ]; then
node=$(print_node_with_least_containers "$label")
if [ x"$node" = x"" ]; then
@@ -279,7 +290,7 @@ exec 1>&3 2>&4
cat <<EOF
# v1 interface
-CONTAINER="ssh -p ${session_port} ${user}${session_host}"
+CONTAINER="${dryruncmd} ssh -p ${session_port} ${user}${session_host}"
CONTAINER_CLEANUP="${CONTAINER_CLEANUP}"
session_host=${session_host}
session_port=${session_port}
@@ -289,7 +300,7 @@ session_port=${session_port}
# Source jenkins-helpers.sh for remote_exec
. "$(dirname "$(readlink -f "$0")")/jenkins-helpers.sh"
-${prefix}CONTAINER_RSH="ssh -p ${session_port} ${user}${session_host}"
+${prefix}CONTAINER_RSH="${dryruncmd} ssh -p ${session_port} ${user}${session_host}"
${prefix}container_cleanup ()
{
${CONTAINER_CLEANUP}
@@ -300,7 +311,7 @@ ${prefix}container_stop ()
}
${prefix}container_exec ()
{
- remote_exec "${user}${session_host}:${session_port}:\$(pwd)" "\$@"
+ $dryruncmd remote_exec "${user}${session_host}:${session_port}:\$(pwd)" "\$@"
}
${prefix}container_host=${session_host}