kas-docker: enable passing SSH configs

This commit enables passing the Docker container a directory containing
SSH configuration and optionally SSH identities and list of known SSH
hosts. Basically what you might expect to find in the ~/.ssh directory
of the container.

Signed-off-by: Silvano Cirujano Cuesta <silvano.cirujano-cuesta@siemens.com>
Suggested-by: Henning Schild <henning.schild@siemens.com>
This commit is contained in:
Cirujano Cuesta, Silvano 2018-12-13 09:33:30 +00:00 committed by Daniel Wagner
parent 46c7d6e38c
commit 49a6bbfc82

View File

@ -40,6 +40,8 @@ usage()
printf "%b" "--docker-args\tAdditional arguments to pass to docker for" \
"running the build.\n"
printf "%b" "-v\t\tPrint operations.\n"
printf "%b" "--ssh-dir\tDirectory containing SSH configurations, " \
"avoid $HOME/.ssh unless you fully trust the container.\n"
exit 1
}
@ -87,6 +89,11 @@ while [ $# -gt 0 ]; do
USER_ARGS=$2
shift 2
;;
--ssh-dir)
[ $# -gt 2 ] || usage
SSH_DIR=$2
shift 2
;;
-v)
VERBOSE=1
shift 1
@ -139,6 +146,11 @@ DOCKER_ARGS="-v ${REPO_DIR}:/repo:ro \
-v ${KAS_WORK_DIR}:/work:rw --workdir=/work \
-e USER_ID=$(id -u) -e GROUP_ID=$(id -g) --rm"
if [ -n "${SSH_DIR}" ] ; then
[ -d "${SSH_DIR}" ] || echo "Passed SSH_VALUE '${SSH_DIR' is not a directory" ; exit 1
DOCKER_ARGS="${DOCKER_ARGS} -v $(readlink -f ${SSH_DIR}):/etc/skel/.ssh:ro"
fi
if [ -t 1 ]; then
DOCKER_ARGS="${DOCKER_ARGS} -t -i"
fi