-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstart_docker.sh
142 lines (124 loc) · 3.81 KB
/
start_docker.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
IMAGE_NAME="epfl-lasa/iiwa_ros"
CONTAINER_NAME="${IMAGE_NAME//[\/.]/-}"
USERNAME="ros"
MODE=()
USE_NVIDIA_TOOLKIT=true
# Help
HELP_MESSAGE="Usage: ./start_dockers.sh [interactive | server | connect] [-i, --image] [-u, --user]
Build the '${IMAGE_NAME}' image.
Options:
interactive Spin the image in the console
server Spin the image as an ssh server
connect Connects to an active container
-i, --image The name of the image to use to start the container
-u, --user Specify the name of the login user. (optional)
-h, --help Show this help message and the one from aica-docker
Additional arguments are passed to the aica-docker command.
"
# Argument parsing
RUN_FLAGS=()
FWS_FLAGS=()
SHOW_HELP=false
while [ "$#" -gt 0 ]; do
case "$1" in
-i | --image)
IMAGE_NAME=$2
shift 2
;;
-u | --user)
USERNAME=$2
shift 2
;;
-m | --mode)
MODE=$2
shift 2
;;
-h | --help)
SHOW_HELP=true
shift 1
;;
*)
if [ -z "${MODE}" ]; then
MODE=$1
else
FWD_ARGS+=("$1")
fi
shift 1
;;
esac
done
# Help verbose
if $SHOW_HELP; then
echo $HELP_MESSAGE
aica-docker $MODE -h
exit 1
fi
# Gotta make sure ssh agent is running
eval $(ssh-agent)
# Handle interactive/server specific arguments
if [ "${MODE}" != "connect" ]; then
# Check if a conitainer with this name is already running
if [ "$( docker container inspect -f '{{.State.Status}}' ${CONTAINER_NAME} 2>/dev/null)" == "running" ]; then
echo "A container named ${CONTAINER_NAME} is already running. Stopping it."
docker stop ${CONTAINER_NAME}
fi
# network for ros
FWD_ARGS+=(--net=host)
FWD_ARGS+=(--env ROS_HOSTNAME="$(hostname)")
# Handle GPU usage
[[ ${USE_NVIDIA_TOOLKIT} = true ]] && GPU_FLAG="--gpus all" || GPU_FLAG=""
FWD_ARGS+=("--runtime=nvidia")
# FWD_ARGS+=("nvidia-smi")
# Other
FWD_ARGS+=("--privileged")
# Setup shared volumes for dev
docker volume rm llm_simulator
docker volume create --driver local \
--opt type="none" \
--opt device="${PWD}/ros_ws/src/llm_simulator" \
--opt o="bind" \
"llm_simulator"
FWD_ARGS+=(--volume="llm_simulator:/home/ros/ros_ws/src/llm_simulator:rw")
docker volume rm llm_common
docker volume create --driver local \
--opt type="none" \
--opt device="${PWD}/ros_ws/src/llm_common" \
--opt o="bind" \
"llm_common"
FWD_ARGS+=(--volume="llm_common:/home/ros/ros_ws/src/llm_common:rw")
docker volume rm llm_primitives
docker volume create --driver local \
--opt type="none" \
--opt device="${PWD}/ros_ws/src/primitive_library" \
--opt o="bind" \
"llm_primitives"
FWD_ARGS+=(--volume="llm_primitives:/home/ros/ros_ws/src/primitive_library:rw")
docker volume rm planner
docker volume create --driver local \
--opt type="none" \
--opt device="${PWD}/ros_ws/src/planner" \
--opt o="bind" \
"planner"
FWD_ARGS+=(--volume="planner:/home/ros/ros_ws/src/planner:rw")
docker volume rm vision_server
docker volume create --driver local \
--opt type="none" \
--opt device="${PWD}/ros_ws/src/vision_server" \
--opt o="bind" \
"vision_server"
FWD_ARGS+=(--volume="vision_server:/home/ros/ros_ws/src/vision_server:rw")
fi
# Trick aica-docker into making a server on a host network container
if [ "${MODE}" == "server" ]; then
FWD_ARGS+=("--detach")
MODE=interactive
fi
# Start docker using aica
aica-docker \
"${MODE}" \
"${IMAGE_NAME}" \
-u "${USERNAME}" \
-n "${CONTAINER_NAME}" \
${GPU_FLAG} \
"${FWD_ARGS[@]}" \