Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Cleanup user overlay Docker example #133

Merged
merged 10 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 26 additions & 32 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,19 @@ ARG USER_GID=1000
# hadolint ignore=DL3006
FROM ${MOVEIT_STUDIO_BASE_IMAGE} as base

# hadolint ignore=DL3002
USER root

# Copy source code from the workspace's ROS 2 packages to a workspace inside the container
ARG USER_OVERLAY_WS=/opt/user_overlay_ws
ENV USER_OVERLAY_WS $USER_OVERLAY_WS
RUN mkdir -p ${USER_OVERLAY_WS}/src ${USER_OVERLAY_WS}/build ${USER_OVERLAY_WS}/install ${USER_OVERLAY_WS}/log
COPY ./src ${USER_OVERLAY_WS}/src

# Create a non-root user
ARG USERNAME
ARG USER_UID
ARG USER_GID

# Copy source code from the workspace's ROS 2 packages to a workspace inside the container
ARG USER_WS=/home/${USERNAME}/user_overlay_ws
ENV USER_WS=${USER_WS}
RUN mkdir -p ${USER_WS}/src ${USER_WS}/build ${USER_WS}/install ${USER_WS}/log
COPY ./src ${USER_WS}/src

# Also mkdir with user permission directories which will be mounted later to avoid docker creating them as root
WORKDIR $USER_OVERLAY_WS
WORKDIR $USER_WS
# hadolint ignore=DL3008
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
Expand All @@ -43,12 +40,14 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
apt-get install -q -y --no-install-recommends sudo && \
echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} && \
chmod 0440 /etc/sudoers.d/${USERNAME} && \
cp -r /etc/skel/. /home/${USERNAME} && \
mkdir -p \
/home/${USERNAME}/.ccache \
/home/${USERNAME}/.config \
/home/${USERNAME}/.ignition \
/home/${USERNAME}/.ros/log && \
chown -R $USER_UID:$USER_GID /home/${USERNAME} ${USER_OVERLAY_WS} /opt/overlay_ws/
/home/${USERNAME}/.colcon \
/home/${USERNAME}/.ros && \
chown -R $USER_UID:$USER_GID /home/${USERNAME} /opt/overlay_ws/

# Install additional dependencies
# You can also add any necessary apt-get install, pip install, etc. commands at this point.
Expand All @@ -62,40 +61,39 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--from-paths src \
--ignore-src

# Remove .bashrc from parent image and create a new one
USER ${USERNAME}
RUN rm /home/${USERNAME}/.bashrc && touch /home/${USERNAME}/.bashrc
# Remove duplicated serial dependency install files, otherwise there will be a build error.
# NOTE: This can be removed when MoveIt Studio fully separates core and hardware capabilities.
WORKDIR /opt/overlay_ws
RUN rm -rf build/serial install/serial

#########################################
# Target for compiled, deployable image #
#########################################
FROM base as user-overlay

ARG USERNAME
USER ${USERNAME}
ARG USER_WS=/home/${USERNAME}/user_overlay_ws
ENV USER_WS=${USER_WS}

# Compile the workspace
WORKDIR $USER_WS
# hadolint ignore=SC1091
RUN --mount=type=cache,target=/home/studio-user/.ccache \
RUN --mount=type=cache,target=/home/${USERNAME}/.ccache \
. /opt/overlay_ws/install/setup.sh && \
colcon build

# Add the custom entrypoint
COPY ./entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
RUN echo "source /entrypoint.sh && set +e" >> ~/.bashrc
# Set up the user's .bashrc file and shell.
# RUN echo "source /moveit_studio_utils/setup_workspaces.sh && set +e" >> /home/${USERNAME}/.bashrc
CMD ["/usr/bin/bash"]

###################################################################
# Target for the developer build which does not compile any code. #
###################################################################
FROM base as user-overlay-dev

USER root

