From eb3a999c35be91efa135c408c7980a9453e9ebd4 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Thu, 9 Mar 2023 15:13:02 -0500 Subject: [PATCH 01/12] add non-rocker Dockerfile Signed-off-by: Mabel Zhang --- docker/buoy_dockerhub/build.bash | 47 ++++++++ .../buoy_dockerhub/buoy_dockerhub/Dockerfile | 64 +++++++++++ docker/{ => buoy_dockerhub}/join.bash | 0 docker/buoy_dockerhub/run.bash | 100 ++++++++++++++++++ docker/buoy_dockerhub/run_no_nvidia.bash | 97 +++++++++++++++++ docker/{ => buoy_rocker}/build.bash | 0 .../buoy_rocker}/Dockerfile | 0 docker/buoy_rocker/join.bash | 26 +++++ docker/{ => buoy_rocker}/run.bash | 0 9 files changed, 334 insertions(+) create mode 100755 docker/buoy_dockerhub/build.bash create mode 100644 docker/buoy_dockerhub/buoy_dockerhub/Dockerfile rename docker/{ => buoy_dockerhub}/join.bash (100%) create mode 100755 docker/buoy_dockerhub/run.bash create mode 100755 docker/buoy_dockerhub/run_no_nvidia.bash rename docker/{ => buoy_rocker}/build.bash (100%) rename docker/{buoy => buoy_rocker/buoy_rocker}/Dockerfile (100%) create mode 100755 docker/buoy_rocker/join.bash rename docker/{ => buoy_rocker}/run.bash (100%) diff --git a/docker/buoy_dockerhub/build.bash b/docker/buoy_dockerhub/build.bash new file mode 100755 index 00000000..b0e06c3d --- /dev/null +++ b/docker/buoy_dockerhub/build.bash @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +# +# Copyright (C) 2022 Open Source Robotics Foundation, Inc. and Monterey Bay Aquarium Research Institute +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# + +# Builds a Docker image. + +if [ $# -lt 1 ] +then + echo "Usage: $0 " + exit 1 +fi + +# get path to current directory +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +if [ ! -d $DIR/$1 ] +then + echo "image-name must be a directory in the same folder as this script" + exit 2 +fi + +user_id=$(id -u) +image_name=$(basename $1) +#image_plus_tag=$image_name:$(export LC_ALL=C; date +%Y_%m_%d_%H%M) +image_plus_tag=$image_name:latest + +docker build --rm -t $image_plus_tag --build-arg user_id=$user_id -f "$DIR/$image_name/Dockerfile" . +#docker tag $image_plus_tag $image_name:latest + +echo "Built $image_plus_tag" +echo "To run:" +echo "./run.bash [-d|s] $image_name:latest" diff --git a/docker/buoy_dockerhub/buoy_dockerhub/Dockerfile b/docker/buoy_dockerhub/buoy_dockerhub/Dockerfile new file mode 100644 index 00000000..17b06043 --- /dev/null +++ b/docker/buoy_dockerhub/buoy_dockerhub/Dockerfile @@ -0,0 +1,64 @@ +FROM ros:humble-ros-base +ENV DEBIAN_FRONTEND=noninteractive + +# Necessary tools +RUN apt update \ + && apt install -y \ + apt-utils \ + vim \ + wget + +# Garden only has nightlies for now +RUN /bin/sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list' \ + && /bin/sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-nightly `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-nightly.list' \ + && /bin/sh -c 'wget http://packages.osrfoundation.org/gazebo.key -O - | apt-key add -' \ + && apt update \ + && apt install -y \ + ros-humble-rmw-cyclonedds-cpp \ + gz-garden \ + && apt clean + +# For timing in tests, need to use cyclonedds for ROS 2 rather than default +# rmw provider +ENV RMW_IMPLEMENTATION rmw_cyclonedds_cpp +# Using non-official Gazebo + ROS combination, set it explicitly +ENV GZ_VERSION garden + +# Add a user with the same user_id as the user outside the container +# Requires a docker build argument `user_id` +ARG user_id +ENV USERNAME developer +RUN useradd -U --uid ${user_id} -ms /bin/bash $USERNAME \ + && echo "$USERNAME:$USERNAME" | chpasswd \ + && adduser $USERNAME sudo \ + && echo "$USERNAME ALL=NOPASSWD: ALL" >> /etc/sudoers.d/$USERNAME + +# Commands below run as the developer user +USER $USERNAME + +# When running a container start in the developer's home folder +WORKDIR /home/$USERNAME + +# Create project directory and import packages +ENV BUOY_WS /home/$USERNAME/buoy_ws +RUN mkdir -p ${BUOY_WS}/src \ + && cd ${BUOY_WS}/src/ \ + && wget https://raw.githubusercontent.com/osrf/buoy_entrypoint/main/buoy_all.yaml \ + && vcs import < buoy_all.yaml + +# Install rosdep dependencies +RUN sudo apt update \ + && cd ${BUOY_WS} \ + && rosdep update \ + && rosdep install --from-paths src --ignore-src -r -y -i \ + && sudo rm -rf /var/lib/apt/lists/* \ + && sudo apt clean + +# Build the project +RUN /bin/bash -c 'source /opt/ros/${ROS_DISTRO}/setup.bash \ + && cd ${BUOY_WS} \ + && colcon build' + +# TODO: Add a run script under home/$USERNAME/run_simulation.sh to execute ros2 launch + +ENTRYPOINT ["/bin/bash" , "-c" , "source ${BUOY_WS}/install/setup.bash && /bin/bash"] diff --git a/docker/join.bash b/docker/buoy_dockerhub/join.bash similarity index 100% rename from docker/join.bash rename to docker/buoy_dockerhub/join.bash diff --git a/docker/buoy_dockerhub/run.bash b/docker/buoy_dockerhub/run.bash new file mode 100755 index 00000000..c1bcf0e1 --- /dev/null +++ b/docker/buoy_dockerhub/run.bash @@ -0,0 +1,100 @@ +#!/usr/bin/env bash + +# +# Copyright (C) 2023 Open Source Robotics Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# + +# Runs a docker container with the image created by build.bash +# Requires: +# docker +# nvidia-docker +# an X server +# Optional: +# A joystick mounted to /dev/input/js0 or /dev/input/js1 + +if [ $# -lt 1 ] +then + echo "Usage: $0 [ ...]" + exit 1 +fi + +IMG=$(basename $1) + +ARGS=("$@") +WORKSPACES=("${ARGS[@]:1}") + +# Make sure processes in the container can connect to the x server +# Necessary so gazebo can create a context for OpenGL rendering (even headless) +XAUTH=/tmp/.docker.xauth +if [ ! -f $XAUTH ] +then + xauth_list=$(xauth nlist $DISPLAY | sed -e 's/^..../ffff/') + if [ ! -z "$xauth_list" ] + then + echo $xauth_list | xauth -f $XAUTH nmerge - + else + touch $XAUTH + fi + chmod a+r $XAUTH +fi + +DOCKER_OPTS= + +# Share your vim settings. +VIMRC=~/.vimrc +if [ -f $VIMRC ] +then + DOCKER_OPTS="$DOCKER_OPTS -v $VIMRC:/home/developer/.vimrc:ro" +fi + +# Mabel: Share your custom terminal setup commands +GITCONFIG=~/.gitconfig +DOCKER_OPTS="$DOCKER_OPTS -v $GITCONFIG:/home/developer/.gitconfig:ro" + +for WS_DIR in ${WORKSPACES[@]} +do + WS_DIRNAME=$(basename $WS_DIR) + if [ ! -d $WS_DIR/src ] + then + echo "Other! $WS_DIR" + DOCKER_OPTS="$DOCKER_OPTS -v $WS_DIR:/home/developer/other/$WS_DIRNAME" + else + echo "Workspace! $WS_DIR" + DOCKER_OPTS="$DOCKER_OPTS -v $WS_DIR:/home/developer/workspaces/$WS_DIRNAME" + fi +done + +# Mount extra volumes if needed. +# E.g.: +# -v "/opt/sublime_text:/opt/sublime_text" \ + +# --ipc=host and --network=host are needed for no-NVIDIA Dockerfile to work +docker run -it \ + -e DISPLAY \ + -e QT_X11_NO_MITSHM=1 \ + -e XAUTHORITY=$XAUTH \ + -v "$XAUTH:$XAUTH" \ + -v "/tmp/.X11-unix:/tmp/.X11-unix" \ + -v "/etc/localtime:/etc/localtime:ro" \ + -v "/dev/input:/dev/input" \ + --privileged \ + --rm \ + --runtime=nvidia \ + --security-opt seccomp=unconfined \ + --ipc=host \ + --network=host \ + $DOCKER_OPTS \ + $IMG diff --git a/docker/buoy_dockerhub/run_no_nvidia.bash b/docker/buoy_dockerhub/run_no_nvidia.bash new file mode 100755 index 00000000..e283217d --- /dev/null +++ b/docker/buoy_dockerhub/run_no_nvidia.bash @@ -0,0 +1,97 @@ +#!/usr/bin/env bash + +# +# Copyright (C) 2023 Open Source Robotics Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# + +# Runs a docker container with the image created by build.bash +# Requires: +# docker +# an X server +# Optional: +# A joystick mounted to /dev/input/js0 or /dev/input/js1 + +if [ $# -lt 1 ] +then + echo "Usage: $0 [ ...]" + exit 1 +fi + +IMG=$(basename $1) + +ARGS=("$@") +WORKSPACES=("${ARGS[@]:1}") + +# Make sure processes in the container can connect to the x server +# Necessary so gazebo can create a context for OpenGL rendering (even headless) +XAUTH=/tmp/.docker.xauth +if [ ! -f $XAUTH ] +then + xauth_list=$(xauth nlist :0 | sed -e 's/^..../ffff/') + if [ ! -z "$xauth_list" ] + then + echo $xauth_list | xauth -f $XAUTH nmerge - + else + touch $XAUTH + fi + chmod a+r $XAUTH +fi + +DOCKER_OPTS= + +# Share your vim settings. +VIMRC=~/.vimrc +if [ -f $VIMRC ] +then + DOCKER_OPTS="$DOCKER_OPTS -v $VIMRC:/home/developer/.vimrc:ro" +fi + +# Mabel: Share your custom terminal setup commands +GITCONFIG=~/.gitconfig +DOCKER_OPTS="$DOCKER_OPTS -v $GITCONFIG:/home/developer/.gitconfig:ro" + +for WS_DIR in ${WORKSPACES[@]} +do + WS_DIRNAME=$(basename $WS_DIR) + if [ ! -d $WS_DIR/src ] + then + echo "Other! $WS_DIR" + DOCKER_OPTS="$DOCKER_OPTS -v $WS_DIR:/home/developer/other/$WS_DIRNAME" + else + echo "Workspace! $WS_DIR" + DOCKER_OPTS="$DOCKER_OPTS -v $WS_DIR:/home/developer/workspaces/$WS_DIRNAME" + fi +done + +# Mount extra volumes if needed. +# E.g.: +# -v "/opt/sublime_text:/opt/sublime_text" \ + +docker run -it \ + -e DISPLAY \ + -v "/tmp/.X11-unix:/tmp/.X11-unix" \ + -v "/etc/localtime:/etc/localtime:ro" \ + -v "/dev/input:/dev/input" \ + --rm \ + --security-opt seccomp=unconfined \ + --ipc=host \ + --network=host \ + $DOCKER_OPTS \ + $IMG + #--privileged \ + #-e QT_X11_NO_MITSHM=1 \ + #-e XAUTHORITY=$XAUTH \ + #-v "$XAUTH:$XAUTH" \ diff --git a/docker/build.bash b/docker/buoy_rocker/build.bash similarity index 100% rename from docker/build.bash rename to docker/buoy_rocker/build.bash diff --git a/docker/buoy/Dockerfile b/docker/buoy_rocker/buoy_rocker/Dockerfile similarity index 100% rename from docker/buoy/Dockerfile rename to docker/buoy_rocker/buoy_rocker/Dockerfile diff --git a/docker/buoy_rocker/join.bash b/docker/buoy_rocker/join.bash new file mode 100755 index 00000000..42322593 --- /dev/null +++ b/docker/buoy_rocker/join.bash @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +# +# Copyright (C) 2022 Open Source Robotics Foundation, Inc. and Monterey Bay Aquarium Research Institute +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# Typical usage: ./join.bash +# + +CONTAINER_ID=$1 + +xhost + +docker exec --privileged -e DISPLAY=${DISPLAY} -e LINES=`tput lines` -it ${CONTAINER_ID} bash +xhost - diff --git a/docker/run.bash b/docker/buoy_rocker/run.bash similarity index 100% rename from docker/run.bash rename to docker/buoy_rocker/run.bash From ffe45804f590540962347b069e8e666a2592249d Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Thu, 9 Mar 2023 18:31:22 -0500 Subject: [PATCH 02/12] modify existing Dockerfile instead of creating another Signed-off-by: Mabel Zhang --- docker/{buoy_rocker => }/build.bash | 0 .../buoy_dockerhub => buoy}/Dockerfile | 0 docker/buoy_dockerhub/build.bash | 47 ------------------- docker/buoy_rocker/buoy_rocker/Dockerfile | 45 ------------------ docker/buoy_rocker/join.bash | 26 ---------- docker/{buoy_dockerhub => }/join.bash | 0 docker/{buoy_dockerhub => }/run.bash | 0 .../{buoy_dockerhub => }/run_no_nvidia.bash | 0 .../{buoy_rocker/run.bash => run_rocker.bash} | 0 9 files changed, 118 deletions(-) rename docker/{buoy_rocker => }/build.bash (100%) rename docker/{buoy_dockerhub/buoy_dockerhub => buoy}/Dockerfile (100%) delete mode 100755 docker/buoy_dockerhub/build.bash delete mode 100644 docker/buoy_rocker/buoy_rocker/Dockerfile delete mode 100755 docker/buoy_rocker/join.bash rename docker/{buoy_dockerhub => }/join.bash (100%) rename docker/{buoy_dockerhub => }/run.bash (100%) rename docker/{buoy_dockerhub => }/run_no_nvidia.bash (100%) rename docker/{buoy_rocker/run.bash => run_rocker.bash} (100%) diff --git a/docker/buoy_rocker/build.bash b/docker/build.bash similarity index 100% rename from docker/buoy_rocker/build.bash rename to docker/build.bash diff --git a/docker/buoy_dockerhub/buoy_dockerhub/Dockerfile b/docker/buoy/Dockerfile similarity index 100% rename from docker/buoy_dockerhub/buoy_dockerhub/Dockerfile rename to docker/buoy/Dockerfile diff --git a/docker/buoy_dockerhub/build.bash b/docker/buoy_dockerhub/build.bash deleted file mode 100755 index b0e06c3d..00000000 --- a/docker/buoy_dockerhub/build.bash +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env bash - -# -# Copyright (C) 2022 Open Source Robotics Foundation, Inc. and Monterey Bay Aquarium Research Institute -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# - -# Builds a Docker image. - -if [ $# -lt 1 ] -then - echo "Usage: $0 " - exit 1 -fi - -# get path to current directory -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -if [ ! -d $DIR/$1 ] -then - echo "image-name must be a directory in the same folder as this script" - exit 2 -fi - -user_id=$(id -u) -image_name=$(basename $1) -#image_plus_tag=$image_name:$(export LC_ALL=C; date +%Y_%m_%d_%H%M) -image_plus_tag=$image_name:latest - -docker build --rm -t $image_plus_tag --build-arg user_id=$user_id -f "$DIR/$image_name/Dockerfile" . -#docker tag $image_plus_tag $image_name:latest - -echo "Built $image_plus_tag" -echo "To run:" -echo "./run.bash [-d|s] $image_name:latest" diff --git a/docker/buoy_rocker/buoy_rocker/Dockerfile b/docker/buoy_rocker/buoy_rocker/Dockerfile deleted file mode 100644 index 43abcd22..00000000 --- a/docker/buoy_rocker/buoy_rocker/Dockerfile +++ /dev/null @@ -1,45 +0,0 @@ -FROM ros:humble-ros-base -ENV DEBIAN_FRONTEND=noninteractive - -# Need to use cyclonedds rather than default rmw provider -RUN apt update \ - && apt install -y \ - ros-humble-rmw-cyclonedds-cpp -ENV RMW_IMPLEMENTATION rmw_cyclonedds_cpp - -# Necessary tools -RUN apt update \ - && apt install -y \ - apt-utils \ - wget - -# Using non-official Gazebo + ROS combination, set it explicitly -ENV GZ_VERSION garden - -# Garden only has nightlies for now -RUN /bin/sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list' \ - && /bin/sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-nightly `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-nightly.list' \ - && /bin/sh -c 'wget http://packages.osrfoundation.org/gazebo.key -O - | apt-key add -' \ - && apt-get update \ - && apt-get install -y gz-garden - -# Create project directory and import packages -RUN mkdir -p /tmp/buoy_ws/src \ - && cd /tmp/buoy_ws/src/ \ - && wget https://raw.githubusercontent.com/osrf/buoy_entrypoint/main/buoy_all.yaml \ - && vcs import < buoy_all.yaml - -# Install rosdep dependencies - this installs Gazebo and other packages -RUN sudo apt update \ - && cd /tmp/buoy_ws \ - && rosdep update \ - && rosdep install --from-paths src --ignore-src -r -y -i \ - && rm -rf /var/lib/apt/lists/* \ - && apt clean - -# Build the project -RUN /bin/bash -c 'source /opt/ros/${ROS_DISTRO}/setup.bash \ - && cd /tmp/buoy_ws \ - && colcon build' - -ENTRYPOINT ["/bin/bash" , "-c" , "source /tmp/buoy_ws/install/setup.bash && /bin/bash"] diff --git a/docker/buoy_rocker/join.bash b/docker/buoy_rocker/join.bash deleted file mode 100755 index 42322593..00000000 --- a/docker/buoy_rocker/join.bash +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -# -# Copyright (C) 2022 Open Source Robotics Foundation, Inc. and Monterey Bay Aquarium Research Institute -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# -# Typical usage: ./join.bash -# - -CONTAINER_ID=$1 - -xhost + -docker exec --privileged -e DISPLAY=${DISPLAY} -e LINES=`tput lines` -it ${CONTAINER_ID} bash -xhost - diff --git a/docker/buoy_dockerhub/join.bash b/docker/join.bash similarity index 100% rename from docker/buoy_dockerhub/join.bash rename to docker/join.bash diff --git a/docker/buoy_dockerhub/run.bash b/docker/run.bash similarity index 100% rename from docker/buoy_dockerhub/run.bash rename to docker/run.bash diff --git a/docker/buoy_dockerhub/run_no_nvidia.bash b/docker/run_no_nvidia.bash similarity index 100% rename from docker/buoy_dockerhub/run_no_nvidia.bash rename to docker/run_no_nvidia.bash diff --git a/docker/buoy_rocker/run.bash b/docker/run_rocker.bash similarity index 100% rename from docker/buoy_rocker/run.bash rename to docker/run_rocker.bash From 7ad0f3d42fbfb4a468b44db4b7e4b16b02a5cee3 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Thu, 9 Mar 2023 19:11:24 -0500 Subject: [PATCH 03/12] fix user_id Signed-off-by: Mabel Zhang --- docker/build.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/build.bash b/docker/build.bash index aa7da460..c18ab8c5 100755 --- a/docker/build.bash +++ b/docker/build.bash @@ -34,11 +34,11 @@ then exit 2 fi -user=$(echo $USERNAME) +user_id=$(id -u) image_name=$(basename $1) image_plus_tag=$image_name:$(export LC_ALL=C; date +%Y_%m_%d_%H%M) -docker build --rm -t $image_plus_tag --build-arg USERNAME="$user" -f "$DIR/$image_name/Dockerfile" . +docker build --rm -t $image_plus_tag --build-arg user_id=$user_id -f "$DIR/$image_name/Dockerfile" . docker tag $image_plus_tag $image_name:latest echo "Built $image_plus_tag and tagged as $image_name:latest" From 4efe609a7a8b4a14531b97a2d0997df8e50b229a Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Thu, 9 Mar 2023 19:16:57 -0500 Subject: [PATCH 04/12] add quick access scripts Signed-off-by: Mabel Zhang --- docker/buoy/Dockerfile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docker/buoy/Dockerfile b/docker/buoy/Dockerfile index 17b06043..e15e803f 100644 --- a/docker/buoy/Dockerfile +++ b/docker/buoy/Dockerfile @@ -59,6 +59,16 @@ RUN /bin/bash -c 'source /opt/ros/${ROS_DISTRO}/setup.bash \ && cd ${BUOY_WS} \ && colcon build' -# TODO: Add a run script under home/$USERNAME/run_simulation.sh to execute ros2 launch +# Add quick access scripts +ENV SETUP_SH /home/$USERNAME/setup.bash +RUN touch ${SETUP_SH} \ + && chmod 755 ${SETUP_SH} \ + && echo ". ${BUOY_WS}/install/setup.bash" >> ${SETUP_SH} +ENV RUN_SH /home/$USERNAME/run_simulation.bash +RUN touch ${RUN_SH} \ + && chmod 755 ${RUN_SH} \ + && echo ". ${BUOY_WS}/install/setup.bash" >> ${RUN_SH} \ + && echo "ros2 launch buoy_gazebo mbari_wec.launch.py" >> ${RUN_SH} +# Start the container at a bash prompt ENTRYPOINT ["/bin/bash" , "-c" , "source ${BUOY_WS}/install/setup.bash && /bin/bash"] From 5261ed7a21f9eacb388bd70ae17c4a8df7b23416 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Thu, 9 Mar 2023 19:18:19 -0500 Subject: [PATCH 05/12] update copyright Signed-off-by: Mabel Zhang --- docker/run.bash | 2 +- docker/run_no_nvidia.bash | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/run.bash b/docker/run.bash index c1bcf0e1..623db346 100755 --- a/docker/run.bash +++ b/docker/run.bash @@ -1,7 +1,7 @@ #!/usr/bin/env bash # -# Copyright (C) 2023 Open Source Robotics Foundation +# Copyright (C) 2023 Open Source Robotics Foundation, Inc. and Monterey Bay Aquarium Research Institute # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/docker/run_no_nvidia.bash b/docker/run_no_nvidia.bash index e283217d..cfab5a5d 100755 --- a/docker/run_no_nvidia.bash +++ b/docker/run_no_nvidia.bash @@ -1,7 +1,7 @@ #!/usr/bin/env bash # -# Copyright (C) 2023 Open Source Robotics Foundation +# Copyright (C) 2023 Open Source Robotics Foundation, Inc. and Monterey Bay Aquarium Research Institute # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From 0f2438a648dc78e72b95759d1a53cc0c756db4b8 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Thu, 9 Mar 2023 19:19:52 -0500 Subject: [PATCH 06/12] comment Signed-off-by: Mabel Zhang --- docker/run_no_nvidia.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/run_no_nvidia.bash b/docker/run_no_nvidia.bash index cfab5a5d..a4c4736b 100755 --- a/docker/run_no_nvidia.bash +++ b/docker/run_no_nvidia.bash @@ -59,7 +59,7 @@ then DOCKER_OPTS="$DOCKER_OPTS -v $VIMRC:/home/developer/.vimrc:ro" fi -# Mabel: Share your custom terminal setup commands +# Share your custom terminal setup commands GITCONFIG=~/.gitconfig DOCKER_OPTS="$DOCKER_OPTS -v $GITCONFIG:/home/developer/.gitconfig:ro" From 034973517830fff1991c3ccd03d6df48115fb5df Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Thu, 9 Mar 2023 19:30:34 -0500 Subject: [PATCH 07/12] remove extra run file Signed-off-by: Mabel Zhang --- docker/build.bash | 8 ++-- docker/run_no_nvidia.bash | 97 --------------------------------------- 2 files changed, 5 insertions(+), 100 deletions(-) delete mode 100755 docker/run_no_nvidia.bash diff --git a/docker/build.bash b/docker/build.bash index c18ab8c5..f697c5c4 100755 --- a/docker/build.bash +++ b/docker/build.bash @@ -36,11 +36,13 @@ fi user_id=$(id -u) image_name=$(basename $1) -image_plus_tag=$image_name:$(export LC_ALL=C; date +%Y_%m_%d_%H%M) +# Remove timestamp tag to avoid too many tags +#image_plus_tag=$image_name:$(export LC_ALL=C; date +%Y_%m_%d_%H%M) +image_plus_tag=$image_name:latest docker build --rm -t $image_plus_tag --build-arg user_id=$user_id -f "$DIR/$image_name/Dockerfile" . -docker tag $image_plus_tag $image_name:latest +#docker tag $image_plus_tag $image_name:latest -echo "Built $image_plus_tag and tagged as $image_name:latest" +echo "Built $image_plus_tag" echo "To run:" echo "./run.bash [-d|s] $image_name:latest" diff --git a/docker/run_no_nvidia.bash b/docker/run_no_nvidia.bash deleted file mode 100755 index a4c4736b..00000000 --- a/docker/run_no_nvidia.bash +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env bash - -# -# Copyright (C) 2023 Open Source Robotics Foundation, Inc. and Monterey Bay Aquarium Research Institute -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# - -# Runs a docker container with the image created by build.bash -# Requires: -# docker -# an X server -# Optional: -# A joystick mounted to /dev/input/js0 or /dev/input/js1 - -if [ $# -lt 1 ] -then - echo "Usage: $0 [ ...]" - exit 1 -fi - -IMG=$(basename $1) - -ARGS=("$@") -WORKSPACES=("${ARGS[@]:1}") - -# Make sure processes in the container can connect to the x server -# Necessary so gazebo can create a context for OpenGL rendering (even headless) -XAUTH=/tmp/.docker.xauth -if [ ! -f $XAUTH ] -then - xauth_list=$(xauth nlist :0 | sed -e 's/^..../ffff/') - if [ ! -z "$xauth_list" ] - then - echo $xauth_list | xauth -f $XAUTH nmerge - - else - touch $XAUTH - fi - chmod a+r $XAUTH -fi - -DOCKER_OPTS= - -# Share your vim settings. -VIMRC=~/.vimrc -if [ -f $VIMRC ] -then - DOCKER_OPTS="$DOCKER_OPTS -v $VIMRC:/home/developer/.vimrc:ro" -fi - -# Share your custom terminal setup commands -GITCONFIG=~/.gitconfig -DOCKER_OPTS="$DOCKER_OPTS -v $GITCONFIG:/home/developer/.gitconfig:ro" - -for WS_DIR in ${WORKSPACES[@]} -do - WS_DIRNAME=$(basename $WS_DIR) - if [ ! -d $WS_DIR/src ] - then - echo "Other! $WS_DIR" - DOCKER_OPTS="$DOCKER_OPTS -v $WS_DIR:/home/developer/other/$WS_DIRNAME" - else - echo "Workspace! $WS_DIR" - DOCKER_OPTS="$DOCKER_OPTS -v $WS_DIR:/home/developer/workspaces/$WS_DIRNAME" - fi -done - -# Mount extra volumes if needed. -# E.g.: -# -v "/opt/sublime_text:/opt/sublime_text" \ - -docker run -it \ - -e DISPLAY \ - -v "/tmp/.X11-unix:/tmp/.X11-unix" \ - -v "/etc/localtime:/etc/localtime:ro" \ - -v "/dev/input:/dev/input" \ - --rm \ - --security-opt seccomp=unconfined \ - --ipc=host \ - --network=host \ - $DOCKER_OPTS \ - $IMG - #--privileged \ - #-e QT_X11_NO_MITSHM=1 \ - #-e XAUTHORITY=$XAUTH \ - #-v "$XAUTH:$XAUTH" \ From 975123b307536125abe3302eb067b1ceb561b5d4 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Thu, 9 Mar 2023 19:44:14 -0500 Subject: [PATCH 08/12] remove nvidia Signed-off-by: Mabel Zhang --- docker/run.bash | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docker/run.bash b/docker/run.bash index 623db346..92482bba 100755 --- a/docker/run.bash +++ b/docker/run.bash @@ -20,7 +20,6 @@ # Runs a docker container with the image created by build.bash # Requires: # docker -# nvidia-docker # an X server # Optional: # A joystick mounted to /dev/input/js0 or /dev/input/js1 @@ -31,6 +30,8 @@ then exit 1 fi +DOCKER_OPTS= + IMG=$(basename $1) ARGS=("$@") @@ -51,8 +52,6 @@ then chmod a+r $XAUTH fi -DOCKER_OPTS= - # Share your vim settings. VIMRC=~/.vimrc if [ -f $VIMRC ] @@ -82,6 +81,7 @@ done # -v "/opt/sublime_text:/opt/sublime_text" \ # --ipc=host and --network=host are needed for no-NVIDIA Dockerfile to work +# If need NVIDIA, add --runtime=nvidia docker run -it \ -e DISPLAY \ -e QT_X11_NO_MITSHM=1 \ @@ -92,7 +92,6 @@ docker run -it \ -v "/dev/input:/dev/input" \ --privileged \ --rm \ - --runtime=nvidia \ --security-opt seccomp=unconfined \ --ipc=host \ --network=host \ From 7ce87154b4c4748f2779a241793cfec96744c13d Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Wed, 15 Mar 2023 02:37:28 -0400 Subject: [PATCH 09/12] add NVIDIA base image and bash script option. Update README Signed-off-by: Mabel Zhang --- README.md | 76 +++--- docker/build.bash | 53 +++- docker/buoy/Dockerfile | 66 ++++- docker/nvidia_opengl_ubuntu22/Dockerfile | 63 +++++ .../NGC-DL-CONTAINER-LICENSE | 230 ++++++++++++++++++ docker/run.bash | 29 ++- 6 files changed, 461 insertions(+), 56 deletions(-) create mode 100644 docker/nvidia_opengl_ubuntu22/Dockerfile create mode 100644 docker/nvidia_opengl_ubuntu22/NGC-DL-CONTAINER-LICENSE diff --git a/README.md b/README.md index 46331b66..004c1c1a 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ See [gz-math Python Get Started tutorial](https://github.com/gazebosim/gz-math/b sudo apt install python3-vcstool python3-colcon-common-extensions python3-pip git wget ``` -##### Usage +##### Build 1. Create a workspace, for example: @@ -106,17 +106,6 @@ See [gz-math Python Get Started tutorial](https://github.com/gazebosim/gz-math/b colcon build ``` -##### Run - -1. In a new terminal, source the workspace - - `. ~/buoy_ws/install/setup.sh` - -1. Launch the simulation - - `ros2 launch buoy_gazebo mbari_wec.launch.py` - - ### Using docker ##### Requirements @@ -126,34 +115,37 @@ See [gz-math Python Get Started tutorial](https://github.com/gazebosim/gz-math/b 1. Complete the [Linux Postinstall steps](https://docs.docker.com/engine/install/linux-postinstall/) to allow you to manage Docker as a non-root user. -1. Install `rocker` by `sudo apt-get install python3-rocker`. - -##### Usage +##### Build 1. Clone the buoy_entrypoint repository to download the latest Dockerfile. - ``` - git clone https://github.com/osrf/buoy_entrypoint.git - cd ~/buoy_entrypoint/docker/ - ``` + ``` + git clone https://github.com/osrf/buoy_entrypoint.git + cd ~/buoy_entrypoint/docker/ + ``` 1. Build the docker image - ``` - ./build.bash buoy - ``` + If you have an NVIDIA graphics card + ``` + ./build.bash nvidia_opengl_ubuntu22 + ./build.bash buoy + ``` + Otherwise + ``` + ./build.bash buoy --no-nvidia + ``` 1. Run the container - ``` - ./run.bash [-d|s] buoy:latest - ``` - where `./run.bash` option: - * -d Use for development with host system volume mount - * -s Simulation purposes only - - The development use case enables to either use host system home directory for user's custom workspace, or a fresh clone inside the docker container. If using host system workspace, follow the [On Host System](#on-host-system) instructions to build and run the project in the container. - Regardless the script option, project source files can be found in `/tmp/buoy_ws/' in the container. Note that any changes to files in the container will have limited scope. + If you have an NVIDIA graphics card + ``` + ./run.bash buoy + ``` + Otherwise + ``` + ./run.bash buoy --no-nvidia + ``` 1. To have another window running the same docker container, run this command in a new terminal: @@ -161,12 +153,26 @@ See [gz-math Python Get Started tutorial](https://github.com/gazebosim/gz-math/b ./join.bash buoy_latest_runtime ``` -> The build and run bash scripts are a wrapper around rocker, checkout its [documentation](https://github.com/osrf/rocker) for additional options. +##### Quick start -##### Run +Quick start scripts are provided in the home directory: -Inside the docker container, run: +This sources the compiled workspace: +``` +./setup.bash +``` +This sources the compiled workspace and launches the simulation: ``` -gz sim mbari_wec.sdf -r +./run_simulation.bash ``` + +## Run + +1. In a new terminal (whether on host machine or in Docker container), source the workspace + + `. ~/buoy_ws/install/setup.sh` + +1. Launch the simulation + + `ros2 launch buoy_gazebo mbari_wec.launch.py` diff --git a/docker/build.bash b/docker/build.bash index f697c5c4..9bc786f3 100755 --- a/docker/build.bash +++ b/docker/build.bash @@ -19,15 +19,47 @@ # Builds a Docker image. -if [ $# -lt 1 ] +# No arg +if [ $# -eq 0 ] then - echo "Usage: $0 " + echo "Usage: $0 directory-name" exit 1 fi -# get path to current directory +# Get path to current directory DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# Default base image, defined in nvidia_opengl_ubuntu22/Dockerfile + +# Ubuntu with nvidia-docker2 beta opengl support, i.e. +# nvidia/opengl:1.0-glvnd-devel-ubuntu22.04, doesn't exist for Ubuntu 22.04 +# at time of writing. Use homebrewed version in ./nvidia_opengl_ubuntu22/. +# https://hub.docker.com/r/nvidia/opengl +base="nvidia_opengl_ubuntu22:latest" +image_suffix="_nvidia" + +# Parse and remove args +PARAMS="" +while (( "$#" )); do + case "$1" in + --no-nvidia) + base="ubuntu:jammy" + image_suffix="_no_nvidia" + shift + ;; + -*|--*=) # unsupported flags + echo "Error: Unsupported flag $1" >&2 + exit 1 + ;; + *) # preserve positional arguments + PARAMS="$PARAMS $1" + shift + ;; + esac +done +# set positional arguments in their proper place +eval set -- "$PARAMS" + if [ ! -d $DIR/$1 ] then echo "image-name must be a directory in the same folder as this script" @@ -36,13 +68,14 @@ fi user_id=$(id -u) image_name=$(basename $1) -# Remove timestamp tag to avoid too many tags -#image_plus_tag=$image_name:$(export LC_ALL=C; date +%Y_%m_%d_%H%M) +#image_plus_tag=$image_name:$(date +%Y_%b_%d_%H%M) +# Tag as latest so don't have a dozen uniquely timestamped images hanging around image_plus_tag=$image_name:latest -docker build --rm -t $image_plus_tag --build-arg user_id=$user_id -f "$DIR/$image_name/Dockerfile" . -#docker tag $image_plus_tag $image_name:latest - +echo "Building $image_name with base image $base" +docker build --rm -t $image_plus_tag --build-arg base=$base --build-arg user_id=$user_id $DIR/$image_name echo "Built $image_plus_tag" -echo "To run:" -echo "./run.bash [-d|s] $image_name:latest" + +# Extra tag in case you have both the NVIDIA and no-NVIDIA images +docker tag $image_plus_tag $image_name$image_suffix:latest +echo "Tagged as $image_name$image_suffix:latest" diff --git a/docker/buoy/Dockerfile b/docker/buoy/Dockerfile index e15e803f..180cc440 100644 --- a/docker/buoy/Dockerfile +++ b/docker/buoy/Dockerfile @@ -1,19 +1,68 @@ -FROM ros:humble-ros-base +#!/usr/bin/env bash + +# +# Copyright (C) 2023 Open Source Robotics Foundation, Inc. and Monterey Bay Aquarium Research Institute +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# + +ARG base +FROM ${base} + ENV DEBIAN_FRONTEND=noninteractive # Necessary tools RUN apt update \ && apt install -y \ apt-utils \ + build-essential \ + cmake \ + cppcheck \ + curl \ + doxygen \ + gdb \ + git \ + gnupg2 \ + locales \ + lsb-release \ + python3-pip \ + sudo \ vim \ - wget + wget \ + && apt clean + +# Set Locale for ROS 2 +RUN locale-gen en_US en_US.UTF-8 && \ + update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 && \ + export LANG=en_US.UTF-8 + +# Add ROS 2 apt repository +# Set up keys +RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg +# Set up sources.list +RUN /bin/sh -c 'echo "deb [arch=amd64,arm64] http://packages.ros.org/ros2/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list' \ + && /bin/sh -c 'echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null' -# Garden only has nightlies for now -RUN /bin/sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list' \ - && /bin/sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-nightly `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-nightly.list' \ - && /bin/sh -c 'wget http://packages.osrfoundation.org/gazebo.key -O - | apt-key add -' \ +# Set up Gazebo keys and install +RUN /bin/sh -c 'wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg' \ + && /bin/sh -c 'echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null' \ && apt update \ && apt install -y \ + python3-rosdep \ + python3-vcstool \ + python3-colcon-common-extensions \ + ros-humble-desktop \ ros-humble-rmw-cyclonedds-cpp \ gz-garden \ && apt clean @@ -49,13 +98,14 @@ RUN mkdir -p ${BUOY_WS}/src \ # Install rosdep dependencies RUN sudo apt update \ && cd ${BUOY_WS} \ + && sudo rosdep init \ && rosdep update \ - && rosdep install --from-paths src --ignore-src -r -y -i \ + && rosdep install --from-paths src --ignore-src -r -y -i --rosdistro humble \ && sudo rm -rf /var/lib/apt/lists/* \ && sudo apt clean # Build the project -RUN /bin/bash -c 'source /opt/ros/${ROS_DISTRO}/setup.bash \ +RUN /bin/bash -c 'source /opt/ros/humble/setup.bash \ && cd ${BUOY_WS} \ && colcon build' diff --git a/docker/nvidia_opengl_ubuntu22/Dockerfile b/docker/nvidia_opengl_ubuntu22/Dockerfile new file mode 100644 index 00000000..19a24d1f --- /dev/null +++ b/docker/nvidia_opengl_ubuntu22/Dockerfile @@ -0,0 +1,63 @@ +# +# Copyright (C) 2023 Open Source Robotics Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Since nvidia/opengl:*-glvnd-devel-ubuntu22.04 is not available yet, this +# builds an equivalent, to run X server in an Ubuntu 20.04 Docker image. +# https://hub.docker.com/r/nvidia/opengl + +FROM ubuntu:jammy + +##### +# Following lines are copied from +# https://gitlab.com/nvidia/container-images/opengl/-/blob/ubuntu18.04/base/Dockerfile +# and removed :i386 packages (not found) +RUN dpkg --add-architecture i386 \ + && apt-get update \ + && apt-get install -y --no-install-recommends \ + libxau6 libxau6:i386 \ + libxdmcp6 libxdmcp6:i386 \ + libxcb1 libxcb1:i386 \ + libxext6 libxext6:i386 \ + libx11-6 libx11-6:i386 && \ + rm -rf /var/lib/apt/lists/* + +# nvidia-container-runtime +ENV NVIDIA_VISIBLE_DEVICES \ + ${NVIDIA_VISIBLE_DEVICES:-all} +ENV NVIDIA_DRIVER_CAPABILITIES \ + ${NVIDIA_DRIVER_CAPABILITIES:+$NVIDIA_DRIVER_CAPABILITIES,}graphics,compat32,utility + +RUN echo "/usr/local/nvidia/lib" >> /etc/ld.so.conf.d/nvidia.conf && \ + echo "/usr/local/nvidia/lib64" >> /etc/ld.so.conf.d/nvidia.conf + +# https://gitlab.com/nvidia/container-images/opengl/-/blob/ubuntu20.04/NGC-DL-CONTAINER-LICENSE +COPY NGC-DL-CONTAINER-LICENSE / + +# Required for non-glvnd setups. +ENV LD_LIBRARY_PATH /usr/lib/x86_64-linux-gnu:/usr/lib/i386-linux-gnu${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}:/usr/local/nvidia/lib:/usr/local/nvidia/lib64 + +##### +# Copied from +# https://gitlab.com/nvidia/container-images/opengl/blob/ubuntu20.04/glvnd/devel/Dockerfile +# and removed :i386 packages (not found) +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + pkg-config \ + libglvnd-dev libglvnd-dev:i386 \ + libgl1-mesa-dev libgl1-mesa-dev:i386 \ + libegl1-mesa-dev libegl1-mesa-dev:i386 \ + libgles2-mesa-dev libgles2-mesa-dev:i386 && \ + rm -rf /var/lib/apt/lists/* diff --git a/docker/nvidia_opengl_ubuntu22/NGC-DL-CONTAINER-LICENSE b/docker/nvidia_opengl_ubuntu22/NGC-DL-CONTAINER-LICENSE new file mode 100644 index 00000000..be9eb755 --- /dev/null +++ b/docker/nvidia_opengl_ubuntu22/NGC-DL-CONTAINER-LICENSE @@ -0,0 +1,230 @@ +NVIDIA DEEP LEARNING CONTAINER LICENSE + +This license is a legal agreement between you and NVIDIA Corporation ("NVIDIA") and governs the use +of the NVIDIA container and all its contents (“CONTAINER”). + +This license can be accepted only by an adult of legal age of majority in the country in which the +CONTAINER is used. If you are under the legal age of majority, you must ask your parent or legal +guardian to consent to this license. If you are entering this license on behalf of a company or +other legal entity, you represent that you have legal authority and “you” will mean the entity you +represent. + +By using the CONTAINER, you affirm that you have reached the legal age of majority, you accept the +terms of this license, and you take legal and financial responsibility for the actions of your +permitted users. + +You agree to use the CONTAINER only for purposes that are permitted by (a) this license, and (b) any +applicable law, regulation or generally accepted practices or guidelines in the relevant +jurisdictions. + +1. LICENSE. Subject to the terms of this license, NVIDIA hereby grants you a non-exclusive, +non-transferable license, without the right to sublicense (except as expressly provided in this +license) to: + +a. Install and use copies of the CONTAINER, and modify and create derivative works of samples or +example source code delivered in the CONTAINER (if applicable), to develop and test services and +applications, + +b. Deploy the CONTAINER on infrastructure you own or lease to offer a service to third parties, +without distributing the CONTAINER or exposing the NVIDIA APIs in the CONTAINER directly to such +service users, and + +c. Develop and extend the CONTAINER to create a Compatible (as defined below) derived CONTAINER that +includes the entire CONTAINER plus other software with primary functionality, to develop and compile +applications, and distribute such derived CONTAINER to run applications, subject to the distribution +requirements indicated in this license. As used in this section, “Compatible” means that extensions +to the CONTAINER must not adversely affect the functionality of the other components in the +CONTAINER. + +2. DISTRIBUTION REQUIREMENTS. For purposes of this Section 2, the term “distribution” also means the +deployment of CONTAINERS in a service or an application for third parties to access over the +internet. These are the distribution requirements for you to exercise the grants above: + +a. A service or an application must have material additional functionality, beyond the included +portions of the CONTAINER. + +b. The following notice shall be included in modifications and derivative works of source code +distributed: “This software contains source code provided by NVIDIA Corporation.” + +c. You agree to distribute the CONTAINER subject to the terms at least as protective as the terms of +this license, including (without limitation) terms relating to the license grant, license +restrictions and protection of NVIDIA’s intellectual property rights. Additionally, you agree that +you will protect the privacy, security and legal rights of your application users. + +d. You agree to notify NVIDIA in writing of any known or suspected distribution or use of the +CONTAINER not in compliance with the requirements of this license, and to enforce the terms of your +agreements with respect to the distributed CONTAINER. + +3. AUTHORIZED USERS. You may allow employees and contractors of your entity or of your +subsidiary(ies) to access and use the CONTAINER from your secure network to perform work on your +behalf. If you are an academic institution you may allow users enrolled or employed by the academic +institution to access and use the CONTAINER from your secure network. You are responsible for the +compliance with the terms of this license by your authorized users. + +4. LIMITATIONS. Your license to use the CONTAINER is restricted as follows: + +a. The CONTAINER is licensed for you to develop services and applications only for their use in +systems with NVIDIA GPUs. + +b. You may not reverse engineer, decompile or disassemble, or remove copyright or other proprietary +notices from any portion of the CONTAINER or copies of the CONTAINER. + +c. Except as expressly provided in this license, you may not copy, sell, rent, sublicense, transfer, +distribute, modify, or create derivative works of any portion of the CONTAINER. For clarity, you may +not distribute or sublicense the CONTAINER as a stand-alone product. + +d. Unless you have an agreement with NVIDIA for this purpose, you may not indicate that a service or +an application created with the CONTAINER is sponsored or endorsed by NVIDIA. + +e. You may not bypass, disable, or circumvent any technical limitation, encryption, security, +digital rights management or authentication mechanism in the CONTAINER. + +f. You may not replace any NVIDIA software components in the CONTAINER that are governed by this +license with other software that implements NVIDIA APIs. + +g. You may not use the CONTAINER in any manner that would cause it to become subject to an open +source software license. As examples, licenses that require as a condition of use, modification, +and/or distribution that the CONTAINER be: (i) disclosed or distributed in source code form; (ii) +licensed for the purpose of making derivative works; or (iii) redistributable at no charge. + +h. Unless you have an agreement with NVIDIA for this purpose, you may not use the CONTAINER with any +system or application where the use or failure of the system or application can reasonably be +expected to threaten or result in personal injury, death, or catastrophic loss. Examples include use +in avionics, navigation, military, medical, life support or other life critical applications. NVIDIA +does not design, test or manufacture the CONTAINER for these critical uses and NVIDIA shall not be +liable to you or any third party, in whole or in part, for any claims or damages arising from such +uses. + +i. You agree to defend, indemnify and hold harmless NVIDIA and its affiliates, and their respective +employees, contractors, agents, officers and directors, from and against any and all claims, +damages, obligations, losses, liabilities, costs or debt, fines, restitutions and expenses +(including but not limited to attorney’s fees and costs incident to establishing the right of +indemnification) arising out of or related to your use of the CONTAINER outside of the scope of this +license, or not in compliance with its terms. + +5. UPDATES. NVIDIA may, at its option, make available patches, workarounds or other updates to this +CONTAINER. Unless the updates are provided with their separate governing terms, they are deemed part +of the CONTAINER licensed to you as provided in this license. You agree that the form and content of +the CONTAINER that NVIDIA provides may change without prior notice to you. While NVIDIA generally +maintains compatibility between versions, NVIDIA may in some cases make changes that introduce +incompatibilities in future versions of the CONTAINER. + +6. PRE-RELEASE VERSIONS. CONTAINER versions identified as alpha, beta, preview, early access or +otherwise as pre-release may not be fully functional, may contain errors or design flaws, and may +have reduced or different security, privacy, availability, and reliability standards relative to +commercial versions of NVIDIA software and materials. You may use a pre-release CONTAINER version at +your own risk, understanding that these versions are not intended for use in production or +business-critical systems. NVIDIA may choose not to make available a commercial version of any +pre-release CONTAINER. NVIDIA may also choose to abandon development and terminate the availability +of a pre-release CONTAINER at any time without liability. + +7. THIRD-PARTY COMPONENTS. The CONTAINER may include third-party components with separate legal +notices or terms as may be described in proprietary notices accompanying the CONTAINER. If and to +the extent there is a conflict between the terms in this license and the third-party license terms, +the third-party terms control only to the extent necessary to resolve the conflict. + +You acknowledge and agree that it is your sole responsibility to obtain any additional third-party +licenses required to make, have made, use, have used, sell, import, and offer for sale your products +or services that include or incorporate any third-party software and content relating to audio +and/or video encoders and decoders from, including but not limited to, Microsoft, Thomson, +Fraunhofer IIS, Sisvel S.p.A., MPEG-LA, and Coding Technologies. NVIDIA does not grant to you under +this license any necessary patent or other rights with respect to any audio and/or video encoders +and decoders. + +Subject to the other terms of this license, you may use the CONTAINER to develop and test +applications released under Open Source Initiative (OSI) approved open source software licenses. + +8. OWNERSHIP. + +8.1 NVIDIA reserves all rights, title and interest in and to the CONTAINER not expressly granted to +you under this license. NVIDIA and its suppliers hold all rights, title and interest in and to the +CONTAINER, including their respective intellectual property rights. The CONTAINER is copyrighted and +protected by the laws of the United States and other countries, and international treaty provisions. + +8.2 Subject to the rights of NVIDIA and its suppliers in the CONTAINER, you hold all rights, title +and interest in and to your services, applications and your derivative works of the sample source +code delivered in the CONTAINER including their respective intellectual property rights. + +9. FEEDBACK. You may, but are not obligated to, provide to NVIDIA suggestions, fixes, modifications, +feature requests or other feedback regarding the CONTAINER (“Feedback”). Feedback, even if +designated as confidential by you, shall not create any confidentiality obligation for NVIDIA. +NVIDIA and its designees have a perpetual, non-exclusive, worldwide, irrevocable license to use, +reproduce, publicly display, modify, create derivative works of, license, sublicense, and otherwise +distribute and exploit Feedback as NVIDIA sees fit without payment and without obligation or +restriction of any kind on account of intellectual property rights or otherwise. + +10. NO WARRANTIES. THE CONTAINER IS PROVIDED AS-IS. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE +LAW NVIDIA AND ITS AFFILIATES EXPRESSLY DISCLAIM ALL WARRANTIES OF ANY KIND OR NATURE, WHETHER +EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, +NON-INFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE. NVIDIA DOES NOT WARRANT THAT THE CONTAINER +WILL MEET YOUR REQUIREMENTS OR THAT THE OPERATION THEREOF WILL BE UNINTERRUPTED OR ERROR-FREE, OR +THAT ALL ERRORS WILL BE CORRECTED. + +11. LIMITATIONS OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW NVIDIA AND ITS +AFFILIATES SHALL NOT BE LIABLE FOR ANY SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL DAMAGES, OR +FOR ANY LOST PROFITS, PROJECT DELAYS, LOSS OF USE, LOSS OF DATA OR LOSS OF GOODWILL, OR THE COSTS OF +PROCURING SUBSTITUTE PRODUCTS, ARISING OUT OF OR IN CONNECTION WITH THIS LICENSE OR THE USE OR +PERFORMANCE OF THE CONTAINER, WHETHER SUCH LIABILITY ARISES FROM ANY CLAIM BASED UPON BREACH OF +CONTRACT, BREACH OF WARRANTY, TORT (INCLUDING NEGLIGENCE), PRODUCT LIABILITY OR ANY OTHER CAUSE OF +ACTION OR THEORY OF LIABILITY, EVEN IF NVIDIA HAS PREVIOUSLY BEEN ADVISED OF, OR COULD REASONABLY +HAVE FORESEEN, THE POSSIBILITY OF SUCH DAMAGES. IN NO EVENT WILL NVIDIA’S AND ITS AFFILIATES TOTAL +CUMULATIVE LIABILITY UNDER OR ARISING OUT OF THIS LICENSE EXCEED US$10.00. THE NATURE OF THE +LIABILITY OR THE NUMBER OF CLAIMS OR SUITS SHALL NOT ENLARGE OR EXTEND THIS LIMIT. + +12. TERMINATION. Your rights under this license will terminate automatically without notice from +NVIDIA if you fail to comply with any term and condition of this license or if you commence or +participate in any legal proceeding against NVIDIA with respect to the CONTAINER. NVIDIA may +terminate this license with advance written notice to you, if NVIDIA decides to no longer provide +the CONTAINER in a country or, in NVIDIA’s sole discretion, the continued use of it is no longer +commercially viable. Upon any termination of this license, you agree to promptly discontinue use of +the CONTAINER and destroy all copies in your possession or control. Your prior distributions in +accordance with this license are not affected by the termination of this license. All provisions of +this license will survive termination, except for the license granted to you. + +13. APPLICABLE LAW. This license will be governed in all respects by the laws of the United States +and of the State of Delaware, without regard to the conflicts of laws principles. The United Nations +Convention on Contracts for the International Sale of Goods is specifically disclaimed. You agree to +all terms of this license in the English language. The state or federal courts residing in Santa +Clara County, California shall have exclusive jurisdiction over any dispute or claim arising out of +this license. Notwithstanding this, you agree that NVIDIA shall still be allowed to apply for +injunctive remedies or urgent legal relief in any jurisdiction. + +14. NO ASSIGNMENT. This license and your rights and obligations thereunder may not be assigned by +you by any means or operation of law without NVIDIA’s permission. Any attempted assignment not +approved by NVIDIA in writing shall be void and of no effect. NVIDIA may assign, delegate or +transfer this license and its rights and obligations, and if to a non-affiliate you will be +notified. + +15. EXPORT. The CONTAINER is subject to United States export laws and regulations. You agree to +comply with all applicable + +U.S. and international export laws, including the Export Administration Regulations (EAR) +administered by the U.S. Department of Commerce and economic sanctions administered by the U.S. +Department of Treasury’s Office of Foreign Assets Control (OFAC). These laws include restrictions on +destinations, end-users and end-use. By accepting this license, you confirm that you are not +currently residing in a country or region currently embargoed by the U.S. and that you are not +otherwise prohibited from receiving the CONTAINER. + +16. GOVERNMENT USE. The CONTAINER is, and shall be treated as being, “Commercial Items” as that term +is defined at 48 CFR § 2.101, consisting of “commercial computer software” and “commercial computer +software documentation”, respectively, as such terms are used in, respectively, 48 CFR § 12.212 and +48 CFR §§ 227.7202 & 252.227-7014(a)(1). Use, duplication or disclosure by the U.S. Government or a +U.S. Government subcontractor is subject to the restrictions in this license pursuant to 48 CFR § +12.212 or 48 CFR § 227.7202. In no event shall the US Government user acquire rights in the +CONTAINER beyond those specified in 48 C.F.R. 52.227-19(b)(1)-(2). + +17. NOTICES. Please direct your legal notices or other correspondence to NVIDIA Corporation, 2788 +San Tomas Expressway, Santa Clara, California 95051, United States of America, Attention: Legal +Department. + +18. ENTIRE AGREEMENT. This license is the final, complete and exclusive agreement between the +parties relating to the subject matter of this license and supersedes all prior or contemporaneous +understandings and agreements relating to this subject matter, whether oral or written. If any court +of competent jurisdiction determines that any provision of this license is illegal, invalid or +unenforceable, the remaining provisions will remain in full force and effect. Any amendment or +waiver under this license shall be in writing and signed by representatives of both parties. + +19. LICENSING. If the distribution terms in this license are not suitable for your organization, or +for any questions regarding this license, please contact NVIDIA at nvidia-compute-license-questions@nvidia.com. + +(v. December 4, 2020) diff --git a/docker/run.bash b/docker/run.bash index 92482bba..1befc90d 100755 --- a/docker/run.bash +++ b/docker/run.bash @@ -22,6 +22,7 @@ # docker # an X server # Optional: +# nvidia-docker # A joystick mounted to /dev/input/js0 or /dev/input/js1 if [ $# -lt 1 ] @@ -30,7 +31,29 @@ then exit 1 fi -DOCKER_OPTS= +# Default to NVIDIA +DOCKER_OPTS="--runtime=nvidia" + +# Parse and remove args +PARAMS="" +while (( "$#" )); do + case "$1" in + --no-nvidia) + DOCKER_OPTS="" + shift + ;; + -*|--*=) # unsupported flags + echo "Error: Unsupported flag $1" >&2 + exit 1 + ;; + *) # preserve positional arguments + PARAMS="$PARAMS $1" + shift + ;; + esac +done +# set positional arguments in their proper place +eval set -- "$PARAMS" IMG=$(basename $1) @@ -45,6 +68,7 @@ then xauth_list=$(xauth nlist $DISPLAY | sed -e 's/^..../ffff/') if [ ! -z "$xauth_list" ] then + touch $XAUTH echo $xauth_list | xauth -f $XAUTH nmerge - else touch $XAUTH @@ -59,7 +83,7 @@ then DOCKER_OPTS="$DOCKER_OPTS -v $VIMRC:/home/developer/.vimrc:ro" fi -# Mabel: Share your custom terminal setup commands +# Share your custom terminal setup commands GITCONFIG=~/.gitconfig DOCKER_OPTS="$DOCKER_OPTS -v $GITCONFIG:/home/developer/.gitconfig:ro" @@ -81,7 +105,6 @@ done # -v "/opt/sublime_text:/opt/sublime_text" \ # --ipc=host and --network=host are needed for no-NVIDIA Dockerfile to work -# If need NVIDIA, add --runtime=nvidia docker run -it \ -e DISPLAY \ -e QT_X11_NO_MITSHM=1 \ From 4ee2f1c0b14e40490f03c9b52a110de948893649 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Mon, 20 Mar 2023 14:36:33 +0900 Subject: [PATCH 10/12] remove rocker run script Signed-off-by: Mabel Zhang --- docker/run_rocker.bash | 64 ------------------------------------------ 1 file changed, 64 deletions(-) delete mode 100755 docker/run_rocker.bash diff --git a/docker/run_rocker.bash b/docker/run_rocker.bash deleted file mode 100755 index 47525c70..00000000 --- a/docker/run_rocker.bash +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env bash - -# -# Copyright (C) 2022 Open Source Robotics Foundation, Inc. and Monterey Bay Aquarium Research Institute -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# - -# Runs a docker container with the image created by build.bash -# Requires: -# docker -# nvidia-docker -# an X server -# rocker - -# Display Help -Help() -{ - echo "Runs a docker container with the image created by build.bash." - echo - echo "Syntax: script [-d|s] image_name" - echo "options:" - echo "-d Use for development with host system volume mount." - echo "-s Simulation purposes only." - echo -} - -if [ $# -lt 2 ] -then - Help - exit 1 -fi - -while getopts ":ds" option; do - case $option in - d) # Build image for development - echo "Building Development image" - ROCKER_ARGS="--devices /dev/dri/ --dev-helpers --nvidia --x11 --user --home --git ";; - s) # Build image for Simulation - echo "Building Simulation image" - ROCKER_ARGS="--devices /dev/dri/ --dev-helpers --nvidia --x11 --user";; - esac -done - -IMG_NAME=${@:$OPTIND:1} - -# Replace `:` with `_` to comply with docker container naming -# And append `_runtime` -CONTAINER_NAME="$(tr ':' '_' <<< "$IMG_NAME")_runtime" -ROCKER_ARGS="${ROCKER_ARGS} --name $CONTAINER_NAME" -echo "Using image <$IMG_NAME> to start container <$CONTAINER_NAME>" - -rocker ${ROCKER_ARGS} $IMG_NAME From 9c102e16fc9258b2620613c1b56d8362fc32e050 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Tue, 21 Mar 2023 14:06:20 +0900 Subject: [PATCH 11/12] Format and move nvidia requirement --- README.md | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 004c1c1a..b1a379e4 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ These are the repositories for the project: Gazebo plugins, worlds and launch files to simulate the buoy. ## Interfaces and Examples + There are two GitHub [template](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template) repositories set up (cpp/python) for a quick start on writing a @@ -36,7 +37,8 @@ controller implementations. ## Install ### On Host System -##### Requirements +#### Requirements + At the moment, only source installation is supported. Use Ubuntu Jammy. 1. Install [ROS 2 Humble](https://docs.ros.org/en/humble/index.html) @@ -65,7 +67,7 @@ See [gz-math Python Get Started tutorial](https://github.com/gazebosim/gz-math/b sudo apt install python3-vcstool python3-colcon-common-extensions python3-pip git wget ``` -##### Build +#### Build 1. Create a workspace, for example: @@ -107,15 +109,15 @@ See [gz-math Python Get Started tutorial](https://github.com/gazebosim/gz-math/b ``` ### Using docker -##### Requirements +#### Requirements -1. Install Docker using [installation instructions.](https://docs.docker.com/engine/install/ubuntu/). - -1. Install [nvidia-docker](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker). +1. Install Docker using [installation instructions](https://docs.docker.com/engine/install/ubuntu/). 1. Complete the [Linux Postinstall steps](https://docs.docker.com/engine/install/linux-postinstall/) to allow you to manage Docker as a non-root user. -##### Build +1. If you have an NVIDIA graphics card, it can help speed up rendering. Install [nvidia-docker](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker). + +#### Build 1. Clone the buoy_entrypoint repository to download the latest Dockerfile. @@ -153,7 +155,7 @@ See [gz-math Python Get Started tutorial](https://github.com/gazebosim/gz-math/b ./join.bash buoy_latest_runtime ``` -##### Quick start +#### Quick start Quick start scripts are provided in the home directory: @@ -171,8 +173,12 @@ This sources the compiled workspace and launches the simulation: 1. In a new terminal (whether on host machine or in Docker container), source the workspace - `. ~/buoy_ws/install/setup.sh` + ``` + . ~/buoy_ws/install/setup.sh + ``` 1. Launch the simulation - `ros2 launch buoy_gazebo mbari_wec.launch.py` + ``` + ros2 launch buoy_gazebo mbari_wec.launch.py + ``` From baadcf3f96c7e89a9261260947bdec835eb51dd7 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Tue, 21 Mar 2023 19:32:09 +0900 Subject: [PATCH 12/12] update join.bash Signed-off-by: Mabel Zhang --- README.md | 2 +- docker/build.bash | 1 - docker/join.bash | 8 ++++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b1a379e4..7e96c54c 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,7 @@ See [gz-math Python Get Started tutorial](https://github.com/gazebosim/gz-math/b 1. To have another window running the same docker container, run this command in a new terminal: ``` - ./join.bash buoy_latest_runtime + ./join.bash buoy ``` #### Quick start diff --git a/docker/build.bash b/docker/build.bash index 9bc786f3..2f396619 100755 --- a/docker/build.bash +++ b/docker/build.bash @@ -68,7 +68,6 @@ fi user_id=$(id -u) image_name=$(basename $1) -#image_plus_tag=$image_name:$(date +%Y_%b_%d_%H%M) # Tag as latest so don't have a dozen uniquely timestamped images hanging around image_plus_tag=$image_name:latest diff --git a/docker/join.bash b/docker/join.bash index 42322593..aa44be66 100755 --- a/docker/join.bash +++ b/docker/join.bash @@ -19,8 +19,12 @@ # Typical usage: ./join.bash # -CONTAINER_ID=$1 +IMG=$(basename $1) +# Use quotes if image name contains symbols like a forward slash /, but then +# cannot use `basename`. +#IMG="$1" xhost + -docker exec --privileged -e DISPLAY=${DISPLAY} -e LINES=`tput lines` -it ${CONTAINER_ID} bash +containerid=$(docker ps -aqf "ancestor=${IMG}") +docker exec --privileged -e DISPLAY=${DISPLAY} -e LINES=`tput lines` -it ${containerid} bash xhost -