diff options
author | Christophe Lyon <christophe.lyon@linaro.org> | 2019-03-20 22:35:50 +0000 |
---|---|---|
committer | Christophe Lyon <christophe.lyon@linaro.org> | 2019-03-21 11:28:05 +0000 |
commit | 759bf5b1e72cf947786a158b1da2e363f61ceef0 (patch) | |
tree | da7cec516075696ed6444986b8ce5c69edc4032d /start-container-docker.sh | |
parent | ff044c8ba5afd5a734316bea4afe872dc44ebde3 (diff) |
start-container-docker.sh, jenkins-helpers.sh: Add --ssh_info option
The new boolean --ssh_info option of start-container-docker.sh enables
passing ssh_host and ssh_port variables to the command executed in the
container via the environment.
The remote_exec helper is enhanced to support passing environment
variables.
Change-Id: Ic068220d52541ada2ea6b4a26f40730788babf9d
Diffstat (limited to 'start-container-docker.sh')
-rwxr-xr-x | start-container-docker.sh | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/start-container-docker.sh b/start-container-docker.sh index a0f09aa7..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= @@ -109,6 +111,11 @@ do [ x${session_name} = x ] && usage shift 2 ;; + --ssh_info) + ssh_info=$2 + [ x$ssh_info = x ] && usage + shift 2 + ;; --task) task=$2 [ x${task} = x ] && usage @@ -196,11 +203,6 @@ fi image=linaro/ci-${container_arch}-tcwg-${task}-ubuntu:${distro} -case "$session_host" in - "localhost"*) docker_host="" ;; - *) docker_host="$session_host" ;; -esac - DOCKER="ssh $session_host docker" $DOCKER pull $image @@ -284,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 @@ -314,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} |