Skip to content

Commit

Permalink
Added Dockerfile
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Tudela <[email protected]>
  • Loading branch information
ajtudela committed Oct 14, 2024
1 parent 451bca7 commit aa86d3f
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
################################################################################
# Repo

.git/
.gitignore
62 changes: 62 additions & 0 deletions .github/workflows/docker_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Docker Image

on:
workflow_dispatch:
workflow_run:
workflows: ["Build"]
types:
- completed

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
dsr-image:
runs-on: ubuntu-latest
steps:
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Checkout
uses: actions/[email protected]

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
images: grupoavispa/scitos2
tags: |
type=ref, suffix=latest, event=branch
type=sha
- name: Docker Setup Buildx
uses: docker/[email protected]
id: scitos2-builder

- name: Cache Docker layers
uses: actions/[email protected]
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build against scitos2-builder
uses: docker/[email protected]
with:
builder: ${{ steps.scitos2-builder.outputs.name }}
context: docker
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
71 changes: 71 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
ARG BASE_IMAGE="humble-ros-core-jammy"
ARG MIRA_WS=/opt/mira
ARG OVERLAY_WS=/opt/overlay_ws
ARG SYSTEM=ubuntu-2204lts-x64

# Install MIRA
FROM ubuntu:22.04 AS mira-base
ARG DEBIAN_FRONTEND=noninteractive
ARG MIRA_WS
ARG SYSTEM
RUN apt update && apt install --no-install-recommends -y \
ca-certificates cmake curl doxygen g++ git subversion unzip wget \
libxml2-dev libssl-dev \
libsqlite3-dev libboost-all-dev \
libogre-1.9-dev libsvn-dev \
libopencv-dev binutils-dev \
libiberty-dev libcurl4-gnutls-dev libprocps-dev \
libqwt-qt5-dev libqt5webkit5-dev libqwtmathml-qt5-dev \
libqt5opengl5-dev libqt5svg5-dev qt*5-dev qttools5-dev-tools && \
rm -rf /var/lib/apt/lists/*
RUN curl -o mira-installer-binary.sh https://www.mira-project.org/downloads/mira-installer-binary.sh
RUN chmod +x mira-installer-binary.sh
RUN ./mira-installer-binary.sh -s ${SYSTEM} -d ${MIRA_WS}
# Setup MIRA environment variables
ENV MIRA_PATH=${MIRA_WS}
ENV PATH=$PATH:${MIRA_WS}/bin
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${MIRA_WS}/lib
# Install SCITOS and Tory Configs
RUN mirapackage --addurl ftp://ftp.metralabs-service.com/repos/MIRA-commercial/${SYSTEM}/MIRA-commercial.repo
RUN mirapackage -R
RUN mirapackage --noninteractive -I CANDriver SCITOS SCITOSConfigs ToryConfig

# Build Scitos2
FROM ros:${BASE_IMAGE} AS scitos2-base
ARG MIRA_WS
ARG OVERLAY_WS
ENV MIRA_PATH=${MIRA_WS}
COPY --from=mira-base ${MIRA_WS} ${MIRA_WS}
WORKDIR $OVERLAY_WS
RUN mkdir -p src
COPY . ./src/scitos2

# Install MIRA and ROS2 dependencies
RUN apt update && apt install --no-install-recommends -y \
libopencv-dev libprocps-dev \
python3-pip \
ros-dev-tools \
python3-vcstool \
python3-colcon-clean \
ros-$ROS_DISTRO-rmw-cyclonedds-cpp
RUN vcs import src < src/scitos2/.github/repos.repos
RUN rosdep init && rosdep update
RUN . /opt/ros/$ROS_DISTRO/setup.sh && \
rosdep install -q -y --from-paths src --ignore-src --rosdistro $ROS_DISTRO && \
rm -rf /var/lib/apt/lists/*
RUN . /opt/ros/$ROS_DISTRO/setup.sh && colcon build
RUN colcon clean workspace --base-select build -y

FROM scitos2-base AS final
ARG MIRA_WS
ARG OVERLAY_WS
ENV MIRA_WS=${MIRA_WS}
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${MIRA_WS}/lib
ENV OVERLAY_WS=${OVERLAY_WS}

WORKDIR $OVERLAY_WS/src/scitos2
COPY ./docker/ros_entrypoint.sh /
RUN chmod +x /ros_entrypoint.sh
COPY ./docker/cyclonedds.xml /
ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["ros2", "launch", "scitos2_mira", "mira.launch.py"]
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
`scitos2` is a ROS 2 stack designed for Metralabs robots that utilize the MIRA framework, including models such as SCITOS, TORY, MORPHIA, etc. This stack comprises several packages, each serving a unique purpose:

* [scitos2_behavior_tree]: This package contains behavior tree nodes that extend your robot's functionalities, such as emergency stop, reset motor stop, etc.
* [scito2_charging_dock]: This package contains the implementation of the charging dock plugin for the SCITOS and TORY robots from MetraLabs using the opennav_docking server.
* [scitos2_charging_dock]: This package contains the implementation of the charging dock plugin for the SCITOS and TORY robots from MetraLabs using the opennav_docking server.
* [scitos2_common]: This package provides common functionalities for the scitos2 stack.
* [scitos2_core]: This package provides the abstract interface (virtual base classes) for the Scitos Modules.
* [scitos2_mira]: This is the main node that interfaces with the MIRA framework.
Expand All @@ -37,8 +37,35 @@ rosdep install -i --from-path src --rosdistro rolling -y
colcon build --symlink-install
```

### Docker

A Dockerfile is provided in the repository to build the `scitos2` stack. This setup ensures that you have a consistent and isolated environment. The image sets a launch file to start the `mira_framework` with the default configuration file: `drive` and `charger` modules. This configuration can be modified by changing the `CMD` instruction in the Dockerfile.

To build and run the `scitos2` stack using Docker, follow these steps:

#### Building the Docker image

First, build the Docker image using the provided Dockerfile in the repository:
```bash
cd /path/to/scitos2
docker build -t grupoavispa/scitos2:latest .
```

#### Running the Docker container

Once the image is built, you can run the container using the docker compose file provided in the repository. Before running the container:
- Install the `udev` rules on your host machine to allow the container to access the robot's hardware.
- Make sure the license file is in the `/opt/MIRA-licenses` directory on your host machine.
- Install the configuration files for the robot in the `/opt/SCITOS` directory on your host machine.
- Update the `docker-compose.yml` file by replacing the XXX placeholders with the correct elements.

Then, run the container using the following command:
```bash
docker-compose up
```

[scitos2_behavior_tree]: /scitos2_behavior_tree
[scito2_charging_dock]: /scitos2_charging_dock
[scitos2_charging_dock]: /scitos2_charging_dock
[scitos2_common]: /scitos2_common
[scitos2_core]: /scitos2_core
[scitos2_mira]: /scitos2_mira
Expand Down
19 changes: 19 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
scitos:
container_name: scitos2
image: grupoavispa/scitos2:latest
build: .
network_mode: host
ipc: host
pid: host
mac_address: XX:XX:XX:XX:XX:XX
environment:
- ROS_DOMAIN_ID=${ROS_DOMAIN_ID}
- NET_INTERFACE=XXXXX
devices:
- /dev/ttyUSB2:/dev/USB_MLCAN
privileged: true
restart: unless-stopped
volumes:
- /opt/MIRA-licenses:/opt/MIRA-licenses
- /opt/SCITOS:/opt/SCITOS
10 changes: 10 additions & 0 deletions docker/cyclonedds.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CycloneDDS xmlns="https://cdds.io/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://cdds.io/config https://raw.githubusercontent.com/eclipse-cyclonedds/cyclonedds/master/etc/cyclonedds.xsd">
<Domain id='any'>
<General>
<Interfaces>
<NetworkInterface name="${NET_INTERFACE}"/>
</Interfaces>
</General>
</Domain>
</CycloneDDS>
16 changes: 16 additions & 0 deletions docker/ros_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -e

######### ROS #########
source /opt/ros/${ROS_DISTRO}/setup.bash
source ${OVERLAY_WS}/install/local_setup.bash
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
export CYCLONEDDS_URI=/cyclonedds.xml

######### MIRA #########
export MIRA_PATH=${MIRA_WS}
export PATH=$PATH:${MIRA_WS}/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${MIRA_WS}/lib
source ${MIRA_WS}/scripts/mirabash

exec "$@"

0 comments on commit aa86d3f

Please sign in to comment.