#!/bin/bash set -e # Pretend to start a local container. Parameters are ignored but # required to have the same interface as the other scripts in this # directory. We check if arch and distro match the local machine's # values. # 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: # - definition of ${CONTAINER}, used to prefix commands that you want # to run inside the container. # - definition of ${CONTAINER_CLEANUP}, a cleanup statement remove the # container on exit for instance # - 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 [--session-host host] [--session-name name] [--task {build|test}]" echo echo " container-arch: architecture (eg: amd64, i386, arm64, armhf)" echo " distro: distribution (eg: trusty)" 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 " task: type of container (build or test, default=build)" exit 1 } # Save stdout/stderr file descriptors exec 3>&1 4>&2 # Make sure all output goes to stderr exec 1>&2 container_arch= distro= session_host= session_name= task="build" while [ $# -ge 1 ] do case $1 in --arch) container_arch=$2 [ x${container_arch} = x ] && usage shift 2 ;; --distro) distro=$2 [ x${distro} = x ] && usage shift 2 ;; --session-host) session_host=$2 [ x${session_host} = x ] && usage shift 2 ;; --session-name) session_name=$2 [ x${session_name} = x ] && usage shift 2 ;; --task) task=$2 [ x${task} = x ] && usage shift 2 ;; *) echo "Unsupported option: $1" usage ;; esac done [ x${container_arch} = x ] && usage [ x${distro} = x ] && usage case $(uname -m) in x86_64) my_arch=amd64 ;; i686) my_arch=i386 ;; aarch64) my_arch=arm64 ;; armv7l|armv8l) my_arch=armhf ;; *) my_arch=$(uname -m) ;; esac if [ x${container_arch} != x${my_arch} ]; then echo "Error: requested container arch (${container_arch}) does not match this machine's arch (${my_arch})" exit 1 fi my_distro=$(lsb_release -c | awk '{print $2;}') if [ x${distro} != x${my_distro} ]; then echo "Error: requested distro (${distro}) does not match this machine's distro (${my_distro})" exit 1 fi if [ x"$DOCKER_HOST" = x"" ]; then [ x"$session_host" = x ] && session_host=localhost # Append .tcwglab if not already present case ${session_host} in *.tcwglab) ;; *) session_host=${session_host}.tcwglab esac session_port=22 else session_host="$(echo $DOCKER_HOST | sed -e "s#^tcp://\(.*\):.*#\1#")" session_port="$(ssh $session_host docker port $DOCKER_CONTAINER_ID 22)" session_port="$(echo $session_port | cut -d: -f 2)" fi # Restore stdout/stderr exec 1>&3 2>&4 cat <