kas-docker: Pass build and shell options into container

This allows invocations like "kas-docker build --task clean kas.yml".

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Jan Kiszka 2018-12-14 17:43:05 +01:00 committed by Daniel Wagner
parent 5a68998ba7
commit 280a695ab3

View File

@ -29,7 +29,7 @@ set -e
usage()
{
printf "%b" "Usage: $0 [OPTIONS] { build | shell } KASFILE\n"
printf "%b" "Usage: $0 [OPTIONS] { build | shell } [KASOPTIONS] KASFILE\n"
printf "%b" " $0 [OPTIONS] clean\n"
printf "%b" "\nPositional arguments:\n"
printf "%b" "build\t\tCheck out repositories and build target.\n"
@ -59,6 +59,7 @@ else
KAS_WORK_DIR=$(pwd)
fi
# parse kas-docker options
while [ $# -gt 0 ]; do
case "$1" in
--isar)
@ -115,13 +116,8 @@ while [ $# -gt 0 ]; do
exit 0
;;
build|shell)
[ $# -eq 2 ] || usage
CMD=$1
FILE=$(echo $2 | cut -d ':' -f 1)
if ! FIRST_KAS_FILE=$(readlink -e $FILE); then
echo "Error: configuration file '$FILE' not found"
exit 1
fi
shift 1
break
;;
*)
@ -132,13 +128,42 @@ done
[ -n "${CMD}" ] || usage
# parse kas sub-command (build or shell) options
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
trace docker run ${DOCKER_IMAGE} ${CMD} --help
exit 0
;;
--skip|--target|--task|-c|--command)
KAS_OPTIONS="${KAS_OPTIONS} $1 '$2'"
shift 2
;;
-*)
KAS_OPTIONS="${KAS_OPTIONS} $1"
shift 1
;;
*)
KAS_FILE=$1
FILE=$(echo ${KAS_FILE} | cut -d ':' -f 1)
if ! FIRST_KAS_FILE=$(readlink -e $FILE); then
echo "Error: configuration file '$FILE' not found"
exit 1
fi
shift 1
;;
esac
done
[ -n "${FIRST_KAS_FILE}" ] || usage
KAS_FILE_DIR=$(dirname ${FIRST_KAS_FILE})
REPO_DIR=$(git -C ${KAS_FILE_DIR} rev-parse --show-toplevel 2>/dev/null) \
|| REPO_DIR=$(hg -cwd ${KAS_FILE_DIR} root 2>/dev/null) \
|| REPO_DIR=${KAS_FILE_DIR}
KAS_FILE=/repo/$(echo $2 | sed 's|'${REPO_DIR}'/||g;s|:|:/repo/|g')
KAS_FILE=/repo/$(echo ${KAS_FILE} | sed 's|'${REPO_DIR}'/||g;s|:|:/repo/|g')
trace mkdir -p ${KAS_WORK_DIR}
@ -188,4 +213,4 @@ for var in SHELL TERM KAS_DISTRO KAS_MACHINE KAS_TARGET KAS_TASK \
done
trace docker run "$@" ${ISAR_ARGS} ${USER_ARGS} \
${DOCKER_IMAGE} ${CMD} ${KAS_FILE}
${DOCKER_IMAGE} ${CMD} ${KAS_OPTIONS} ${KAS_FILE}