/
cmd.sh
126 lines (92 loc) · 2.77 KB
/
cmd.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
# this script contains a function for command line operation of controlling envoy. it should not be called directly.
# set -x
function cmd {
SCRIPT=$0 # TODO: set from calling script somehow so help text is easier to read
USAGE="Use: $SCRIPT build|stack|test [OPTIONS]"
if [ "$#" -eq 0 ]; then
echo $USAGE
echo "Execute one of the above commands to see more options"
exit 1
fi
OPERATION=$1
shift
if [[ "$OPERATION" == "stack" || "$OPERATION" == "compose" ]]; then
# This script is basically a wrapper around docker-compose with some additional sugar for this project to help determine which compose file to run
USAGE="Use: $SCRIPT stack STACKNAME"
if [ "$#" -eq 0 ]; then
echo $USAGE
echo Choose a stack:
list_stacks
else
STACK=$1
shift
args="$@"
if (( $# == 0 )); then
args="up"
fi
CMD="docker-compose -f $CONFIGURATIONS/$STACK.yml $args"
echo $CMD
$CMD
fi
elif [[ "$OPERATION" == "build" ]]; then
COMMAND=$1
NAME=$2
USAGE="Use: $SCRIPT build image|stack|all name"
if [ "$#" -eq 0 ]; then
echo $USAGE
elif [[ "$COMMAND" == "image" ]]; then
if [ -z $NAME ]; then
echo Choose an image to build:
list_projects
else
build_image $NAME
fi
elif [ "$COMMAND" == "stack" ]; then
if [ -z $NAME ]; then
echo Choose a stack to build:
list_stacks
else
IMAGES=$(get_images_from_config $CONFIGURATIONS/$NAME.yml)
echo Building images: $IMAGES
build_images $IMAGES
fi
elif [ "$COMMAND" == "all" ]; then
projects=$(list_projects)
for project in $projects
do
build_image $project
done;
else
echo $USAGE
fi
elif [[ "$OPERATION" == "test" ]]; then
if [ "$#" -eq 0 ]; then
echo "Use: $SCRIPT test TESTNAME"
echo
echo TESTS:
echo "$(find $TESTS -name "*.py" -exec basename -s .py -a {} +)"
exit 1
fi
TEST=$1
echo Running tests/$TEST.py
cd $ENVOY
docker build . --file testrunner.dockerfile --tag testrunner:envoy || exit 2
cd -
cd $TESTS
# TODO: change 'custom' to something like 'plos' so we can have more then one of these on a system
docker build . --tag testrunner:custom || exit 3
cd -
docker run --rm --network=configurations_default \
-e "DOCKERFILES=$DOCKERFILES" \
-e "CONFIGURATIONS=/dockerfiles/configurations" \
-v $DOCKERFILES:/dockerfiles:ro \
-v /var/run/docker.sock:/var/run/docker.sock \
testrunner:custom \
pytest -p no:cacheprovider --capture=no /dockerfiles/tests/${TEST}.py -v
# pass up the exit code to the caller
exit $?
else
echo $USAGE
fi
}