|
| 1 | +# Docker image for extending MoveIt Pro with a custom overlay. |
| 2 | +# |
| 3 | +# Example build command (with defaults): |
| 4 | +# |
| 5 | +# docker build -f ./Dockerfile . |
| 6 | +# |
| 7 | + |
| 8 | +# Specify the MoveIt Pro release to build on top of. |
| 9 | +ARG MOVEIT_STUDIO_BASE_IMAGE |
| 10 | +ARG USERNAME=studio-user |
| 11 | +ARG USER_UID=1000 |
| 12 | +ARG USER_GID=1000 |
| 13 | + |
| 14 | +################################################## |
| 15 | +# Starting from the specified MoveIt Pro release # |
| 16 | +################################################## |
| 17 | +# The image tag is specified in the argument itself. |
| 18 | +# hadolint ignore=DL3006 |
| 19 | +FROM ${MOVEIT_STUDIO_BASE_IMAGE} AS base |
| 20 | + |
| 21 | +# Create a non-root user |
| 22 | +ARG USERNAME |
| 23 | +ARG USER_UID |
| 24 | +ARG USER_GID |
| 25 | + |
| 26 | +# Copy source code from the workspace's ROS 2 packages to a workspace inside the container |
| 27 | +ARG USER_WS=/home/${USERNAME}/user_ws |
| 28 | +ENV USER_WS=${USER_WS} |
| 29 | +RUN mkdir -p ${USER_WS}/src ${USER_WS}/build ${USER_WS}/install ${USER_WS}/log |
| 30 | +COPY ./src ${USER_WS}/src |
| 31 | + |
| 32 | +# Also mkdir with user permission directories which will be mounted later to avoid docker creating them as root |
| 33 | +WORKDIR $USER_WS |
| 34 | +# hadolint ignore=DL3008 |
| 35 | +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ |
| 36 | + --mount=type=cache,target=/var/lib/apt,sharing=locked \ |
| 37 | + groupadd --gid $USER_GID ${USERNAME} && \ |
| 38 | + useradd --uid $USER_UID --gid $USER_GID --shell /bin/bash --create-home ${USERNAME} && \ |
| 39 | + apt-get update && \ |
| 40 | + apt-get install -q -y --no-install-recommends sudo && \ |
| 41 | + echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} && \ |
| 42 | + chmod 0440 /etc/sudoers.d/${USERNAME} && \ |
| 43 | + cp -r /etc/skel/. /home/${USERNAME} && \ |
| 44 | + mkdir -p \ |
| 45 | + /home/${USERNAME}/.ccache \ |
| 46 | + /home/${USERNAME}/.config \ |
| 47 | + /home/${USERNAME}/.ignition \ |
| 48 | + /home/${USERNAME}/.colcon \ |
| 49 | + /home/${USERNAME}/.ros && \ |
| 50 | + chown -R $USER_UID:$USER_GID /home/${USERNAME} /opt/overlay_ws/ |
| 51 | + |
| 52 | +# IMPORTANT: Optionally install Nvidia drivers for improved simulator performance with Nvidia GPUs. |
| 53 | +# To do this you must |
| 54 | +# 1. Uncomment the ENV and RUN entries below |
| 55 | +# 2. Replace the 'nvidia-driver-555' apt package with the Nvidia driver version on your host, e.g. nvidia-driver-535, nvidia-driver-555. Use nvidia-smi on your host to determine the driver version. |
| 56 | +# After rebuilding via `moveit_pro build` verify the drivers are active in your container by running `nvidia_smi` inside of `moveit_pro shell`. |
| 57 | +# ENV DEBIAN_FRONTEND=noninteractive |
| 58 | +# RUN apt update && apt install -y software-properties-common |
| 59 | +# RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ |
| 60 | +# --mount=type=cache,target=/var/lib/apt,sharing=locked \ |
| 61 | +# add-apt-repository ppa:graphics-drivers/ppa && \ |
| 62 | +# apt update && apt upgrade -y && apt install -y nvidia-driver-555 |
| 63 | + |
| 64 | +# Install additional dependencies |
| 65 | +# You can also add any necessary apt-get install, pip install, etc. commands at this point. |
| 66 | +# NOTE: The /opt/overlay_ws folder contains MoveIt Pro binary packages and the source file. |
| 67 | +# hadolint ignore=SC1091 |
| 68 | +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ |
| 69 | + --mount=type=cache,target=/var/lib/apt,sharing=locked \ |
| 70 | + . /opt/overlay_ws/install/setup.sh && \ |
| 71 | + apt-get update && \ |
| 72 | + rosdep install -q -y \ |
| 73 | + --from-paths src \ |
| 74 | + --ignore-src |
| 75 | + |
| 76 | +# Set up colcon defaults for the new user |
| 77 | +USER ${USERNAME} |
| 78 | +RUN colcon mixin add default \ |
| 79 | + https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml && \ |
| 80 | + colcon mixin update && \ |
| 81 | + colcon metadata add default \ |
| 82 | + https://raw.githubusercontent.com/colcon/colcon-metadata-repository/master/index.yaml && \ |
| 83 | + colcon metadata update |
| 84 | +COPY colcon-defaults.yaml /home/${USERNAME}/.colcon/defaults.yaml |
| 85 | + |
| 86 | +# hadolint ignore=DL3002 |
| 87 | +USER root |
| 88 | + |
| 89 | +################################################################### |
| 90 | +# Target for the developer build which does not compile any code. # |
| 91 | +################################################################### |
| 92 | +FROM base AS user-overlay-dev |
| 93 | + |
| 94 | +ARG USERNAME |
| 95 | +ARG USER_WS=/home/${USERNAME}/user_ws |
| 96 | +ENV USER_WS=${USER_WS} |
| 97 | + |
| 98 | +# Install any additional packages for development work |
| 99 | +# hadolint ignore=DL3008 |
| 100 | +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ |
| 101 | + --mount=type=cache,target=/var/lib/apt,sharing=locked \ |
| 102 | + apt-get update && \ |
| 103 | + apt-get install -y --no-install-recommends \ |
| 104 | + less \ |
| 105 | + gdb \ |
| 106 | + nano |
| 107 | + |
| 108 | +# Set up the user's .bashrc file and shell. |
| 109 | +CMD ["/usr/bin/bash"] |
| 110 | + |
| 111 | +######################################### |
| 112 | +# Target for compiled, deployable image # |
| 113 | +######################################### |
| 114 | +FROM base AS user-overlay |
| 115 | + |
| 116 | +ARG USERNAME |
| 117 | +ARG USER_WS=/home/${USERNAME}/user_ws |
| 118 | +ENV USER_WS=${USER_WS} |
| 119 | + |
| 120 | +# Compile the workspace |
| 121 | +WORKDIR $USER_WS |
| 122 | + |
| 123 | +# Set up the user's .bashrc file and shell. |
| 124 | +CMD ["/usr/bin/bash"] |
0 commit comments