From 58404bff89c6f72c8fb5ba2acbf687fbeca06fe8 Mon Sep 17 00:00:00 2001 From: quarkytale Date: Mon, 18 Apr 2022 15:42:56 -0700 Subject: [PATCH 01/11] build, run dockerfile for buoy Signed-off-by: quarkytale --- README.md | 9 ++++ docker/build.bash | 47 ++++++++++++++++++ docker/buoy/Dockerfile | 109 +++++++++++++++++++++++++++++++++++++++++ docker/join.bash | 26 ++++++++++ docker/run.bash | 46 +++++++++++++++++ 5 files changed, 237 insertions(+) create mode 100755 docker/build.bash create mode 100644 docker/buoy/Dockerfile create mode 100755 docker/join.bash create mode 100755 docker/run.bash diff --git a/README.md b/README.md index ecdc7ec6..04f9aee1 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,15 @@ At the moment, only source installation is supported. Use Ubuntu Focal. colcon build ``` +2. Using docker + ``` + git clone https://github.com/osrf/buoy_entrypoint.git + cd ~/buoy_entrypoint/docker/ + ./build.bash buoy -u + ./run.bash buoy:latest + ``` + + ## Run 1. Source the workspace diff --git a/docker/build.bash b/docker/build.bash new file mode 100755 index 00000000..5d82b7cb --- /dev/null +++ b/docker/build.bash @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +# +# Copyright (C) 2021 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. +# +# + +# 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=$(-u) +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 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" +echo "To run:" +echo "./run.bash $image_name" \ No newline at end of file diff --git a/docker/buoy/Dockerfile b/docker/buoy/Dockerfile new file mode 100644 index 00000000..ec96a76f --- /dev/null +++ b/docker/buoy/Dockerfile @@ -0,0 +1,109 @@ +FROM ros:galactic-ros-base +ENV DEBIAN_FRONTEND=noninteractive + +# Set Ubuntu release +ARG RELEASE=focal + +# Set ROS distribution +ARG DIST=galactic + + +# Useful tools +RUN apt update \ + && apt install -y \ + apt-utils \ + atop \ + build-essential \ + cmake \ + cppcheck \ + curl \ + gdb \ + git \ + gnutls-bin \ + gnupg \ + g++-8 \ + lsb-release \ + net-tools \ + pkg-config \ + python3-dbg \ + python3-empy \ + python3-numpy \ + python3-pip \ + python3-scipy \ + python3-setuptools \ + python3-venv \ + qtbase5-dev \ + ruby \ + software-properties-common \ + sudo \ + vim \ + wget \ + xvfb \ + && apt clean + +# Setup and install ignition fortress +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' +RUN apt update \ + && apt install -y ignition-fortress \ + && rm -rf /var/lib/apt/lists/* \ + && apt clean + +# Setup and install ROS2 +RUN /bin/sh -c 'curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg' \ + && /bin/sh -c 'echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null' +RUN apt update \ + && apt install -y ros-${DIST}-desktop \ + && rm -rf /var/lib/apt/lists/* \ + && apt clean -qq + +# Install colcon and rosdep +RUN /bin/sh -c 'echo "deb http://packages.ros.org/ros2/ubuntu ${RELEASE} main" > /etc/apt/sources.list.d/ros2.list' \ + && apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 \ + && apt update \ + && apt install -y \ + python3-colcon-common-extensions \ + python3-rosdep \ + python3-rosinstall \ + python3-rosinstall-generator \ + python3-vcstool \ + && apt clean + +# 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 user's home folder +WORKDIR /home/$USERNAME + +# Setup working environment +ENV IGNITION_VERSION fortress + +# Create project directory and import packages +RUN mkdir -p /home/$USERNAME/buoy_ws/src \ + && cd /home/$USERNAME/buoy_ws/src/ \ + && vcs import --skip-existing < ~/buoy_entrypoint/buoy_all.yaml + +WORKDIR /home/$USERNAME/buoy_ws + +# Install rosdep dependencies and build the project +RUN cd /home/$USERNAME/buoy_ws/ \ + && rosdep init \ + && rosdep update \ + && rosdep install --from-paths src --ignore-src -r -y -i \ + && colcon build --cmake-clean-cache + +# Source workspaces +RUN source /opt/ros/${DIST}/setup.bash \ + && source /home/$USERNAME/buoy_ws/install/setup.bash +# Or add it to the bashrc +# RUN /bin/sh -c 'echo ". /opt/ros/galactic/setup.bash" >> ~/.bashrc' \ +# && /bin/sh -c 'echo ". ~/buoy_ws/install/setup.sh" >> ~/.bashrc' diff --git a/docker/join.bash b/docker/join.bash new file mode 100755 index 00000000..3fb8e0ae --- /dev/null +++ b/docker/join.bash @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# +# +# Copyright (C) 2021 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. +# +# +# 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/run.bash new file mode 100755 index 00000000..b9a8dfd7 --- /dev/null +++ b/docker/run.bash @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# +# Copyright (C) 2021 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 +# rocker +# Recommended: +# A joystick mounted to /dev/input/js0 or /dev/input/js1 + +if [ $# -lt 1 ] +then + echo "Usage: $0 [ ...]" + exit 1 +fi + +CUDA="" +ROCKER_ARGS="--devices /dev/dri/ --dev-helpers --nvidia --x11 --user --home --git" + +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 ${CUDA} ${ROCKER_ARGS} $IMG_NAME From 6e5579b0bf83f68a4eb660611fcf5bab148e5e72 Mon Sep 17 00:00:00 2001 From: Dharini Dutia Date: Mon, 18 Apr 2022 15:53:29 -0700 Subject: [PATCH 02/11] typo in image name --- docker/build.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/build.bash b/docker/build.bash index 5d82b7cb..23789083 100755 --- a/docker/build.bash +++ b/docker/build.bash @@ -44,4 +44,4 @@ docker tag $image_plus_tag $image_name:latest echo "Built $image_plus_tag and tagged as $image_name:latest" echo "To run:" -echo "./run.bash $image_name" \ No newline at end of file +echo "./run.bash $image_name:latest" From 44633f81c9594fd4243f4fefbd00e8e5b4c41001 Mon Sep 17 00:00:00 2001 From: quarkytale Date: Tue, 19 Apr 2022 18:44:06 -0700 Subject: [PATCH 03/11] suggested edits and fixed user Signed-off-by: quarkytale --- docker/build.bash | 7 ++- docker/buoy/Dockerfile | 97 +++++++++++------------------------------- docker/join.bash | 2 +- docker/run.bash | 2 +- 4 files changed, 30 insertions(+), 78 deletions(-) diff --git a/docker/build.bash b/docker/build.bash index 23789083..2f7b7444 100755 --- a/docker/build.bash +++ b/docker/build.bash @@ -1,7 +1,7 @@ #!/usr/bin/env bash # -# Copyright (C) 2021 Open Source Robotics Foundation +# 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. @@ -34,12 +34,11 @@ then exit 2 fi -user=$(-u) -user_id=$(id -u) +user=$(echo $USERNAME) 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 user_id="$user_id" -f "$DIR/$image_name/Dockerfile" . +docker build --rm -t $image_plus_tag --build-arg USERNAME="$user" -f "$DIR/$image_name/Dockerfile" . docker tag $image_plus_tag $image_name:latest echo "Built $image_plus_tag and tagged as $image_name:latest" diff --git a/docker/buoy/Dockerfile b/docker/buoy/Dockerfile index ec96a76f..2411a340 100644 --- a/docker/buoy/Dockerfile +++ b/docker/buoy/Dockerfile @@ -1,109 +1,62 @@ FROM ros:galactic-ros-base ENV DEBIAN_FRONTEND=noninteractive -# Set Ubuntu release -ARG RELEASE=focal - -# Set ROS distribution -ARG DIST=galactic - - # Useful tools RUN apt update \ && apt install -y \ - apt-utils \ - atop \ build-essential \ - cmake \ - cppcheck \ curl \ - gdb \ - git \ - gnutls-bin \ - gnupg \ - g++-8 \ lsb-release \ - net-tools \ - pkg-config \ - python3-dbg \ - python3-empy \ - python3-numpy \ - python3-pip \ - python3-scipy \ - python3-setuptools \ - python3-venv \ - qtbase5-dev \ - ruby \ - software-properties-common \ - sudo \ - vim \ wget \ - xvfb \ && apt clean # Setup and install ignition fortress 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' -RUN apt update \ + && /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 ignition-fortress \ && rm -rf /var/lib/apt/lists/* \ && apt clean -# Setup and install ROS2 -RUN /bin/sh -c 'curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg' \ - && /bin/sh -c 'echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null' -RUN apt update \ - && apt install -y ros-${DIST}-desktop \ - && rm -rf /var/lib/apt/lists/* \ - && apt clean -qq - # Install colcon and rosdep -RUN /bin/sh -c 'echo "deb http://packages.ros.org/ros2/ubuntu ${RELEASE} main" > /etc/apt/sources.list.d/ros2.list' \ - && apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 \ - && apt update \ +RUN apt update \ && apt install -y \ python3-colcon-common-extensions \ + python3-colcon-core \ python3-rosdep \ - python3-rosinstall \ - python3-rosinstall-generator \ python3-vcstool \ && apt clean -# 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 user's home folder -WORKDIR /home/$USERNAME +# Add the same user as outside the container +# Requires a docker build argument `USERNAME` +ARG USERNAME # Setup working environment ENV IGNITION_VERSION fortress +# When running a container start in the user's home folder +WORKDIR /home/${USERNAME}/ + # Create project directory and import packages RUN mkdir -p /home/$USERNAME/buoy_ws/src \ && cd /home/$USERNAME/buoy_ws/src/ \ - && vcs import --skip-existing < ~/buoy_entrypoint/buoy_all.yaml + && wget https://raw.githubusercontent.com/osrf/buoy_entrypoint/main/buoy_all.yaml \ + && vcs import --skip-existing < buoy_all.yaml -WORKDIR /home/$USERNAME/buoy_ws +WORKDIR /home/${USERNAME}/buoy_ws +COPY . src/buoy_sim -# Install rosdep dependencies and build the project -RUN cd /home/$USERNAME/buoy_ws/ \ - && rosdep init \ +# Install rosdep dependencies +RUN apt update \ && rosdep update \ && rosdep install --from-paths src --ignore-src -r -y -i \ - && colcon build --cmake-clean-cache + && rm -rf /var/lib/apt/lists/* \ + && apt clean + +# TODO(quarkytale): Build the project +# RUN pwd \ +# && colcon info buoy_sim -# Source workspaces -RUN source /opt/ros/${DIST}/setup.bash \ - && source /home/$USERNAME/buoy_ws/install/setup.bash -# Or add it to the bashrc -# RUN /bin/sh -c 'echo ". /opt/ros/galactic/setup.bash" >> ~/.bashrc' \ -# && /bin/sh -c 'echo ". ~/buoy_ws/install/setup.sh" >> ~/.bashrc' +# Source workspaces, add it to the bashrc +RUN /bin/sh -c 'echo ". /opt/ros/${ROS_DISTRO}/setup.bash" >> ~/.bashrc' \ + && /bin/sh -c 'echo ". ~/buoy_ws/install/setup.sh" >> ~/.bashrc' diff --git a/docker/join.bash b/docker/join.bash index 3fb8e0ae..d2b48116 100755 --- a/docker/join.bash +++ b/docker/join.bash @@ -1,7 +1,7 @@ #!/usr/bin/env bash # # -# Copyright (C) 2021 Open Source Robotics Foundation +# 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. diff --git a/docker/run.bash b/docker/run.bash index b9a8dfd7..e5549b53 100755 --- a/docker/run.bash +++ b/docker/run.bash @@ -1,7 +1,7 @@ #!/usr/bin/env bash # -# Copyright (C) 2021 Open Source Robotics Foundation +# 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. From 2dd2ef9793562fed0088f1264245460b8e777464 Mon Sep 17 00:00:00 2001 From: quarkytale Date: Wed, 20 Apr 2022 16:27:33 -0700 Subject: [PATCH 04/11] fixed project building and added run options Signed-off-by: quarkytale --- README.md | 19 ++++++++++++++----- docker/build.bash | 2 +- docker/buoy/Dockerfile | 22 ++++++++++++---------- docker/run.bash | 30 +++++++++++++++++++++++++----- 4 files changed, 52 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 04f9aee1..97242e98 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ These are the repositories for the project: Gazebo plugins, worlds and launch files to simulate the buoy. ## Install - +### On Host System At the moment, only source installation is supported. Use Ubuntu Focal. 1. Install [ROS 2 Galactic](https://docs.ros.org/en/galactic/index.html) @@ -62,14 +62,23 @@ At the moment, only source installation is supported. Use Ubuntu Focal. colcon build ``` -2. Using docker +### Using docker +#### Requirements +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. +1. Install `rocker` by `sudo apt-get install python3-rocker`. + +#### Usage +Clone the buoy_entrypoint repository to download the latest Dockerfile. ``` git clone https://github.com/osrf/buoy_entrypoint.git cd ~/buoy_entrypoint/docker/ - ./build.bash buoy -u - ./run.bash buoy:latest + ./build.bash buoy + ./run.bash [-d|s] buoy:latest ``` - +where `./run.bash` option: +1. -d Use for development with host system volume mount +1. -s Simulation purposes only ## Run diff --git a/docker/build.bash b/docker/build.bash index 2f7b7444..aa7da460 100755 --- a/docker/build.bash +++ b/docker/build.bash @@ -43,4 +43,4 @@ docker tag $image_plus_tag $image_name:latest echo "Built $image_plus_tag and tagged as $image_name:latest" echo "To run:" -echo "./run.bash $image_name:latest" +echo "./run.bash [-d|s] $image_name:latest" diff --git a/docker/buoy/Dockerfile b/docker/buoy/Dockerfile index 2411a340..8fd04ad2 100644 --- a/docker/buoy/Dockerfile +++ b/docker/buoy/Dockerfile @@ -4,6 +4,7 @@ ENV DEBIAN_FRONTEND=noninteractive # Useful tools RUN apt update \ && apt install -y \ + apt-utils \ build-essential \ curl \ lsb-release \ @@ -37,9 +38,10 @@ ENV IGNITION_VERSION fortress # When running a container start in the user's home folder WORKDIR /home/${USERNAME}/ +### TODO(quarkytale): creating and building not required for development # Create project directory and import packages -RUN mkdir -p /home/$USERNAME/buoy_ws/src \ - && cd /home/$USERNAME/buoy_ws/src/ \ +RUN mkdir -p /home/${USERNAME}/buoy_ws/src \ + && cd /home/${USERNAME}/buoy_ws/src/ \ && wget https://raw.githubusercontent.com/osrf/buoy_entrypoint/main/buoy_all.yaml \ && vcs import --skip-existing < buoy_all.yaml @@ -48,15 +50,15 @@ COPY . src/buoy_sim # Install rosdep dependencies RUN apt update \ - && rosdep update \ - && rosdep install --from-paths src --ignore-src -r -y -i \ - && rm -rf /var/lib/apt/lists/* \ - && apt clean + && rosdep update \ + && rosdep install --from-paths src --ignore-src -r -y -i \ + && rm -rf /var/lib/apt/lists/* \ + && apt clean -# TODO(quarkytale): Build the project -# RUN pwd \ -# && colcon info buoy_sim +# Build the project +RUN /bin/bash -c 'source /opt/ros/${ROS_DISTRO}/setup.bash \ + && colcon build --cmake-clean-cache' # Source workspaces, add it to the bashrc RUN /bin/sh -c 'echo ". /opt/ros/${ROS_DISTRO}/setup.bash" >> ~/.bashrc' \ - && /bin/sh -c 'echo ". ~/buoy_ws/install/setup.sh" >> ~/.bashrc' + && /bin/sh -c 'echo "./home/${USERNAME}/buoy_ws/install/setup.sh" >> ~/.bashrc' diff --git a/docker/run.bash b/docker/run.bash index e5549b53..b960069b 100755 --- a/docker/run.bash +++ b/docker/run.bash @@ -26,14 +26,34 @@ # Recommended: # A joystick mounted to /dev/input/js0 or /dev/input/js1 -if [ $# -lt 1 ] +# Display Help +Help() +{ + echo "Runs a docker container with the image created by build.bash." + echo + echo "Syntax: script [-s|t] image_name" + echo "options:" + echo "d Use for development with host system volume mount." + echo "s Simulation purposes only." + echo +} + +if [ $# -lt 2 ] then - echo "Usage: $0 [ ...]" + echo "Usage: $0 " + Help exit 1 fi -CUDA="" -ROCKER_ARGS="--devices /dev/dri/ --dev-helpers --nvidia --x11 --user --home --git" +while getopts ":ds" option; do + case $option in + d) # Build image for development + 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 --git";; + esac +done IMG_NAME=${@:$OPTIND:1} @@ -43,4 +63,4 @@ CONTAINER_NAME="$(tr ':' '_' <<< "$IMG_NAME")_runtime" ROCKER_ARGS="${ROCKER_ARGS} --name $CONTAINER_NAME" echo "Using image <$IMG_NAME> to start container <$CONTAINER_NAME>" -rocker ${CUDA} ${ROCKER_ARGS} $IMG_NAME +rocker ${ROCKER_ARGS} $IMG_NAME From c7ce40da1eaa5c3da71513d34c528ab862aee4cc Mon Sep 17 00:00:00 2001 From: quarkytale Date: Wed, 27 Apr 2022 09:24:20 -0700 Subject: [PATCH 05/11] commiting suggestions Signed-off-by: quarkytale --- README.md | 7 +++++++ docker/buoy/Dockerfile | 19 +++++++------------ docker/run.bash | 8 +++----- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 97242e98..ece29c81 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ At the moment, only source installation is supported. Use Ubuntu Focal. ### Using docker #### 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. 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`. @@ -79,6 +80,12 @@ Clone the buoy_entrypoint repository to download the latest Dockerfile. where `./run.bash` option: 1. -d Use for development with host system volume mount 1. -s Simulation purposes only +> The `./run.bash` script is a wrapper around rocker, see [documentation](https://github.com/osrf/rocker) for additional options. + +To have another window running the same docker container, run this command in a new terminal: + ``` + ./join.bash buoy_latest_runtime + ``` ## Run diff --git a/docker/buoy/Dockerfile b/docker/buoy/Dockerfile index 8fd04ad2..f500ed20 100644 --- a/docker/buoy/Dockerfile +++ b/docker/buoy/Dockerfile @@ -11,23 +11,18 @@ RUN apt update \ wget \ && apt clean -# Setup and install ignition fortress +# Setup and install ignition fortress, colcon and rosdep 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 ignition-fortress \ + python3-colcon-common-extensions \ + python3-colcon-core \ + python3-rosdep \ + python3-vcstool \ && rm -rf /var/lib/apt/lists/* \ && apt clean -# Install colcon and rosdep -RUN apt update \ - && apt install -y \ - python3-colcon-common-extensions \ - python3-colcon-core \ - python3-rosdep \ - python3-vcstool \ - && apt clean - # Add the same user as outside the container # Requires a docker build argument `USERNAME` ARG USERNAME @@ -57,8 +52,8 @@ RUN apt update \ # Build the project RUN /bin/bash -c 'source /opt/ros/${ROS_DISTRO}/setup.bash \ - && colcon build --cmake-clean-cache' + && colcon build' # Source workspaces, add it to the bashrc RUN /bin/sh -c 'echo ". /opt/ros/${ROS_DISTRO}/setup.bash" >> ~/.bashrc' \ - && /bin/sh -c 'echo "./home/${USERNAME}/buoy_ws/install/setup.sh" >> ~/.bashrc' + && /bin/sh -c 'echo ". /home/${USERNAME}/buoy_ws/install/setup.sh" >> ~/.bashrc' diff --git a/docker/run.bash b/docker/run.bash index b960069b..4c5ad404 100755 --- a/docker/run.bash +++ b/docker/run.bash @@ -23,8 +23,6 @@ # nvidia-docker # an X server # rocker -# Recommended: -# A joystick mounted to /dev/input/js0 or /dev/input/js1 # Display Help Help() @@ -33,14 +31,13 @@ Help() echo echo "Syntax: script [-s|t] image_name" echo "options:" - echo "d Use for development with host system volume mount." - echo "s Simulation purposes only." + echo "-d Use for development with host system volume mount." + echo "-s Simulation purposes only." echo } if [ $# -lt 2 ] then - echo "Usage: $0 " Help exit 1 fi @@ -48,6 +45,7 @@ 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" From 367cdbee2a30e879c328126c9a56fcccaa254db2 Mon Sep 17 00:00:00 2001 From: quarkytale Date: Wed, 27 Apr 2022 09:49:49 -0700 Subject: [PATCH 06/11] typo Signed-off-by: quarkytale --- docker/join.bash | 2 +- docker/run.bash | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/join.bash b/docker/join.bash index d2b48116..42322593 100755 --- a/docker/join.bash +++ b/docker/join.bash @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# + # # Copyright (C) 2022 Open Source Robotics Foundation, Inc. and Monterey Bay Aquarium Research Institute # diff --git a/docker/run.bash b/docker/run.bash index 4c5ad404..29895082 100755 --- a/docker/run.bash +++ b/docker/run.bash @@ -29,7 +29,7 @@ Help() { echo "Runs a docker container with the image created by build.bash." echo - echo "Syntax: script [-s|t] image_name" + echo "Syntax: script [-d|s] image_name" echo "options:" echo "-d Use for development with host system volume mount." echo "-s Simulation purposes only." From ba0bf1926f141b11a616eea66dc27ea2560d7c62 Mon Sep 17 00:00:00 2001 From: quarkytale Date: Tue, 10 May 2022 00:02:20 -0700 Subject: [PATCH 07/11] fixing buoy_ws permissions Signed-off-by: quarkytale --- docker/buoy/Dockerfile | 38 ++++++++++++++++++++++---------------- docker/run.bash | 2 +- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/docker/buoy/Dockerfile b/docker/buoy/Dockerfile index f500ed20..5a5fc0d5 100644 --- a/docker/buoy/Dockerfile +++ b/docker/buoy/Dockerfile @@ -23,37 +23,43 @@ RUN /bin/sh -c 'wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share && rm -rf /var/lib/apt/lists/* \ && apt clean -# Add the same user as outside the container -# Requires a docker build argument `USERNAME` -ARG USERNAME - # Setup working environment ENV IGNITION_VERSION fortress # When running a container start in the user's home folder WORKDIR /home/${USERNAME}/ -### TODO(quarkytale): creating and building not required for development -# Create project directory and import packages -RUN mkdir -p /home/${USERNAME}/buoy_ws/src \ - && cd /home/${USERNAME}/buoy_ws/src/ \ +# Add the same user as outside the container +# Requires a docker build argument `USERNAME` +ARG USERNAME +RUN useradd -d /home/${USERNAME}/ -m -s /bin/bash $USERNAME + +# Create project directory, set permissions and import packages +RUN mkdir -p /tmp/buoy_ws/src \ + && chown -R $USERNAME:$USERNAME /tmp/buoy_ws \ + && adduser $USERNAME sudo \ + && echo "$USERNAME ALL=NOPASSWD: ALL" >> /etc/sudoers.d/$USERNAME \ + && cd /tmp/buoy_ws/src/ \ && wget https://raw.githubusercontent.com/osrf/buoy_entrypoint/main/buoy_all.yaml \ - && vcs import --skip-existing < buoy_all.yaml + && vcs import --skip-existing < buoy_all.yaml \ + && chown -R $USERNAME:$USERNAME . -WORKDIR /home/${USERNAME}/buoy_ws -COPY . src/buoy_sim +# Run the commands below as non-root +# USER ${USERNAME} # Install rosdep dependencies -RUN apt update \ +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 + && 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 /tmp/buoy_ws \ && colcon build' # Source workspaces, add it to the bashrc -RUN /bin/sh -c 'echo ". /opt/ros/${ROS_DISTRO}/setup.bash" >> ~/.bashrc' \ - && /bin/sh -c 'echo ". /home/${USERNAME}/buoy_ws/install/setup.sh" >> ~/.bashrc' +RUN /bin/sh -c 'echo ". /opt/ros/${ROS_DISTRO}/setup.bash" >> /home/${USERNAME}/.bashrc' \ + && /bin/sh -c 'echo ". /home/${USERNAME}/buoy_ws/install/setup.sh" >> /home/${USERNAME}/.bashrc' diff --git a/docker/run.bash b/docker/run.bash index 29895082..47525c70 100755 --- a/docker/run.bash +++ b/docker/run.bash @@ -49,7 +49,7 @@ while getopts ":ds" option; do 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 --git";; + ROCKER_ARGS="--devices /dev/dri/ --dev-helpers --nvidia --x11 --user";; esac done From 776fbd3befa38b7fdc9982a890e4df41882ffbb3 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Tue, 10 May 2022 10:22:08 -0700 Subject: [PATCH 08/11] Suggestions to Docker Signed-off-by: Louise Poubel --- docker/buoy/Dockerfile | 52 ++++++++---------------------------------- 1 file changed, 9 insertions(+), 43 deletions(-) diff --git a/docker/buoy/Dockerfile b/docker/buoy/Dockerfile index 5a5fc0d5..b72fdda8 100644 --- a/docker/buoy/Dockerfile +++ b/docker/buoy/Dockerfile @@ -1,65 +1,31 @@ FROM ros:galactic-ros-base ENV DEBIAN_FRONTEND=noninteractive -# Useful tools +# Necessary tools RUN apt update \ && apt install -y \ - apt-utils \ - build-essential \ - curl \ - lsb-release \ - wget \ - && apt clean + wget -# Setup and install ignition fortress, colcon and rosdep -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 ignition-fortress \ - python3-colcon-common-extensions \ - python3-colcon-core \ - python3-rosdep \ - python3-vcstool \ - && rm -rf /var/lib/apt/lists/* \ - && apt clean - -# Setup working environment +# Using non-official Gazebo + ROS combination, set it explicitly ENV IGNITION_VERSION fortress -# When running a container start in the user's home folder -WORKDIR /home/${USERNAME}/ - -# Add the same user as outside the container -# Requires a docker build argument `USERNAME` -ARG USERNAME -RUN useradd -d /home/${USERNAME}/ -m -s /bin/bash $USERNAME - -# Create project directory, set permissions and import packages +# Create project directory and import packages RUN mkdir -p /tmp/buoy_ws/src \ - && chown -R $USERNAME:$USERNAME /tmp/buoy_ws \ - && adduser $USERNAME sudo \ - && echo "$USERNAME ALL=NOPASSWD: ALL" >> /etc/sudoers.d/$USERNAME \ && cd /tmp/buoy_ws/src/ \ && wget https://raw.githubusercontent.com/osrf/buoy_entrypoint/main/buoy_all.yaml \ - && vcs import --skip-existing < buoy_all.yaml \ - && chown -R $USERNAME:$USERNAME . - -# Run the commands below as non-root -# USER ${USERNAME} + && vcs import < buoy_all.yaml -# Install rosdep dependencies +# 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 \ - && sudo rm -rf /var/lib/apt/lists/* \ - && sudo apt clean + && 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' -# Source workspaces, add it to the bashrc -RUN /bin/sh -c 'echo ". /opt/ros/${ROS_DISTRO}/setup.bash" >> /home/${USERNAME}/.bashrc' \ - && /bin/sh -c 'echo ". /home/${USERNAME}/buoy_ws/install/setup.sh" >> /home/${USERNAME}/.bashrc' +ENTRYPOINT ["/bin/bash" , "-c" , "source /tmp/buoy_ws/install/setup.bash && /bin/bash"] From ab9f9399eee2deadfa01bce93292072111324b99 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Tue, 10 May 2022 10:57:04 -0700 Subject: [PATCH 09/11] apt-utils --- docker/buoy/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/buoy/Dockerfile b/docker/buoy/Dockerfile index b72fdda8..6894c096 100644 --- a/docker/buoy/Dockerfile +++ b/docker/buoy/Dockerfile @@ -4,6 +4,7 @@ ENV DEBIAN_FRONTEND=noninteractive # Necessary tools RUN apt update \ && apt install -y \ + apt-utils \ wget # Using non-official Gazebo + ROS combination, set it explicitly From 1b81e2e1acad7fb79f0caa3537d92cfe1efd4f0d Mon Sep 17 00:00:00 2001 From: quarkytale Date: Tue, 10 May 2022 13:15:19 -0700 Subject: [PATCH 10/11] additional documentation Signed-off-by: quarkytale --- README.md | 64 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index ece29c81..cf9d6d61 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ These are the repositories for the project: ## Install ### On Host System +##### Requirements At the moment, only source installation is supported. Use Ubuntu Focal. 1. Install [ROS 2 Galactic](https://docs.ros.org/en/galactic/index.html) @@ -26,6 +27,8 @@ At the moment, only source installation is supported. Use Ubuntu Focal. `sudo apt install python3-vcstool python3-colcon-common-extensions git wget` +##### Usage + 1. Create a workspace, for example: ``` @@ -62,38 +65,67 @@ At the moment, only source installation is supported. Use Ubuntu Focal. colcon build ``` +##### Run + +1. Source the workspace + + `. ~/buoy_ws/install/setup.sh` + +1. Launch the simulation + + `ros2 launch buoy_gazebo buoy.launch.py` + + ### Using docker -#### Requirements -1. Install Docker using [installation instructions.](https://docs.docker.com/engine/install/ubuntu/) +##### 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. 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 -Clone the buoy_entrypoint repository to download the latest Dockerfile. +##### Usage + +1. Clone the buoy_entrypoint repository to download the latest Dockerfile. + ``` git clone https://github.com/osrf/buoy_entrypoint.git cd ~/buoy_entrypoint/docker/ + ``` + +1. Build the docker image + + ``` ./build.bash buoy + ``` + +1. Run the container + + ``` ./run.bash [-d|s] buoy:latest ``` -where `./run.bash` option: -1. -d Use for development with host system volume mount -1. -s Simulation purposes only -> The `./run.bash` script is a wrapper around rocker, see [documentation](https://github.com/osrf/rocker) for additional options. + 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 in the docker container. + Regardless the script option, project source files can be found in `/tmp/buoy_ws/' inside the container. Note that any changes to files in the container will have limited scope. + +1. To have another window running the same docker container, run this command in a new terminal: -To have another window running the same docker container, run this command in a new terminal: ``` ./join.bash buoy_latest_runtime ``` -## Run - -1. Source the workspace - - `. ~/buoy_ws/install/setup.sh` +> The build and run bash scripts are a wrapper around rocker, checkout its [documentation](https://github.com/osrf/rocker) for additional options. -1. Launch the simulation +##### Run - `ros2 launch buoy_gazebo buoy.launch.py` +Inside the docker container, run: +``` +ign gazebo mbari_wec.sdf -r +``` From 2a30488796a83e70a37baa0804f35b0b99bc434c Mon Sep 17 00:00:00 2001 From: quarkytale Date: Tue, 10 May 2022 13:34:53 -0700 Subject: [PATCH 11/11] doc for development option Signed-off-by: quarkytale --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cf9d6d61..fa976105 100644 --- a/README.md +++ b/README.md @@ -111,8 +111,8 @@ At the moment, only source installation is supported. Use Ubuntu Focal. * -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 in the docker container. - Regardless the script option, project source files can be found in `/tmp/buoy_ws/' inside the container. Note that any changes to files in the container will have limited scope. + 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. 1. To have another window running the same docker container, run this command in a new terminal: