From 98d19dcff04fc4247b163f935e7922be70ed84a0 Mon Sep 17 00:00:00 2001 From: Sebastian Castro Date: Fri, 24 Mar 2023 14:24:43 -0400 Subject: [PATCH 1/2] Add overlay Docker image option --- .docker/entrypoint-dev.sh | 20 ++++++++ .docker/entrypoint-release.sh | 11 +++++ Dockerfile | 86 +++++++++++++++++++++++++++++++++++ README.md | 30 +++++++++++- docker-compose-overlay.yaml | 68 +++++++++++++++++++++++++++ docker-compose.yaml | 13 ------ 6 files changed, 214 insertions(+), 14 deletions(-) create mode 100755 .docker/entrypoint-dev.sh create mode 100755 .docker/entrypoint-release.sh create mode 100644 Dockerfile create mode 100644 docker-compose-overlay.yaml diff --git a/.docker/entrypoint-dev.sh b/.docker/entrypoint-dev.sh new file mode 100755 index 00000000..3b8ca991 --- /dev/null +++ b/.docker/entrypoint-dev.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Custom entrypoint to start when running a developer container. + +set -e + +# Allow aliases in noninteractive shells and source common MoveIt Studio aliases +shopt -s expand_aliases +source "/common_aliases.sh" + +if [[ -f ${CUSTOM_WS}/install/setup.bash ]] +then + echo "Sourcing custom workspace" + source "${CUSTOM_WS}/install/setup.bash" + /copy_dds_configs.sh +else + echo -e "Custom workspace is not built. Please build it with: \ncolcon build\n" +fi + +exec "$@" diff --git a/.docker/entrypoint-release.sh b/.docker/entrypoint-release.sh new file mode 100755 index 00000000..4df17904 --- /dev/null +++ b/.docker/entrypoint-release.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Custom entrypoint to start when running a release image. + +set -e + +source "${CUSTOM_WS}/install/setup.bash" + +/copy_dds_configs.sh + +exec "$@" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..addd403f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,86 @@ +# Docker container image build for running MoveIt Studio with +# a custom overlay image +# +# Example build command (with defaults): +# +# docker build -f .docker/Dockerfile . +# + +# Specify the MoveIt Studio release to build on top of. See, +# https://hub.docker.com/r/picknikciuser/moveit-studio-binaries/tags +ARG MOVEIT_STUDIO_BASE_IMAGE + +##################################################### +# Starting from the specified MoveIt Studio release # +##################################################### +# The image tag is specified in the argument itself. +# hadolint ignore=DL3006 +FROM ${MOVEIT_STUDIO_BASE_IMAGE} as base + +# The location of the user's custom workspace inside the container +ARG CUSTOM_WS=/opt/custom_ws +ENV CUSTOM_WS $CUSTOM_WS + +# Copy site configuration packages and and dependencies +RUN mkdir -p ${CUSTOM_WS}/src +COPY ./src $CUSTOM_WS/src +WORKDIR $CUSTOM_WS + +# Install additional ROS dependencies +# NOTE: The "OVERLAY_WS" contains MoveIt Studio binary packages and the source file. +# hadolint ignore=SC1091 +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + . "${OVERLAY_WS}/install/setup.sh" && \ + apt-get update && \ + rosdep install -q -y \ + --from-paths src \ + --ignore-src + +################################################# +# Target for compiled, deployable release image # +################################################# +FROM base as release + +WORKDIR $CUSTOM_WS + +# Compile the workspace +# hadolint ignore=SC1091 +RUN --mount=type=cache,target=/root/.ccache \ + . "${OVERLAY_WS}/install/setup.sh" && \ + colcon build + +# Add the custom entrypoint +COPY .docker/entrypoint-release.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] +CMD ["/usr/bin/bash"] + +################################################################### +# Target for the developer build which does not compile any code. # +################################################################### +# Expected to mount workspace and compile/test it +# inside of the resulting container. +FROM base as dev + +# The location of the user's workspace inside the container +ARG CUSTOM_WS=/opt/custom_ws +ENV CUSTOM_WS $CUSTOM_WS +WORKDIR $CUSTOM_WS + +# Install any additional packages for development work +# hadolint ignore=DL3008 +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + less \ + gdb \ + gdbserver \ + ros-humble-rclcpp-dbgsym + +# Add the developer entrypoint +COPY .docker/entrypoint-dev.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] +RUN echo "source /entrypoint.sh" >> ~/.bashrc && \ + echo "set +e" >> ~/.bashrc +CMD ["/usr/bin/bash"] diff --git a/README.md b/README.md index a0b05b3a..59ad12ac 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,32 @@ Replace ``ur10`` with the model of your choice ``[ur3,ur3e,ur5,ur5e,ur10,ur10e,u ## Start MoveIt Studio -``docker compose up`` \ No newline at end of file +``docker compose up`` + +## Using a custom Docker overlay image + +### Release image + +To build: + +``docker compose -f docker-compose-overlay.yaml build`` + +To start: + +``docker compose -f docker-compose-overlay.yaml up`` + +### Developer container + +We use Docker profiles to have separate configuration for developers. + +To build: + +``docker compose -f docker-compose-overlay.yaml build dev`` + +To start: + +``docker compose -f docker-compose-overlay.yaml up dev`` + +And in a new Terminal, you can access a dev shell: + +``docker compose exec -it dev bash`` diff --git a/docker-compose-overlay.yaml b/docker-compose-overlay.yaml new file mode 100644 index 00000000..2580394d --- /dev/null +++ b/docker-compose-overlay.yaml @@ -0,0 +1,68 @@ +version: "3.9" +services: + base: + extends: + file: docker-compose.yaml + service: base + # Optionally allow building this service from source with `docker compose build` + build: + context: . + target: release + args: + MOVEIT_STUDIO_BASE_IMAGE: ghcr.io/picknikrobotics/moveit-studio:${STUDIO_DOCKER_TAG:-main} + command: sleep infinity + + # Extend all the services from the base image + workspace_builder: + extends: + file: docker-compose.yaml + service: workspace_builder + workspace_test: + extends: + file: docker-compose.yaml + service: workspace_test + agent: + extends: + file: docker-compose.yaml + service: agent + bridge: + extends: + file: docker-compose.yaml + service: bridge + rest_api: + extends: + file: docker-compose.yaml + service: rest_api + drivers: + extends: + file: docker-compose.yaml + service: drivers + + ##################################### + # Developer specific configuration + # Uses the "dev" profile + ##################################### + dev: + extends: base + build: + target: dev + # This image deliberately has no user prefix because it should not be pushed! + stdin_open: true + tty: true + privileged: true + # Allows use of gdbserver + security_opt: + - seccomp:unconfined + volumes: + - ${HOME}/.ros/log_moveit_studio:/root/.ros/log:/root/.ros/log + # Mount source code + - ./src/:/opt/custom_ws/src/:rw + # Mount anonymous volumes to build cache and artifacts + - /opt/custom_ws/build + - /opt/custom_ws/install + - /opt/custom_ws/log + - /root/.ccache + # Allow access to host hardware e.g. RealSense cameras + - /dev:/dev + command: sleep infinity + profiles: ["dev"] diff --git a/docker-compose.yaml b/docker-compose.yaml index 3e708e1a..1906bdd5 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -62,14 +62,11 @@ services: # Allow the user to run graphical programs from within the docker container. - /tmp/.X11-unix:/tmp/.X11-unix:ro - ${XAUTHORITY:-$HOME/.Xauthority}:/root/.Xauthority - # Persist Ignition model download cache - - ignition_resources:/root/.ignition/ # Mount the host's DDS config(s) so we can talk to user's ROS tooling - ${CYCLONEDDS_URI:-/dev/null}:/root/.ros/cyclonedds_host.xml - ${FASTRTPS_DEFAULT_PROFILES_FILE:-/dev/null}:/root/.ros/fastdds_host.xml workspace_builder: - container_name: "moveit_studio_workspace_builder" extends: base depends_on: base: @@ -77,7 +74,6 @@ services: command: bash -c "source /build_user_ws.sh" workspace_test: - container_name: "moveit_studio_workspace_test" extends: base depends_on: workspace_builder: @@ -88,7 +84,6 @@ services: # Starts the MoveIt Studio Agent agent: - container_name: "moveit_studio" extends: base privileged: true device_cgroup_rules: @@ -109,7 +104,6 @@ services: # Starts the Bridge between the Agent and the Web UI bridge: - container_name: "moveit_studio_bridge" extends: base depends_on: workspace_builder: @@ -121,7 +115,6 @@ services: # Starts the frontend-agent frontend_agent: - container_name: "moveit_studio_frontend" extends: base depends_on: workspace_builder: @@ -130,7 +123,6 @@ services: # Starts the REST API for the Web UI rest_api: - container_name: "moveit_studio_rest_api" extends: base environment: - LOG_LEVEL=DEBUG @@ -146,7 +138,6 @@ services: # Starts the robot drivers drivers: - container_name: "moveit_studio_drivers" extends: base privileged: true devices: @@ -158,7 +149,6 @@ services: command: bash -c "ros2 launch moveit_studio_agent robot_drivers_wrapper.launch.py 2>&1 | tee ~/.ros/log/robot_0_0.log" web_ui: - container_name: "moveit_studio_web_ui" image: ghcr.io/picknikrobotics/moveit-studio-frontend:${STUDIO_DOCKER_TAG:-main} ports: - "80:80" @@ -170,6 +160,3 @@ services: depends_on: base: condition: service_completed_successfully - -volumes: - ignition_resources: From 3280636c2b1ebf5623efe404f997d520aa5e49bd Mon Sep 17 00:00:00 2001 From: Sebastian Castro Date: Fri, 24 Mar 2023 16:47:44 -0400 Subject: [PATCH 2/2] Erik PR comments --- .docker/entrypoint-dev.sh | 10 +++++++--- .docker/entrypoint-release.sh | 3 ++- Dockerfile | 22 +++++++++++----------- docker-compose-overlay.yaml | 4 ++-- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/.docker/entrypoint-dev.sh b/.docker/entrypoint-dev.sh index 3b8ca991..fca194ec 100755 --- a/.docker/entrypoint-dev.sh +++ b/.docker/entrypoint-dev.sh @@ -8,13 +8,17 @@ set -e shopt -s expand_aliases source "/common_aliases.sh" -if [[ -f ${CUSTOM_WS}/install/setup.bash ]] +# If the custom workspace has been compiled we will source the setup.bash file. +# Otherwise it is up to the developer to compile and source it in their session. +if [[ -f ${MOVEIT_STUDIO_CUSTOM_WS}/install/setup.bash ]] then echo "Sourcing custom workspace" - source "${CUSTOM_WS}/install/setup.bash" - /copy_dds_configs.sh + source "${MOVEIT_STUDIO_CUSTOM_WS}/install/setup.bash" else echo -e "Custom workspace is not built. Please build it with: \ncolcon build\n" fi +# Copies a DDS configuration file from the user's environment, if available. +/copy_dds_configs.sh + exec "$@" diff --git a/.docker/entrypoint-release.sh b/.docker/entrypoint-release.sh index 4df17904..a14cc8e5 100755 --- a/.docker/entrypoint-release.sh +++ b/.docker/entrypoint-release.sh @@ -4,8 +4,9 @@ set -e -source "${CUSTOM_WS}/install/setup.bash" +source "${MOVEIT_STUDIO_CUSTOM_WS}/install/setup.bash" +# Copies a DDS configuration file from the user's environment, if available. /copy_dds_configs.sh exec "$@" diff --git a/Dockerfile b/Dockerfile index addd403f..612d7fb6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,13 +18,13 @@ ARG MOVEIT_STUDIO_BASE_IMAGE FROM ${MOVEIT_STUDIO_BASE_IMAGE} as base # The location of the user's custom workspace inside the container -ARG CUSTOM_WS=/opt/custom_ws -ENV CUSTOM_WS $CUSTOM_WS +ARG MOVEIT_STUDIO_CUSTOM_WS=/opt/custom_ws +ENV MOVEIT_STUDIO_CUSTOM_WS $MOVEIT_STUDIO_CUSTOM_WS # Copy site configuration packages and and dependencies -RUN mkdir -p ${CUSTOM_WS}/src -COPY ./src $CUSTOM_WS/src -WORKDIR $CUSTOM_WS +RUN mkdir -p ${MOVEIT_STUDIO_CUSTOM_WS}/src +COPY ./src $MOVEIT_STUDIO_CUSTOM_WS/src +WORKDIR $MOVEIT_STUDIO_CUSTOM_WS # Install additional ROS dependencies # NOTE: The "OVERLAY_WS" contains MoveIt Studio binary packages and the source file. @@ -40,9 +40,9 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ ################################################# # Target for compiled, deployable release image # ################################################# -FROM base as release +FROM base as moveit-studio-custom-release -WORKDIR $CUSTOM_WS +WORKDIR $MOVEIT_STUDIO_CUSTOM_WS # Compile the workspace # hadolint ignore=SC1091 @@ -60,12 +60,12 @@ CMD ["/usr/bin/bash"] ################################################################### # Expected to mount workspace and compile/test it # inside of the resulting container. -FROM base as dev +FROM base as moveit-studio-custom-dev # The location of the user's workspace inside the container -ARG CUSTOM_WS=/opt/custom_ws -ENV CUSTOM_WS $CUSTOM_WS -WORKDIR $CUSTOM_WS +ARG MOVEIT_STUDIO_CUSTOM_WS=/opt/custom_ws +ENV MOVEIT_STUDIO_CUSTOM_WS $MOVEIT_STUDIO_CUSTOM_WS +WORKDIR $MOVEIT_STUDIO_CUSTOM_WS # Install any additional packages for development work # hadolint ignore=DL3008 diff --git a/docker-compose-overlay.yaml b/docker-compose-overlay.yaml index 2580394d..f4ea6022 100644 --- a/docker-compose-overlay.yaml +++ b/docker-compose-overlay.yaml @@ -7,7 +7,7 @@ services: # Optionally allow building this service from source with `docker compose build` build: context: . - target: release + target: moveit-studio-custom-release args: MOVEIT_STUDIO_BASE_IMAGE: ghcr.io/picknikrobotics/moveit-studio:${STUDIO_DOCKER_TAG:-main} command: sleep infinity @@ -45,7 +45,7 @@ services: dev: extends: base build: - target: dev + target: moveit-studio-custom-dev # This image deliberately has no user prefix because it should not be pushed! stdin_open: true tty: true