-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdocker_utils
executable file
·87 lines (73 loc) · 1.66 KB
/
docker_utils
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
#!/bin/bash
# NOTE: uses standard container names/ports et all
# TODO: use env vars or something
function run_docker {
CONTAINER=$1
shift
${DOCKER_COMMAND}exec $TERM_FLAG $CONTAINER $DOCKER_DELIM $*
}
function fix_exit_code {
CODE=$?
if [ $CODE -eq 5 ]; then
exit 0
else
exit $CODE
fi
}
# Checking if native docker is available
# TODO: what if we have a docker AND a VM setup? exotic case, do something about it
if which docker > /dev/null 2>&1 ; then
DOCKER_COMMAND="docker "
DOCKER_DELIM=""
# Checking if we are run from interactive terminal
if [ -t 0 ] ; then
TERM_FLAG="-it"
else
TERM_FLAG="-i"
fi
else
DOCKER_COMMAND="vagrant docker-"
DOCKER_DELIM="--"
# Pretend there is a tty
TERM_FLAG="-it"
if [ ! -t 0 ] ; then
# TODO: #11
echo "Piping is not supported, see #11"
exit 1
fi
fi
case `basename $0` in
sql_access)
if [ -z $1 ]; then
SQL_USER=promis
else
SQL_USER=$1
fi
if [ -z $2 ]; then
SQL_DB=promisdb
else
SQL_DB=$2
fi
run_docker db.promis psql -U $SQL_USER $SQL_DB
;;
backend_shell)
run_docker api.promis python promis/manage.py shell
;;
backend_command)
run_docker api.promis python promis/manage.py $*
;;
backend_bash)
run_docker api.promis bash
;;
backend_test)
run_docker api.promis py.test -v promis/
fix_exit_code
;;
integration_test)
if ! vagrant status test.promis 2>&1 | grep 'running (docker)' >/dev/null; then
vagrant up test.promis
fi
run_docker test.promis py.test -v
fix_exit_code
;;
esac