-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwvu_comp_final
219 lines (177 loc) · 5.68 KB
/
wvu_comp_final
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#! /usr/bin/env bash
# IMAGE TAG MODIFIED FROM ORIGINAL VERSION
#
# Space Robotics Challenge, Phase 2
# Copyright (c) 2019-2021, NASA-JSC. All Rights Reserved
# Unauthorized Distribution Strictly Prohibited
#
# move to this directory
_this_dir="$( cd "$(dirname "$0")" ; pwd -P )"
pushd `pwd` > /dev/null 2>&1
cd $_this_dir
# Source helper scripts
source "srcp2_setup.bash"
source "gpu_and_x.bash"
image_tag="wvu-competitor:latest"
sim_container_name="srcp2-final"
cmp_container_name="competitor-final"
# container constraints
use_local="false"
cpus=4
mem="5g"
cmp_volumes=""
# Main SIM Ros Master Network Name
simalias_name="simmaster"
srcp2net_name="srcp2net"
function help(){
echo -e "${B}Summary:${rs}
This script manages the docker containers necessary to run the Space
Robotics Simulation (Final). It starts the Docker containers, and
configures the host correctly for XServer forwarding.
Note that all short-form options are case-sensitive
${B}General Options:${rs}
${B}-h | --help${rs}
Show this message and quit
${B}-L | --local-docker${rs}
Use the local versions of the docker images (if they exist). This overrides
the default behaviour, which is to search for updates each time this
script is run.
${B}-d | --developer${rs}
Developer mode with '/home/srcp2/cmp_workspace' from to host folder
${B}-i | --interactive${rs}
Simply launch as normal, but override all runtime args with
interactive BASH shell
${B}-c | --cpus${rs}
Set number of CPUs available to this container. Default is ${cpus}
${B}-m | --mem${rs}
Set GB of RAM available to this container. Default is ${mem}
Throttling this may result in undefined behavior
${B}Copyright${rs}
Space Robotics Challange, Phase 2
Copyright (c) 2019, 2020, 2021, NASA-JSC. All Rights Reserved
Unauthorized Distribution Strictly Prohibited
"
}
# ______________________________________________________________________________________________________________________
echo_header
echo -e "${B}From host system:${rs}\n"
for arg in "$@"; do
shift
case "$arg" in
"--help") set -- "$@" "-h" ;;
"--local-docker") set -- "$@" "-L" ;;
"--interactive") set -- "$@" "-i" ;;
"--developer") set -- "$@" "-d" ;;
#
"--cpus") set -- "$@" "-c";;
"--mem") set -- "$@" "-m";;
*) set -- "$@" "$arg"
esac
done
OPTIND=1
while getopts hC:dl:nd:Lic:m: arg; do
case $arg in
h)
help
exit 0
;;
L)
use_local="true"
;;
d)
cmp_volumes="developer"
;;
i)
interactive="-it"
override_command="/bin/bash"
;;
c)
cpus=$OPTARG
;;
m)
mem="${OPTARG}g"
;;
*)
echo -e "$echo_error input option '$arg' is not supported"
quit_with_popd 1
;;
esac
done
# update docker images
if [[ "$use_local" == "false" ]]; then
if ! docker pull $image_tag; then
echo -e "$echo_error Docker pull failed"
exit 1
fi
echo -e "$echo_ok image update complete"
else
echo -e "$echo_warn Using local versions of the docker images, will ${B}not${rs} check Dockerhub for updates"
fi
# Display run state information to user (dev and comp)
echo
echo -e "$echo_info running image : ${b}$image_tag${rs}"
echo -e "$echo_info container name : ${b}$cmp_container_name${rs}"
echo -e "$echo_info volumes from name: ${b}$sim_container_name${rs}"
if [ -z $interactive ]; then
echo
echo -e "$echo_info Simulation container started. Gazebo startup typically takes a few seconds"
echo -e "$echo_info run ${b}docker kill $container_name${rs} to stop, or await sim timeout"
else
echo
echo -e "$echo_info Running in interactive mode. Starting a BASH shell..."
fi
echo
# Setup the Host Volume
echo
if [[ $cmp_volumes =~ "developer" ]]; then
cmp_host_path=$(cd ../../cmp_workspace && pwd)
if [[ ! -d $cmp_host_path ]]; then
echo -e "$echo_error This machine does not have access to competitor source code. ${r}Cannot run as developer!${rs} Nice try"
exit 1
fi
cmp_volumes="--volume=${cmp_host_path}:/home/srcp2/cmp_workspace:rw"
fi
echo
echo -e "$echo_info Confirming Network Setup: ${b} Network Setup${rs}..."
if ! docker network ls | grep -q "$srcp2net_name"; then
echo -e "$echo_info Setting up as ${b} Bridge $srcp2net_name${rs}"
docker network create --driver=bridge $srcp2net_name
echo
else
echo -e "$echo_info Existing network found: ${b}$srcp2net_name${rs}"
fi
echo -e "$echo_info Network Setup is now ${b} ready as $srcp2net_name${rs}..."
echo
echo -e "${B}________________________________________________________________________________________________________________________${rs}"
echo -e "${B}From Container:${rs}"
echo
# $cmp_volumes \
# X Server / Display
if ! x_host_setup; then
echo -e "$echo_error Host X-Server setup failed"
exit 1
fi
# XServer
xsock="/tmp/.X11-unix"
xauth="/tmp/.docker.xauth"
echo -e "$echo_info X Display ${b}Setup Done${rs}"
docker run --rm \
--name $cmp_container_name\
--user 1001:1001 \
$interactive \
--gpus all \
--env="DISPLAY"=$DISPLAY \
--env=XAUTHORITY=$xauth \
--env=XAUTHORITY=$xauth \
--volume=$xsock:$xsock:rw \
--volume=$xauth:$xauth:rw \
--volume=/dev/log:/dev/log:rw \
--device=/dev/dri:/dev/dri \
--network $srcp2net_name \
--network-alias $simalias_name \
--env=ROS_MASTER_URI="http://${simalias_name}:11311" \
--cpus=$cpus \
--memory=$mem \
$cmp_volumes \
$image_tag $override_command
exit $?