diff --git a/docker/Dockerfile.base b/docker/Dockerfile.base index 06c8da65..6212bbce 100644 --- a/docker/Dockerfile.base +++ b/docker/Dockerfile.base @@ -28,7 +28,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y -o Dpkg::Option ros-humble-ros2-controllers \ ros-humble-rqt-common-plugins \ ros-humble-webots-ros2 \ - ros-humble-dynamixel-workbench-toolbox \ + ros-humble-dynamixel-workbench-toolbox \ ros-humble-behaviortree-cpp \ libopencv-dev \ python3-pip \ @@ -43,7 +43,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y -o Dpkg::Option vim \ rsync \ dialog \ - fish + fish @@ -58,7 +58,7 @@ RUN su memristor -c 'code --install-extension eamodio.gitlens' && \ su memristor -c 'code --install-extension ms-vscode.cpptools-extension-pack' && \ su memristor -c 'code --install-extension usernamehw.errorlens' && \ su memristor -c 'code --install-extension redhat.vscode-xml' && \ - su memristor -c 'code --install-extension ms-iot.vscode-ros' + su memristor -c 'code --install-extension ms-iot.vscode-ros' @@ -69,7 +69,7 @@ RUN su memristor -c 'curl -fsSL https://code-server.dev/install.sh | sh' && \ su memristor -c 'code-server --install-extension ms-vscode.cpptools-extension-pack' && \ su memristor -c 'code-server --install-extension usernamehw.errorlens' && \ su memristor -c 'code-server --install-extension redhat.vscode-xml' && \ - su memristor -c 'code-server --install-extension ms-iot.vscode-ros' + su memristor -c 'code-server --install-extension ms-iot.vscode-ros' # Webots RUN curl -L -o /tmp/webots.deb \ diff --git a/docker/Makefile b/docker/Makefile index 19433f10..5fab0d56 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -1,3 +1,4 @@ +MAKEFLAGS+=--silent UID:=$(shell id -u) DOCKER_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) PROJECT_DIR:=$(shell dirname ${DOCKER_DIR}) @@ -7,23 +8,28 @@ IMAGE=ghcr.io/memristor/mep3 .PHONY: all -all: destroy test-nvidia run setup-default exec start-code-server +all: destroy test-nvidia run setup-default + +colors: + $(eval NC=\033[1;0m) + $(eval RED=\033[1;31m) + $(eval GREEN=\033[1;32m) + $(eval BOLD=\033[1;37m) vnc: $(eval FLAVOR=vnc) $(eval IMAGE=ghcr.io/memristor/mep3-vnc) - @true + true build: echo ${NO_CACHE_ARG} - @DOCKER_BUILDKIT=1 docker build ${DOCKER_DIR} -f ${DOCKER_DIR}/Dockerfile.base -t mep3 ${DOCKER_ARGS} --build-arg UID=${UID} - @[ ${FLAVOR} != 'devel' ] && \ + DOCKER_BUILDKIT=1 docker build ${DOCKER_DIR} -f ${DOCKER_DIR}/Dockerfile.base -t mep3 ${DOCKER_ARGS} --build-arg UID=${UID} + [ ${FLAVOR} != 'devel' ] && \ DOCKER_BUILDKIT=1 docker build ${DOCKER_DIR} -f ${DOCKER_DIR}/Dockerfile.${FLAVOR} -t ${IMAGE} ${DOCKER_ARGS} || \ true -run: - @${MAKE} -s test-nvidia - @docker run \ +run: test-nvidia + docker run \ --net=host \ --ipc=host \ --cap-add SYS_ADMIN \ @@ -37,42 +43,37 @@ run: -v /dev/dri:/dev/dri:ro \ -v /dev:/dev:rw \ -v ${PROJECT_DIR}:/memristor/ros2_ws/src/mep3:rw \ - -d -it ${IMAGE} - -test-nvidia: - $(eval NC=\033[1;0m) - $(eval RED=\033[1;31m) - $(eval GREEN=\033[1;32m) + -d -it ${IMAGE} 1>/dev/null - @lspci | grep -qi nvidia && base64 --decode massage | unxz || true - - @docker run --rm \ +test-nvidia: colors + lspci | grep -qi nvidia && base64 --decode massage | unxz || true + docker run --rm \ -e NVIDIA_DRIVER_CAPABILITIES=all ${NVIDIA_GPU} \ -e DISPLAY=${DISPLAY} \ ${IMAGE} | grep -qi 'nvidia' && \ printf '%b\n' "${RED}Detected NVIDIA GPU in system, but missing packets, look up NVIDIA GPU section in README!\n${NC}" || \ - printf '%b\n' "${GREEN}Everything set up!${NC}" + true start-code-server: - @docker exec -d -it mep3-${FLAVOR} bash -c 'pgrep code-server || code-server /memristor/ros2_ws/src/mep3' && \ + docker exec -d -it mep3-${FLAVOR} bash -c 'pgrep code-server || code-server /memristor/ros2_ws/src/mep3' && \ xdg-open 'localhost:31415?folder=/memristor/ros2_ws/src/mep3' stop-code-server: - @docker exec -it mep3-${FLAVOR} pkill -f code-server + docker exec -it mep3-${FLAVOR} pkill -f code-server exec: - @docker exec -it mep3-${FLAVOR} bash + docker exec -it mep3-${FLAVOR} bash destroy: - @docker container kill mep3-${FLAVOR} || true - @docker container rm -f mep3-${FLAVOR} || true + docker container kill mep3-${FLAVOR} 1>/dev/null || true + docker container rm -f mep3-${FLAVOR} 1>/dev/null || true -setup-default: - @docker exec -it mep3-${FLAVOR} sh -c '/usr/bin/setup.sh --all' - @echo 'Restarting mep3-${FLAVOR} container...' - @docker restart mep3-${FLAVOR} +setup-default: colors + docker exec -it mep3-${FLAVOR} sh -c '/usr/bin/setup.sh --default' + printf '%b\n%b\n' "${GREEN}Default setup complete!${NC}" \ + "Run ${BOLD}make exec${NC} or ${BOLD}docker exec -it mep3-${FLAVOR}${NC} to access the container" -setup-interactive: - @docker exec -it mep3-${FLAVOR} sh -c '/usr/bin/setup.sh --all --interactive' - @echo 'Restarting mep3-${FLAVOR} container...' - @docker restart mep3-${FLAVOR} +setup-interactive: colors + docker exec -it mep3-${FLAVOR} sh -c '/usr/bin/setup.sh --interactive' + printf '%b\n%b\n' "${GREEN}Interactive setup complete!${NC}" \ + "Run ${BOLD}make exec${NC} or ${BOLD}docker exec -it mep3-${FLAVOR}${NC} to access the container" diff --git a/docker/config/bashrc b/docker/config/bashrc index 6863bc16..dd0ddb92 100644 --- a/docker/config/bashrc +++ b/docker/config/bashrc @@ -1,8 +1,11 @@ export WEBOTS_HOME=/usr/local/webots export USERNAME=default -export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp +if uname -v | grep -qi 'ubuntu'; then + export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp +fi alias cb='colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Debug' +alias rr='rm -rf /memristor/ros2_ws/build /memristor/ros2_ws/install' test -f /opt/ros/humble/local_setup.bash && \ source /opt/ros/humble/local_setup.bash diff --git a/docker/config/setup.sh b/docker/config/setup.sh index e701390a..ebc00655 100755 --- a/docker/config/setup.sh +++ b/docker/config/setup.sh @@ -1,13 +1,11 @@ #!/usr/bin/env bash -_help=false _configure_proxy=false _vnc=false _first_time_ros_setup=false _enhanced_shell_prompt=false _shell_shortcuts=false -_all=false -interactive=false +_interactive=false usage() { echo "Usage: $0 [--help] [--configure-proxy] [--vnc] [--first-time-ros-setup] [--enhanced-shell-prompt] [--shell-shortcuts] [--interactive]" @@ -28,7 +26,7 @@ default_configure_proxy() { } configure_proxy() { - if $interactive; then + if $_interactive; then # FTN proxy is actually enabled here if dialog --title 'mep3 config' --defaultno --yesno 'Enable UNS proxy' 5 30; then sed '/# Setup_proxy/d' -i /memristor/.bashrc @@ -44,7 +42,6 @@ configure_proxy() { } default_first_time_ros_setup() { - clear sudo -E rosdep init sudo -E apt-get install -y python3-vcstool rosdep --rosdistro "${ROS_DISTRO}" update @@ -52,7 +49,7 @@ default_first_time_ros_setup() { } first_time_ros_setup() { - if $interactive; then + if $_interactive; then if dialog --title 'mep3 config' --yesno 'Run first time ROS setup' 5 30; then default_first_time_ros_setup return @@ -68,7 +65,7 @@ default_enhanced_shell_prompt() { } enhanced_shell_prompt() { - if $interactive; then + if $_interactive; then if dialog --title 'mep3 config' --yesno 'Enable enhanced shell prompt' 5 38; then default_enhanced_shell_prompt return @@ -86,7 +83,7 @@ default_shell_shortcuts() { } shell_shortcuts() { - if $interactive; then + if $_interactive; then if dialog --title 'mep3 config' --yesno 'Enable shell shortcuts' 5 30; then default_shell_shortcuts return @@ -131,7 +128,7 @@ vnc() { echo "TurboVNC is not installed" exit 1 fi - if $interactive; then + if $_interactive; then interactive_vnc return fi @@ -141,7 +138,6 @@ vnc() { finalize() { sed '/# Setup_shell/d' -i /memristor/.bashrc echo 'echo "$-" | grep i -q && exec fish # Setup_shell' >>/memristor/.bashrc - clear } @@ -163,46 +159,33 @@ while [ "$#" -gt 0 ]; do _shell_shortcuts=true ;; --interactive) - interactive=true - ;; - --help) - _help=true + _interactive=true ;; - --all) - _all=true + --default) + _enhanced_shell_prompt=true + _shell_shortcuts=true ;; - *) + --help|*) usage ;; esac shift done -if $_help; then - usage -fi - -if $_all; then +if $_configure_proxy; then configure_proxy +fi +if $_first_time_ros_setup; then first_time_ros_setup +fi +if $_enhanced_shell_prompt; then enhanced_shell_prompt +fi +if $_shell_shortcuts; then shell_shortcuts +fi +if $_vnc; then vnc -else - if $_configure_proxy; then - configure_proxy - fi - if $_first_time_ros_setup; then - first_time_ros_setup - fi - if $_enhanced_shell_prompt; then - enhanced_shell_prompt - fi - if $_shell_shortcuts; then - shell_shortcuts - fi - if $_vnc; then - vnc - fi fi + finalize