REC-11 Creating and testing Namespaces
[ta/cloudtaf.git] / rfcli-docker
1 #!/bin/bash
2
3 # Copyright 2019 Nokia
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 set -e
18 set -u
19 set -x
20
21 # TOX_ENV is tox environment which is to be executed.
22 if [ -z ${TOX_ENV+x} ]; then
23     TOX_ENV=rfcli
24 fi
25 SCRIPT_DIR="$(dirname $(readlink -f ${BASH_SOURCE[0]}))"
26
27 DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG:-rec-cloudtaf-runner}
28
29 $SCRIPT_DIR/rfcli-docker-build $DOCKER_IMAGE_TAG
30
31 i=0
32 ORIGINAL_ARGS=("$@")
33 NO_TARGET_CMD=""
34 while [ $i -lt ${#ORIGINAL_ARGS[@]} ]; do
35     arg=${ORIGINAL_ARGS[$i]}
36     if [ $arg == "-t" ]; then
37         target_index=$(expr $i + 1)
38         target_path=${ORIGINAL_ARGS[$target_index]}
39         i=$(expr $i + 2)
40     else
41         NO_TARGET_CMD="${NO_TARGET_CMD} ${arg}"
42         i=$(expr $i + 1)
43     fi
44 done
45
46 cp $target_path targets
47 new_target_path=targets/$(basename $target_path)
48
49 docker run --rm -t \
50     --net="host" \
51     --env DISPLAY \
52     --env TOX_ENV \
53     -v $(pwd):/tmp/rec-cloudtaf \
54     -w /tmp/rec-cloudtaf \
55     $DOCKER_IMAGE_TAG ./rfcli-tox-umask -t ${new_target_path} $NO_TARGET_CMD