-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker.sh
executable file
·135 lines (121 loc) · 3.16 KB
/
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
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage: $0 <command>"
echo " where <command> is one of: build, run"
exit 1
fi
is_valid_ip() {
local ip=$1
local valid_ip_regex="^([0-9]{1,3}\.){3}[0-9]{1,3}$"
if [[ $ip =~ $valid_ip_regex ]]; then
# Check if each octet is between 0 and 255
IFS='.' read -r -a octets <<< "$ip"
for octet in "${octets[@]}"; do
if (( octet < 0 || octet > 255 )); then
return 1
fi
done
return 0
else
return 1
fi
}
build() {
cd docker || { echo "Could not find docker directory"; exit 1; }
build_args=()
cohda_llc_include_dir=""
while [[ $# -gt 0 ]]; do
case $1 in
--no-cache)
build_args+=("--no-cache")
shift
;;
--build-cohda)
shift
cohda_llc_include_dir="$1"
if [ -z "$cohda_llc_include_dir" ]; then
echo "Missing path to Cohda LLC library"
exit 1
fi
if [ ! -d "$cohda_llc_include_dir" ]; then
echo "Directory not found: $cohda_llc_include_dir"
exit 1
fi
;;
*)
shift
;;
esac
done
if [ -n "$cohda_llc_include_dir" ]; then
echo "Building with Cohda LLC support"
echo "Cohda LLC include directory: $cohda_llc_include_dir"
cp -fr "$cohda_llc_include_dir" cohda
else
echo "Building without Cohda LLC support"
fi
docker build -t "autoware_v2x" "${build_args[@]}" .
rm -rf cohda >/dev/null 2>&1
exit $?
}
if [ "$1" == "build" ]; then
build "$@"
elif [ "$1" == "run" ]; then
if [ "$#" -ne 5 ]; then
echo "Usage: $0 run </path/to/autoware_v2x.param.yaml> <ros_domain_id> <ros_network_interface> <master_ip>"
exit 1
fi
if [ ! -f "$2" ]; then
echo "File not found: $2"
exit 1
fi
if [ ! -r "$2" ]; then
echo "File not readable: $2"
exit 1
fi
if [ "${2: -5}" != ".yaml" ]; then
echo "File is not a .yaml file: $2"
exit 1
fi
if [ ! -s "$2" ]; then
echo "File is empty: $2"
exit 1
fi
hostname_ip=$(ifconfig "$4" | grep 'inet ' | awk '{print $2}')
if [ -z "$hostname_ip" ]; then
echo "Couldn't find ip address for interface: $4"
exit 1
fi
if ! is_valid_ip "$5"; then
echo "Invalid ROS master ip address: $5"
exit 1
fi
if ! docker image inspect "autoware_v2x" &> /dev/null; then
echo "Docker image not found. Do you want to build it now? [y/N]"
read -r response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
build
else
exit 1
fi
fi
cp -f docker/.env.example docker/.env
sed -i "s/ROS_DOMAIN_ID=.*/ROS_DOMAIN_ID=$3/" docker/.env
sed -i "s/ROS_HOSTNAME=.*/ROS_HOSTNAME=$hostname_ip/" docker/.env
sed -i "s/ROS_MASTER_URI=.*/ROS_MASTER_URI=http:\/\/$5:11311/" docker/.env
PARAM_FILE=$(realpath "$2")
MOUNT_OPTIONS="type=bind,source=$PARAM_FILE,target=/v2x/install/autoware_v2x/share/autoware_v2x/config/autoware_v2x.param.yaml"
docker run -d --rm \
--mount "${MOUNT_OPTIONS}" \
--privileged \
--name autoware_v2x \
--network host \
--env-file "docker/.env" \
autoware_v2x
rm -f docker/.env
exit $?
else
echo "Usage: $0 <command>"
echo " where <command> is one of: build, run"
exit 1
fi