summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2019-02-28 07:38:17 +0000
committerMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2019-03-06 12:41:20 +0000
commitacd4dfe5cbee22fee97c40afb0a3a2df6722e96a (patch)
treefad7f601260b55b17be68869c0bdf44101af9e08
parent849ca36d4278b0799f7a3baf5285a741aff95463 (diff)
start-container-docker.sh, docker-run.sh: Rework --ssh_info support
Instead of a hack in docker-run.sh add ability to pass environment variables in remote_exec(). Use this to pass ssh_host/ssh_port via container_exec() function. Change-Id: Ic8f7bb3c3ae94b501eb475e90b892c0d769dd0dd
-rwxr-xr-xdocker-run.sh9
-rw-r--r--jenkins-helpers.sh16
-rwxr-xr-xstart-container-docker.sh13
3 files changed, 22 insertions, 16 deletions
diff --git a/docker-run.sh b/docker-run.sh
index 2af4c8e3..de7f340a 100755
--- a/docker-run.sh
+++ b/docker-run.sh
@@ -7,7 +7,6 @@ convert_args_to_variables "$@"
shift "$SHIFT_CONVERTED_ARGS"
qemu="${qemu-}"
-ssh_info="${ssh_info-false}"
trap "container_cleanup" EXIT
@@ -17,10 +16,4 @@ case "$qemu" in
esac
. ./container.sh
-if $ssh_info; then
- ssh_opts="--ssh_host $session_host --ssh_port $session_port"
-else
- ssh_opts=""
-fi
-
-container_exec "$@" $ssh_opts
+container_exec "$@"
diff --git a/jenkins-helpers.sh b/jenkins-helpers.sh
index 5573f391..8f406820 100644
--- a/jenkins-helpers.sh
+++ b/jenkins-helpers.sh
@@ -224,18 +224,22 @@ print_tester_label_for_target ()
}
# Run command on remote machine in given directory via ssh on a given port
-# "$1" -- <host>[:<port>[:<dir>[:<ssh_opts>]]]
+# "$1" -- <host>[:<port>[:<dir>[:<ssh_opts>[:<env>]]]]
# "$2, $3, etc" -- command and its arguments
# E.g., remote_exec dev-01.tcwglab::/tmp find -name "my file.bak"
+# NOTE: The environment variables are not escaped, so pass only simple things.
+# This is because we want ability to pass multiple variables "a=b c=d",
+# and escaping will make that into a single a="b c=d" variable.
remote_exec ()
{
(
set -euf -o pipefail
- local host="$(echo $1 | cut -d: -f 1)"
- local port="$(echo $1 | cut -s -d: -f 2)"
- local dir="$(echo $1 | cut -s -d: -f 3)"
- local opts="$(echo $1 | cut -s -d: -f 4)"
+ local host="$(echo "$1" | cut -d: -f 1)"
+ local port="$(echo "$1" | cut -s -d: -f 2)"
+ local dir="$(echo "$1" | cut -s -d: -f 3)"
+ local opts="$(echo "$1" | cut -s -d: -f 4)"
+ local env_vars="$(echo "$1" | cut -s -d: -f 5)"
shift
local -a cmd
cmd=()
@@ -244,7 +248,7 @@ remote_exec ()
# Be careful to prepend statements before ${cmd[@]} only if necessary.
# E.g., when triggering jobs via jenkins-cli, the command is not a binary,
# so we can't "exec" it.
- ssh $opts ${port:+-p$port} $host "${dir:+cd "$(printf '%q' "$dir")" && exec }${cmd[@]}"
+ ssh $opts ${port:+-p$port} $host "${env_vars:+export $env_vars && }${dir:+cd "$(printf '%q' "$dir")" && exec }${cmd[@]}"
)
}
diff --git a/start-container-docker.sh b/start-container-docker.sh
index ac6d1536..dfcff4ee 100755
--- a/start-container-docker.sh
+++ b/start-container-docker.sh
@@ -15,7 +15,7 @@ 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] --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] [--verbose true/false]"
+ echo "Usage: $0 [--arch container-arch] --distro flavour [--docker_opts opts] [--dryrun true/false] [--label label] [--newuser username:[uid]] [--node node] [--prefix prefix] [--session-host host] [--session-name name] [--ssh_info true/false] [--task {build|test}] [--user user] [--weight weight] [--verbose true/false]"
echo
echo " container-arch: architecture (eg: amd64, i386, arm64, armhf)"
echo " distro: distribution (eg: trusty)"
@@ -27,6 +27,7 @@ usage() {
echo " session-host: hostname where the container will run, defaults to localhost"
echo " useful if the name resolution does not work correctly"
echo " session-name: session, in case the default '$BUILD_NUMBER-$JOB_NAME' is not suitable"
+ echo " ssh_info: set $ssh_host and $ssh_port env variables in the container"
echo " task: type of container (build or test, default=build)"
echo " user: remote user to use in the container."
echo " weight: container weight, reserves resources. Default=1"
@@ -50,6 +51,7 @@ newuser=
prefix=
session_host=
session_name=
+ssh_info=false
task="build"
weight=1
user=
@@ -110,6 +112,8 @@ do
shift 2
;;
--ssh_info)
+ ssh_info=$2
+ [ x$ssh_info = x ] && usage
shift 2
;;
--task)
@@ -282,6 +286,11 @@ fi
# Do not remove the container upon exit: it is now ready
trap EXIT
+ssh_info_opt=""
+if $ssh_info; then
+ ssh_info_opt="ssh_host=${user}$session_host ssh_port=$session_port"
+fi
+
# Restore stdout/stderr
exec 1>&3 2>&4
@@ -312,7 +321,7 @@ ${prefix}container_stop ()
}
${prefix}container_exec ()
{
- $dryruncmd remote_exec "${user}${session_host}:${session_port}:\$(pwd)" "\$@"
+ $dryruncmd remote_exec "${user}${session_host}:${session_port}:\$(pwd)::$ssh_info_opt" "\$@"
}
${prefix}container_host=${session_host}