-
Notifications
You must be signed in to change notification settings - Fork 4
/
run
executable file
·139 lines (118 loc) · 3.35 KB
/
run
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
#!/bin/bash
help_() {
echo \
"This is a simple CLI with the most default commands to help running the object-level fusion.
Despite most of the underneath commands being run using Docker, it's a specially useful script for people who don't know how to use Docker.
Usage: ./$(basename $0) [up|down|build|compile|status|shell|tests|clean|tests_no_tty|help]
Commands:
up Starts the application.
down Bring the application down. More useful when starting the application in background or for cleaning.
build Builds the applications containers.
compile Recompiles from source code without the need to call 'build' again. Requires that the application is NOT running.
status To check the status of the application containers
shell Executes a shell inside the application container. Useful for running customized commands. Requires the application to be UP.
tests Executes the unitary tests from the application. Requires the application to be UP.
clean Delete the directories auto generated when compiling the application
help Prints this help
"
}
CMD="$1"
ARGS=${@:2}
COMPOSE_FILE="docker/docker-compose.dev.yml"
set -e
_retrieve_build_files() {
set +e
[ -f install/setup.sh ] \
|| sudo docker-compose -f $COMPOSE_FILE run \
--rm \
--entrypoint='' \
fusion_layer \
bash -c "cp -aT /opt/install /ros2_ws/install \
&& cp -aT /opt/build /ros2_ws/build \
&& cp -aT /opt/log /ros2_ws/log"
}
build() {
echo "Building the application..."
sudo docker-compose -f $COMPOSE_FILE build $ARGS
}
up() {
echo "Bringing the application up..."
_retrieve_build_files
sudo docker-compose -f $COMPOSE_FILE up $ARGS
}
down() {
echo "Bringing the application down..."
sudo docker-compose -f $COMPOSE_FILE down $ARGS
}
shell() {
echo "Initializing shell in the container..."
set +e
sudo docker-compose -f $COMPOSE_FILE exec fusion_layer /entrypoint.sh bash $ARGS \
|| echo -e "\nSome error happened. Was the application UP when you tried to run the command?" \
&& exit 1
}
compile() {
echo "Initializing shell in the container..."
sudo docker-compose -f $COMPOSE_FILE run --rm \
--entrypoint='' \
fusion_layer \
bash -c ". /opt/ros/foxy/setup.sh && colcon build $ARGS"
}
status_() {
echo "Status of the application containers:"
sudo docker-compose -f $COMPOSE_FILE ps
}
tests() {
echo "Running tests..."
sudo docker-compose -f $COMPOSE_FILE exec fusion_layer \
/entrypoint.sh colcon test --packages-above fusion_layer --return-code-on-test-failure --event-handlers console_cohesion+ $ARGS
}
tests_no_tty() {
echo "Running tests..."
sudo docker-compose -f $COMPOSE_FILE exec -T fusion_layer \
/entrypoint.sh colcon test --packages-above fusion_layer --return-code-on-test-failure --event-handlers console_cohesion+ $ARGS
}
clean() {
echo "Cleaning generated files"
sudo rm -rf build log install
}
case $CMD in
"")
echo "No command specified, assuming 'up'..."
up
;;
build)
build
;;
up)
up
;;
down)
down
;;
status)
status_
;;
shell)
shell
;;
compile)
compile
;;
tests)
tests
;;
help)
help_
;;
clean)
clean
;;
tests_no_tty)
tests_no_tty
;;
*)
echo "Unknown command $1!"
exit 1
;;
esac