From 992837ea9d8ce233ead3eb8c3685f869192a7b91 Mon Sep 17 00:00:00 2001 From: Michael Ripperger Date: Wed, 23 Oct 2024 10:38:53 -0500 Subject: [PATCH] Add Docker files for GUI application (#278) * Added docker files * Added workflow for building docker image * Changed method that java libraries locations are appended to LD_LIBRARY_PATH --- .github/workflows/docker.yml | 62 ++++++++++++++++++++++++++++++ docker/Dockerfile | 44 +++++++++++++++++++++ docker/docker-compose.override.yml | 12 ++++++ docker/docker-compose.yml | 21 ++++++++++ docker/entrypoint.sh | 4 ++ 5 files changed, 143 insertions(+) create mode 100644 .github/workflows/docker.yml create mode 100644 docker/Dockerfile create mode 100644 docker/docker-compose.override.yml create mode 100644 docker/docker-compose.yml create mode 100755 docker/entrypoint.sh diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..beed2a75 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,62 @@ +name: Docker + +on: + push: + branches: + - master + - dev + pull_request: + release: + types: + - released + +jobs: + ci: + name: ${{ matrix.os }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + os: [focal, jammy, noble] + env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + PUSH_DOCKER_IMAGE: ${{ github.ref == 'refs/heads/master' || github.event_name == 'release' }} + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker meta-information + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + latest=false + prefix= + suffix= + tags: | + type=ref,event=branch,prefix=${{ matrix.os }}- + type=ref,event=pr,prefix=${{ matrix.os }}- + type=semver,pattern={{major}}.{{minor}},prefix=${{ matrix.os }}- + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: docker/Dockerfile + build-args: | + TAG=${{ matrix.os }} + push: ${{ env.PUSH_DOCKER_IMAGE }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..a3d65a13 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,44 @@ +ARG TAG=jammy +FROM ubuntu:${TAG} + +SHELL ["/bin/bash", "-c"] + +ENV DEBIAN_FRONTEND noninteractive + +USER root + +# Install +RUN apt update \ + && apt upgrade -y \ + && apt install -y cmake curl git python3 + +# Add ROS2 sources to install ROS infrastructure tools +RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg \ + && 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" | tee /etc/apt/sources.list.d/ros2.list > /dev/null + +# Install and configure ROS infrastructure tools +RUN apt update \ + && apt install -y python3-vcstool python3-colcon-common-extensions python3-rosdep \ + && rosdep init \ + && rosdep update + +# Bind mount the source directory so as not to unnecessarily copy source code into the docker image +ARG WORKSPACE_DIR=/opt/noether +RUN --mount=type=bind,target=${WORKSPACE_DIR}/src/noether \ + apt update -y -qq \ + && vcs import ${WORKSPACE_DIR}/src < ${WORKSPACE_DIR}/src/noether/dependencies.repos --shallow \ + && rosdep install \ + --from-paths ${WORKSPACE_DIR}/src \ + -iry \ + --skip-keys libvtk + +# Build the repository +# Bind mount the source directory so as not to unnecessarily copy source code into the docker image +RUN --mount=type=bind,target=${WORKSPACE_DIR}/src/noether \ + cd ${WORKSPACE_DIR} \ + && colcon build --cmake-args \ + && rm -rf build log + +# Set the entrypoint to source the workspace +COPY docker/entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker/docker-compose.override.yml b/docker/docker-compose.override.yml new file mode 100644 index 00000000..6c4ceb82 --- /dev/null +++ b/docker/docker-compose.override.yml @@ -0,0 +1,12 @@ +# Uncomment for use with GPU +# services: +# noether: +# environment: +# NVIDIA_DRIVER_CAPABILITIES: all +# deploy: +# resources: +# reservations: +# devices: +# - driver: nvidia +# count: 1 +# capabilities: [gpu] diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 00000000..b0b81d75 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,21 @@ +services: + noether: + build: + context: .. + dockerfile: docker/Dockerfile + args: + TAG: jammy + environment: + DISPLAY: $DISPLAY + XAUTHORITY: $XAUTHORITY + LD_LIBRARY_PATH_ADDITIONS: /usr/lib/jvm/java-11-openjdk-amd64/lib:/usr/lib/jvm/java-11-openjdk-amd64/lib/server + container_name: noether + image: ghcr.io/ros-industrial/noether:jammy + stdin_open: true + tty: true + network_mode: host + privileged: false + user: ${CURRENT_UID} # CURRENT_UID=$(id -u):$(id -g) + volumes: + - /tmp/.X11-unix:/tmp/.X11-unix + # - //:/meshes # Mount a local directory with meshes to /meshes in the docker container diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 00000000..ade6eb40 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,4 @@ +#! /bin/bash +source /opt/noether/install/setup.bash +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LD_LIBRARY_PATH_ADDITIONS +./opt/noether/install/noether_gui/bin/noether_gui_app