# The location of the user's workspace inside the container
ARG USER_OVERLAY_WS=/opt/user_overlay_ws
ENV USER_OVERLAY_WS $USER_OVERLAY_WS
ARG USERNAME
ARG USER_WS=/home/${USERNAME}/user_overlay_ws
ENV USER_WS=${USER_WS}

# Install any additional packages for development work
# hadolint ignore=DL3008
Expand All @@ -107,10 +105,6 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
gdb \
nano

# Add the dev entrypoint
ARG USERNAME
USER ${USERNAME}
COPY ./entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
RUN echo "source /entrypoint.sh && set +e" >> ~/.bashrc
# Set up the user's .bashrc file and shell.
# RUN echo "source /moveit_studio_utils/setup_workspaces.sh && set +e" >> /home/${USERNAME}/.bashrc
CMD ["/usr/bin/bash"]
Empty file removed build/.gitkeep
Empty file.
23 changes: 11 additions & 12 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ services:
- USER_GID=${STUDIO_USER_UID:-1000}
- USERNAME=${USERNAME:-studio-user}
- MOVEIT_STUDIO_BASE_IMAGE=picknikciuser/moveit-studio:${STUDIO_DOCKER_TAG:-main}
# Set the user workspace folder location.
environment:
- USER_WS=/home/${USERNAME:-studio-user}/user_overlay_ws

# Starts the MoveIt Studio Agent and the Bridge between the Agent and the Web UI
agent_bridge:
Expand All @@ -44,12 +47,7 @@ services:
delay: 2s
command: agent_bridge.app

# Starts the frontend-agent
frontend_agent:
extends: base
command: /usr/lib/formant/agent/formant-agent

# Starts the REST API for the Web UI
# Starts the REST API for the Web UI.
rest_api:
extends: base
healthcheck:
Expand All @@ -58,7 +56,7 @@ services:
timeout: 1m
command: rest_api.app

# Starts the robot drivers
# Starts the robot drivers.
drivers:
extends: base
privileged: true
Expand All @@ -69,6 +67,7 @@ services:
- "/dev/ttyUSB0:/dev/ttyUSB0" # Allow access to the gripper.
command: robot.app

# Starts the web UI frontend.
web_ui:
image: picknikciuser/moveit-studio-frontend:${STUDIO_DOCKER_TAG:-main}
ports:
Expand Down Expand Up @@ -100,12 +99,12 @@ services:
privileged: true
volumes:
# Mount the source code, colcon generated artifacts, and ccache
- ./src/:/opt/user_overlay_ws/src:rw
- ./build/:/opt/user_overlay_ws/build:rw
- ./install/:/opt/user_overlay_ws/install:rw
- ./log/:/opt/user_overlay_ws/log:rw
- ./src/:/home/${USERNAME:-studio-user}/user_overlay_ws/src:rw
- ./build/:/home/${USERNAME:-studio-user}/user_overlay_ws/build:rw
- ./install/:/home/${USERNAME:-studio-user}/user_overlay_ws/install:rw
- ./log/:/home/${USERNAME:-studio-user}/user_overlay_ws/log:rw
- ./.ccache/:/home/${USERNAME:-studio-user}/.ccache:rw
- ${HOME}/.ros/log_moveit_studio:/root/.ros/log:/root/.ros/log
- ${HOME}/.ros/log_moveit_studio:/home/${USERNAME:-studio-user}/.ros/log
# Allow access to host hardware e.g. RealSense cameras
- /dev:/dev
command: sleep infinity
Expand Down
24 changes: 0 additions & 24 deletions entrypoint.sh

This file was deleted.

Empty file removed install/.gitkeep
Empty file.
Empty file removed log/.gitkeep
Empty file.
9 changes: 9 additions & 0 deletions src/external_dependencies/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# Disable all checks in this folder.
# At least one check must be enabled to avoid errors, though.
Checks: '-*,
cppcoreguidelines-avoid-goto,
'
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
...