forked from HonuRobotics/dockwater
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.bash
More file actions
executable file
·95 lines (86 loc) · 3.64 KB
/
run.bash
File metadata and controls
executable file
·95 lines (86 loc) · 3.64 KB
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
#!/usr/bin/env bash
#
# Copyright (C) 2018 Open Source Robotics Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Runs a docker container with the image created by build.bash
# Requires:
# docker
# nvidia-docker
# an X server
# rocker
# Recommended:
# A joystick mounted to /dev/input/js0 or /dev/input/js1
############################################################
# Help #
############################################################
Help()
{
# Display Help
echo "Runs a docker container with the image created by build.bash."
echo
echo "Syntax: $(basename $0) [-p <host_port>] [-c|i|r|s|t|h] <docker_img_name>"
echo "options:"
echo "r With internal graphics card (without nvidia) and with RDP. The default user in container is 'docker' due to RDP constraints (custom host port can be set via the -p option)"
echo "c Add cuda library support."
echo "i With internal graphics card (without nvidia)"
echo "p Override host RDP port (follow syntax for usage, only affects -r option)"
echo "s Create an image with novnc for use with cloudsim."
echo "t Create a test image for use with CI pipelines."
echo "x Create base image for the VRX competition server."
echo "h Print this help message and exit."
echo
}
JOY=/dev/input/js0
CUDA=""
HOST_RDP_PORT=3389
ROCKER_ARGS="--devices /dev/dri $JOY --dev-helpers --nvidia --x11 --git --volume "$HOME":/root/HOST"
while getopts ":cstxhirp:" option; do
case $option in
c) # enable cuda library support
CUDA="--cuda";;
i) # With internal graphics card (without nvidia)
ROCKER_ARGS="--devices /dev/dri $JOY --x11 --git --volume "$HOME":/root/HOST";;
r) # With internal graphics card (without nvidia) and with RDP.
# The default user in container is 'docker' due to RDP constraints (custom host port can be set via the -p option)
# shellcheck disable=SC2116
ROCKER_ARGS="--devices /dev/dri $JOY --x11 --git --port "$HOST_RDP_PORT":3389 --volume "$HOME":/home/docker/HOST";;
s) # Build cloudsim image
ROCKER_ARGS="--nvidia --novnc --turbovnc --user --user-override-name=developer";;
t) # Build test image for Continuous Integration
echo "Building CI image"
ROCKER_ARGS="--dev-helpers --nvidia";;
x) # Build VRX Competition base image
echo "Building VRX Competition server base image"
ROCKER_ARGS="--dev-helpers --devices $JOY --nvidia --x11 --user --user-override-name=developer";;
h) # print this help message and exit
Help
exit;;
p) # Override host RDP port
HOST_RDP_PORT=$OPTARG;;
:) #handle missing arguments
echo "Error: Option -$OPTARG requires an argument." >&2
exit 1;;
\?) # handle unrecognized options
echo "Invalid option: -$OPTARG" >&2
exit 1;;
esac
done
IMG_NAME=${@:$OPTIND:1}
# Replace `:` with `_` to comply with docker container naming
# And append `_runtime`
CONTAINER_NAME="$(tr ':' '_' <<< "$IMG_NAME")_runtime"
ROCKER_ARGS="${ROCKER_ARGS} --name $CONTAINER_NAME"
echo "Using image <$IMG_NAME> to start container <$CONTAINER_NAME>"
rocker ${CUDA} ${ROCKER_ARGS} $IMG_NAME