Skip to content

Commit e38497b

Browse files
authored
Dockerfile improvement (#4)
* tmux script to run entire stack * remove -j for mac add and run tmux script * generalize tmux to work with install path param * sanitize variable input, improve checking * add docker context variable * check for context variable * stop as first argument move path to -d argument * move 'bash -lc' to ENTRYPOINT * combine layers, fix entry point for docker_all make target * fast forward dockerfile to match upstream changes * remove -j * updated README for docker changes
1 parent c7a89da commit e38497b

4 files changed

Lines changed: 93 additions & 5 deletions

File tree

Dockerfile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ RUN apt-get update && \
55
apt-get install -y git libgflags-dev libpopt-dev \
66
libgoogle-glog-dev liblua5.1-0-dev \
77
libboost-all-dev libqt5websockets5-dev \
8-
python-is-python3 libeigen3-dev sudo
8+
python-is-python3 libeigen3-dev sudo tmux
99

1010
# install ros apt deps
1111
RUN apt-get install -y ros-noetic-tf ros-noetic-angles
@@ -35,5 +35,12 @@ RUN echo "source /opt/ros/noetic/setup.bash\n" \
3535

3636

3737
# build deps
38-
RUN /bin/bash -lc "cd amrl_msgs && make -j"
39-
RUN /bin/bash -lc "cd ut_automata && make -j"
38+
RUN /bin/bash -lc "cd amrl_msgs && make"
39+
RUN /bin/bash -lc "cd ut_automata && make"
40+
41+
# add launcher
42+
ENV CS378_DOCKER_CONTEXT 1
43+
COPY --chown=dev:dev ./tmux_session.sh /home/dev/tmux_session.sh
44+
RUN chmod u+x /home/dev/tmux_session.sh
45+
CMD [ "/home/dev/tmux_session.sh" ]
46+
ENTRYPOINT [ "/bin/bash", "-l", "-c" ]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ all: build/CMakeLists.txt.copy
1818
$(MAKE) --no-print-directory -C build
1919

2020
docker_all: docker_build_q
21-
docker run --rm --volume "$(shell pwd)":/home/dev/cs378_starter cs378_starter bash -lc "cd cs378_starter && make -j"
21+
docker run --rm --volume "$(shell pwd)":/home/dev/cs378_starter cs378_starter "cd cs378_starter && make -j"
2222

2323
docker_shell: docker_build_q
2424
if [ $(shell docker ps -a -f name=cs378_starter_shell | wc -l) -ne 2 ]; then docker run -dit --name cs378_starter_shell --volume "$(shell pwd)":/home/dev/cs378_starter --workdir /home/dev/cs378_starter -p 10272:10272 cs378_starter; fi

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ Please follow the instructions in the UT AUTOmata [reference manual](https://dri
2323
### Optional: Building/Running with Docker
2424
1. Make sure you have Docker installed and set up.
2525
2. Make sure you are in the root directory of the repository.
26-
3. Run `make docker_all` to just compile. You can run `make docker_shell` to get a shell within the Docker container. Inside this shell, you can build with `make -j`, as well as run other utilities such as `roscore` and the `ut_automata` websocket and simulator.
26+
3. Run `make docker_all` to just compile.
27+
4. You can run `make docker_shell` to get a shell within the Docker container. The shell will automatically launch `roscore` and the `ut_automata` websocket and simulator inside of a `tmux` session. Inside the shell, you can compile and run your navigation code and connect using localhost in the web visualization.
28+
29+
For debugging purposes, you can look at the tmux processes at any time by attaching to the session: `tmux a -t ROS`. For more information about `tmux`, refer to the [tmux documentation](https://tmuxguide.readthedocs.io/en/latest/tmux/tmux.html)
30+
5. To shutdown the docker container, run `make docker_stop`

tmux_session.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
tmux -V > /dev/null 2>&1
4+
if [ $? -eq 127 ]
5+
then
6+
echo "tmux is not installed! Cannot continue"
7+
exit 127
8+
fi
9+
10+
session="ROS"
11+
12+
tmux has-session -t $session > /dev/null 2>&1
13+
RUNNING=$?
14+
15+
ARG=$1
16+
if [[ "${ARG}" == "stop" ]]
17+
then
18+
if [ $RUNNING -ne 0 ]
19+
then
20+
echo "tmux session is not running."
21+
exit 0
22+
fi
23+
24+
echo "Killing running tmux session"
25+
tmux kill-session -t $session > /dev/null 2>&1
26+
exit 0
27+
fi
28+
29+
if [ $RUNNING -eq 0 ]
30+
then
31+
echo "ERROR: tmux session is already running. Kill current session with ./tmux_session.sh stop"
32+
exit 127
33+
fi
34+
35+
36+
if [ "${ARG}" == "-d" ]
37+
then
38+
INSTALL_PATH=$2
39+
if [ -z "${INSTALL_PATH}" ]
40+
then
41+
INSTALL_PATH="${HOME}/"
42+
fi
43+
44+
# check for / at the end
45+
if [ ${INSTALL_PATH: -1} != '/' ]
46+
then
47+
INSTALL_PATH="${INSTALL_PATH}/"
48+
fi
49+
else
50+
INSTALL_PATH="${HOME}/"
51+
fi
52+
53+
if ! [[ -d "${INSTALL_PATH}ut_automata" ]]
54+
then
55+
echo "${INSTALL_PATH}ut_automata does not exist, please provide a valid path using ./tmux_session.sh -d <INSTALL_PATH>"
56+
exit 127
57+
fi
58+
59+
tmux new-session -d -s $session
60+
tmux set mouse on
61+
window=0
62+
63+
tmux rename-window -t $session:$window 'roscore'
64+
tmux send-keys -t $session:$window 'roscore' C-m
65+
66+
window=1
67+
tmux new-window -t $session:$window -n 'simulator'
68+
tmux send-keys -t $session:$window "cd ${INSTALL_PATH}/ut_automata && ./bin/simulator --localize" C-m
69+
70+
window=2
71+
tmux new-window -t $session:$window -n 'websocket'
72+
tmux send-keys -t $session:$window "cd ${INSTALL_PATH}/ut_automata && ./bin/websocket" C-m
73+
74+
if ! [ -z ${CS378_DOCKER_CONTEXT+x} ]
75+
then
76+
/bin/bash
77+
fi

0 commit comments

Comments
 (0)