-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_image.sh
executable file
·89 lines (67 loc) · 2.1 KB
/
build_image.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
#!/bin/bash
# Map host's display socket to docker
DOCKER_ARGS+=("-v /tmp/.X11-unix:/tmp/.X11-unix")
DOCKER_ARGS+=("-v $HOME/.Xauthority:/home/admin/.Xauthority:rw")
# DOCKER_ARGS+=("-e DISPLAY")
DOCKER_ARGS+=("-e NVIDIA_VISIBLE_DEVICES=all")
DOCKER_ARGS+=("-e NVIDIA_DRIVER_CAPABILITIES=all")
# DOCKER_ARGS+=("-e FASTRTPS_DEFAULT_PROFILES_FILE=/usr/local/share/middleware_profiles/rtps_udp_profile.xml")
xhost +local:root
image_name="moveit-classic-noetic"
container_name="ajgar-docker-build"
# Initialize variables
force_option=false
clean_option=false
# Parse options
while [[ $# -gt 0 ]]; do
case "$1" in
--force)
force_option=true
shift
;;
--clean)
clean_option=true
shift
;;
*)
echo "Invalid option: $1"
exit 1
;;
esac
done
if $force_option; then
echo "Buidling Existing Docker Image: $image_name"
docker build -f Dockerfile -t "$image_name":1.0 .
./build_image.sh
else
run_command='source /opt/ros/noetic/setup.bash && catkin_make && source devel/setup.bash && exit'
if $clean_option; then
run_command='source /opt/ros/noetic/setup.bash && rm -rf build devel && catkin_make && source devel/setup.bash && exit'
echo "Force Command Enabled"
else
echo "Force Command Disabled"
fi
if docker images --format '{{.Repository}}' | grep -q "$image_name"; then
echo "Found Docker Image: $image_name:1.0"
echo "Updating the existing Docker image: $image_name:1.0"
docker run -it --rm=false \
--privileged \
${DOCKER_ARGS[@]} \
-e DISPLAY=$DISPLAY \
-v $PWD/build_files:/workspaces/sim_ws/ \
-v $PWD:/workspaces/sim_ws/src \
-v /etc/localtime:/etc/localtime:ro \
--name "$container_name" \
--runtime nvidia \
--workdir /workspaces/sim_ws \
$@ \
"$image_name":1.0 \
bash -c "$run_command"
docker rm "$container_name"
# ./run_image.sh
else
echo "Building a new Docker image: $image_name"
docker build -f Dockerfile -t "$image_name":1.0 .
./build_image.sh
fi
fi