diff --git a/.github/workflows/integration_tests.yaml b/.github/workflows/integration_tests.yaml index eed1445e..2611ef60 100644 --- a/.github/workflows/integration_tests.yaml +++ b/.github/workflows/integration_tests.yaml @@ -13,5 +13,7 @@ jobs: sudo rm -rf /opt/ghc - name: Check out code uses: actions/checkout@v2 - - name: Compile and run tests - run: docker build -t mbari_lrauv . -f docker/tests/Dockerfile + - name: Compile tests + run: docker build -t osrf_lrauv . -f docker/tests/Dockerfile + - name: Run tests + run: docker run --rm osrf_lrauv diff --git a/README.md b/README.md index f408d350..f790fe44 100644 --- a/README.md +++ b/README.md @@ -24,18 +24,55 @@ Optionally, you may choose to build this repository using Docker, for convenience. Make sure you have a recent version of [Docker](https://docs.docker.com/) and [nvidia-docker](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker) -installed. Next to get started simply run the following command. +installed. +And [rocker](https://github.com/osrf/rocker) installed. + ``` docker/build_and_run_docker.sh ``` To join in a separate terminal, remember to source Ignition and the workspace: ``` -docker/join.sh mbari_lrauv +docker/join.sh osrf_lrauv . /home/ign_ws/install/setup.bash . /home/colcon_ws/install/setup.bash ``` + +### Empty World from Source + +~ 90 minutes from scratch + +~ 70 seconds with only workspace changes + +``` +cd docker +docker build -t osrf_lrauv -f empty_world/Dockerfile .. +rocker --nvidia --x11 --user osrf_lrauv bash +ign launch lrauv_world.ign +``` + +### Unit tests dockerfile + +Enter test environment + +``` +docker build -t osrf_lrauv_tests -f tests/Dockerfile .. +rocker --nvidia --x11 --user osrf_lrauv_tests bash +``` + +Then run anything you want in the environment, unit tests are in `./build/lrauv_ignition_plugins` +``` +./build/lrauv_ignition_plugins/test_buoyancy_action +``` + +Or the main entry point + +``` +ign launch lrauv_world.ign +``` + + ## To build To run the code in this repository natively without Docker, make sure you have diff --git a/docker/build_and_run_docker.sh b/docker/build_and_run_docker.sh index cb77d3b1..b393fba2 100755 --- a/docker/build_and_run_docker.sh +++ b/docker/build_and_run_docker.sh @@ -23,55 +23,11 @@ # 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) - xauth_list=$(sed -e 's/^..../ffff/' <<< "$xauth_list") - if [ ! -z "$xauth_list" ] - then - echo "$xauth_list" | xauth -f $XAUTH nmerge - - else - touch $XAUTH - fi - chmod a+r $XAUTH -fi - -DOCKER_OPTS= - -# Get the current version of docker -DOCKER_VER=$(docker version --format '{{.Server.Version}}') -if dpkg --compare-versions 19.03 gt "$DOCKER_VER" -then - echo "Docker version is less than 19.03, using nvidia-docker2 runtime" - if ! dpkg --list | grep nvidia-docker2 - then - echo "Please either update docker-ce to a version greater than 19.03 or install nvidia-docker2" - exit 1 - fi - DOCKER_OPTS="$DOCKER_OPTS --runtime=nvidia" -else - DOCKER_OPTS="$DOCKER_OPTS --gpus all" -fi - DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" cd $DIR # Build the docker image -docker build -t mbari_lrauv -f $DIR/empty_world/Dockerfile .. +docker build -t osrf_lrauv -f $DIR/tests/Dockerfile .. + +rocker --nvidia --x11 --user --user-override-name=developer --user-preserve-home -- osrf_lrauv -# Run the image -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" \ - --network host \ - --rm \ - --privileged \ - --security-opt seccomp=unconfined \ - $DOCKER_OPTS \ - mbari_lrauv diff --git a/docker/debug_integration.sh b/docker/debug_integration.sh index 88c617be..ee47e18a 100755 --- a/docker/debug_integration.sh +++ b/docker/debug_integration.sh @@ -23,60 +23,14 @@ # 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) - xauth_list=$(sed -e 's/^..../ffff/' <<< "$xauth_list") - if [ ! -z "$xauth_list" ] - then - echo "$xauth_list" | xauth -f $XAUTH nmerge - - else - touch $XAUTH - fi - chmod a+r $XAUTH -fi -DOCKER_OPTS= - -# Get the current version of docker -DOCKER_VER=$(docker version --format '{{.Server.Version}}') -if dpkg --compare-versions 19.03 gt "$DOCKER_VER" -then - echo "Docker version is less than 19.03, using nvidia-docker2 runtime" - if ! dpkg --list | grep nvidia-docker2 - then - echo "Please either update docker-ce to a version greater than 19.03 or install nvidia-docker2" - exit 1 - fi - DOCKER_OPTS="$DOCKER_OPTS --runtime=nvidia" -else - DOCKER_OPTS="$DOCKER_OPTS --gpus all" -fi +# exit if the docker image doesn't build +set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" cd $DIR - -# exit if the docker image doesn't build -set -e - # Build the docker image -docker build -t mbari_lrauv_debug -f $DIR/debug_integration/Dockerfile .. +docker build -t osrf_lrauv_tests -f $DIR/tests/Dockerfile .. -# Run the image -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" \ - -v "$DIR/../../results:/results"\ - --network host \ - --rm \ - --privileged \ - --security-opt seccomp=unconfined \ - $DOCKER_OPTS \ - mbari_lrauv_debug +rocker --nvidia --x11 --user --user-override-name=developer --user-preserve-home -- osrf_lrauv_tests tmuxinator start debug_and_plot -n debug_session -p src/lrauv/docker/tests/debug_integration_mux.yml \ No newline at end of file diff --git a/docker/debug_integration/Dockerfile b/docker/debug_integration/Dockerfile deleted file mode 100644 index 07512996..00000000 --- a/docker/debug_integration/Dockerfile +++ /dev/null @@ -1,79 +0,0 @@ -# -# 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. -# - -# -# Development of this module has been funded by the Monterey Bay Aquarium -# Research Institute (MBARI) and the David and Lucile Packard Foundation -# - -FROM mbari/lrauv-ignition-sim:garden - -USER root - -# This avoids keyboard interaction when asked for geographic area -ARG DEBIAN_FRONTEND=noninteractive - -# setup timezone -RUN echo 'Etc/UTC' > /etc/timezone && \ - ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime - -RUN apt-get update \ - && apt-get install -y \ - build-essential \ - curl \ - gnupg2 \ - lsb-release \ - tzdata \ - wget \ - python3-numpy - -# Add Ignition's latest packages, which may be more up-to-date than the ones from the MBARI image -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 -' - -# Install the latest Ignition binaries -RUN apt-get -qq update && apt-get -q -y install \ - ignition-garden python3-numpy - -# Install PCL -RUN apt-get update \ - && apt-get install -y \ - libpcl-dev tmux tmuxinator - -# Clean up apt -RUN rm -rf /var/lib/apt/lists/* \ - && apt-get -qq clean - -USER $USERNAME - -# We're in /home/developer/lrauv_ws/src/lrauv-application, go back to ~/lrauv_ws -WORKDIR ../.. - -# Clean up colcon workspace -RUN rm -rf build log install src/lrauv - -# Use current version of the code: Change to local branch if needed. -COPY . src/lrauv - -# Build image -RUN [ "/bin/bash" , "-c" , "colcon build --cmake-args='-DBUILD_TESTING=true'" ] - -# Run tests -# RUN [ "/bin/bash" , "-c" , ". ~/lrauv_ws/install/setup.sh; colcon test --event-handlers console_direct+" ] -# RUN [ "/bin/bash" , "-c" , ". ~/lrauv_ws/install/setup.sh; colcon test-result" ]" - -ENTRYPOINT tmuxinator start debug_and_plot -n debug_session -p src/lrauv/docker/debug_integration/mux.yml diff --git a/docker/empty_world/Dockerfile b/docker/empty_world/Dockerfile index 668bfbec..cf707249 100644 --- a/docker/empty_world/Dockerfile +++ b/docker/empty_world/Dockerfile @@ -104,12 +104,12 @@ COPY . /home/colcon_ws/src WORKDIR /home/colcon_ws RUN [ "/bin/bash" , "-c" , \ "source ${IGN_WS}/install/setup.bash \ - && colcon build \ + && colcon build --cmake-args='-DBUILD_TESTING=ON' \ && apt-get -qq clean" ] -SHELL ["/bin/bash", "-c"] +COPY docker/entrypoint.bash / -# start ignition -ENTRYPOINT [ "/bin/bash" , "-c" , \ - "source /home/colcon_ws/install/setup.bash \ - && ign gazebo buoyant_tethys.sdf" ] +# setup ignition environment +ENTRYPOINT ["/entrypoint.bash"] + +CMD ign gazebo buoyant_tethys.sdf diff --git a/docker/entrypoint.bash b/docker/entrypoint.bash new file mode 100755 index 00000000..083a7115 --- /dev/null +++ b/docker/entrypoint.bash @@ -0,0 +1,16 @@ +#!/bin/bash +set -e + +# Empty world dockerfile +if [ -z /home/colcon_ws/install/setup.bash ]; then + source /home/colcon_ws/install/setup.bash +# tests dockerfile +else #if [ -z ~/lrauv_ws/install/setup.bash ]; then + source /home/developer/lrauv_ws/install/setup.bash + # Make sure we're in the right workingdir + cd /home/developer/lrauv_ws +fi + +exec "$@" + + diff --git a/docker/tests/Dockerfile b/docker/tests/Dockerfile index 78e5e8e6..8fa43f5e 100644 --- a/docker/tests/Dockerfile +++ b/docker/tests/Dockerfile @@ -35,10 +35,15 @@ RUN apt-get update \ build-essential \ curl \ gnupg2 \ + libpcl-dev \ lsb-release \ + python3-numpy \ + tmux \ + tmuxinator \ tzdata \ wget \ - python3-numpy + && rm -rf /var/lib/apt/lists/* \ + && apt-get -qq clean # Add Ignition's latest packages, which may be more up-to-date than the ones from the MBARI image 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' && \ @@ -47,16 +52,10 @@ RUN /bin/sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable # Install and upgrade the latest Ignition binaries RUN apt-get -qq update && apt-get -q -y install \ - ignition-garden && apt-get dist-upgrade -y - -# Install PCL -RUN apt-get update \ - && apt-get install -y \ - libpcl-dev + ignition-garden\ + && rm -rf /var/lib/apt/lists/* \ + && apt-get -qq clean && apt-get dist-upgrade -y -# Clean up apt -RUN rm -rf /var/lib/apt/lists/* \ - && apt-get -qq clean USER $USERNAME @@ -69,9 +68,12 @@ RUN rm -rf build log install src/lrauv # Use current version of the code COPY . src/lrauv -# Build image +# Build workspace RUN [ "/bin/bash" , "-c" , "colcon build --cmake-args='-DBUILD_TESTING=true'" ] +COPY docker/entrypoint.bash / +# setup ignition environment +ENTRYPOINT ["/entrypoint.bash"] + # Run tests -RUN [ "/bin/bash" , "-c" , ". ~/lrauv_ws/install/setup.sh; colcon test --event-handlers console_direct+" ] -RUN [ "/bin/bash" , "-c" , ". ~/lrauv_ws/install/setup.sh; colcon test-result" ] +CMD [ "/bin/bash" , "-c" , "colcon test --event-handlers console_direct+; colcon test-result" ] diff --git a/docker/debug_integration/mux.yml b/docker/tests/debug_integration_mux.yml similarity index 100% rename from docker/debug_integration/mux.yml rename to docker/tests/debug_integration_mux.yml