run.sh prints instructions/settings for running a test suite.
[arvados.git] / docker / run.sh
1 #!/bin/bash
2
3 function usage {
4   echo >&2 "usage: $0 [--doc] [--sso] [--api] [--workbench] [--keep]"
5   echo >&2 "If no switches are given, the default is to start all servers."
6 }
7
8 if [[ "$ENABLE_SSH" != "" ]]; then
9   EXTRA=" -e ENABLE_SSH=$ENABLE_SSH"
10 else
11   EXTRA=''
12 fi
13
14 start_doc=false
15 start_sso=false
16 start_api=false
17 start_workbench=false
18 start_keep=false
19
20 while [ $# -ge 1 ]
21 do
22     case $1 in
23         --doc)
24             start_doc=true
25             ;;
26         --sso)
27             start_sso=true
28             ;;
29         --api)
30             start_api=true
31             ;;
32         --workbench)
33             start_workbench=true
34             ;;
35         --keep)
36             start_keep=true
37             ;;
38         *)
39             usage
40             exit 1
41             ;;
42     esac
43     shift
44 done
45
46 # If no options were selected, then start all servers.
47 if $start_doc || $start_sso || $start_api || $start_workbench || $start_keep
48 then
49     :
50 else
51     start_doc=true
52     start_sso=true
53     start_api=true
54     start_workbench=true
55     start_keep=true
56 fi
57
58 function ip_address {
59   local container=$1
60   echo `docker inspect $container  |grep IPAddress |cut -f4 -d\"`
61 }
62
63 function start_container {
64   local port="-p $1"
65   if [[ "$2" != '' ]]; then
66     local name="-name $2"
67   fi
68   if [[ "$3" != '' ]]; then
69     local volume="-v $3"
70   fi
71   if [[ "$4" != '' ]]; then
72     local link="-link $4"
73   fi
74   local image=$5
75
76   `docker ps |grep -P "$2[^/]" -q`
77   if [[ "$?" == "0" ]]; then
78     echo "You have a running container with name $2 -- skipping."
79     return
80   fi
81
82   echo "Starting container:"
83   echo "  docker run -d -i -t$EXTRA $port $name $volume $link $image"
84   container=`docker run -d -i -t$EXTRA $port $name $volume $link $image`
85   if [[ "$?" != "0" ]]; then
86     echo "Unable to start container"
87     exit 1
88   fi
89   if [[ $EXTRA ]]; then
90     ip=$(ip_address $container )
91     echo
92     echo "You can ssh into the container with:"
93     echo
94     echo "    ssh root@$ip"
95     echo
96   fi
97 }
98
99 declare -a keep_volumes
100
101 # Initialize the global `keep_volumes' array. If any keep volumes
102 # already appear to exist (mounted volumes with a top-level "keep"
103 # directory), use them; create temporary volumes if necessary.
104 #
105 function make_keep_volumes () {
106   # Mount a keep volume if we don't already have one
107   for mountpoint in $(cut -d ' ' -f 2 /proc/mounts); do
108     if [[ -d "$mountpoint/keep" && "$mountpoint" != "/" ]]; then
109       keep_volumes+=($mountpoint)
110     fi
111   done
112
113   # Create any keep volumes that do not yet exist.
114   while [ ${#keep_volumes[*]} -lt 2 ]
115   do
116     new_keep=$(mktemp -d)
117     echo >&2 "mounting 512M tmpfs keep volume in $new_keep"
118     sudo mount -t tmpfs -o size=512M tmpfs $new_keep
119     mkdir $new_keep/keep
120     keep_volumes+=($new_keep)
121   done
122 }
123
124 $start_doc && start_container "9898:80" "doc_server" '' '' "arvados/doc"
125 $start_sso && start_container "9901:443" "sso_server" '' '' "arvados/sso"
126 $start_api && start_container "9900:443" "api_server" '' "sso_server:sso" "arvados/api"
127 $start_workbench && start_container "9899:80" "workbench_server" '' "api_server:api" "arvados/workbench"
128
129 declare -a keep_volumes
130 make_keep_volumes
131 $start_keep && start_container "25107:25107" "keep_server_0" "${keep_volumes[0]}:/dev/keep-0" "api_server:api" "arvados/warehouse"
132 $start_keep && start_container "25108:25107" "keep_server_1" "${keep_volumes[1]}:/dev/keep-0" "api_server:api" "arvados/warehouse"
133
134 ARVADOS_API_HOST=$(ip_address "api_server")
135 ARVADOS_API_HOST_INSECURE=yes
136 ARVADOS_API_TOKEN=$(grep '^\w' api/generated/secret_token.rb | cut -d "'" -f 2)
137
138 echo "To run a test suite:"
139
140 echo "export ARVADOS_API_HOST=$ARVADOS_API_HOST"
141 echo "export ARVADOS_API_HOST_INSECURE=$ARVADOS_API_HOST_INSECURE"
142 echo "export ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN"
143 echo "python -m unittest discover ../sdk/python"