Skip to content

Commit e717e86

Browse files
committed
Adding initial docker files
1 parent 52cb3a5 commit e717e86

File tree

6 files changed

+259
-0
lines changed

6 files changed

+259
-0
lines changed

docker/bash_aliases.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Aliases for the ~/.bashrc file
2+
alias build='cd ~/ros2_ws/ && colcon build && source ~/.bashrc'
3+
alias cleanup='echo "Cleaning up..." && \
4+
sleep 5.0 && \
5+
pkill -9 -f "ros2|demo_nova_sanctum"'
6+
alias elephant='ros2 launch mycobot_description robot_state_publisher.launch.py'
7+
alias ars_system='ros2 launch demo_nova_sanctum ars_systems_v2.launch.py'
8+
alias ogs_system='ros2 launch demo_nova_sanctum ogs_systems_v2.launch.py'
9+
alias wrs_system='ros2 launch demo_nova_sanctum wrs_systems.launch.py'

docker/build.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
3+
# Get the absolute path of the directory containing this script (docker directory)
4+
SCRIPT_PATH=$(dirname $(realpath "$0"))
5+
6+
# Get the parent directory path (mycobot_ros2 directory)
7+
# This is where our actual ROS 2 package code lives
8+
PARENT_PATH=$(dirname "$SCRIPT_PATH")
9+
10+
# Function to build the Docker image
11+
# This function handles the actual Docker build process
12+
build_docker_image()
13+
{
14+
# Set a log message for the build process
15+
LOG="Building Docker image nova_sanctum:latest ..."
16+
17+
# Print the log message using our debug function
18+
print_debug
19+
20+
# Build the Docker image
21+
# -f $SCRIPT_PATH/Dockerfile: Specify the path to the Dockerfile in the docker directory
22+
# -t nova_sanctum:latest: Tag the image as nova_sanctum:latest
23+
# $PARENT_PATH: Use the parent directory as the build context, allowing access to all package files
24+
# --no-cache: Build the image without using the cache, ensuring fresh dependencies
25+
sudo docker image build -f $SCRIPT_PATH/Dockerfile -t nova_sanctum:latest $PARENT_PATH --no-cache
26+
}
27+
28+
# Function to create a shared folder
29+
# This folder will be used to share files between the host and the Docker container
30+
create_shared_folder()
31+
{
32+
# Check if the directory doesn't exist
33+
if [ ! -d "$HOME/siddarth/shared/ros2" ]; then
34+
# Set a log message for folder creation
35+
LOG="Creating $HOME/siddarth/shared/ros2 ..."
36+
37+
# Print the log message
38+
print_debug
39+
40+
# Create the directory and its parent directories if they don't exist
41+
# -p flag creates parent directories as needed
42+
mkdir -p $HOME/siddarth/shared/ros2
43+
fi
44+
}
45+
46+
# Function to print debug messages
47+
# This provides consistent formatting for our log messages
48+
print_debug()
49+
{
50+
# Print an empty line for readability
51+
echo ""
52+
53+
# Print the log message
54+
echo $LOG
55+
56+
# Print another empty line for readability
57+
echo ""
58+
}
59+
60+
# Main execution flow
61+
62+
# First, create the shared folder that will be mounted in the container
63+
create_shared_folder
64+
65+
# Then, build the Docker image
66+
build_docker_image

docker/docker-compose.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
version: '3.3'
2+
services:
3+
eclss_base: &eclss_base
4+
image: nova_sanctum # Use the built image name
5+
ipc: host
6+
network_mode: host
7+
privileged: true
8+
environment:
9+
- DISPLAY
10+
- XAUTHORITY=/tmp/.Xauthority
11+
volumes:
12+
- $HOME/siddarth/shared/ros2:/root/shared/ros2
13+
- $HOME/.Xauthority:/tmp/.Xauthority
14+
- /tmp/.X11-unix:/tmp/.X11-unix:rw
15+
- /dev:/dev
16+
command: ["/bin/bash", "-c", "source /opt/ros/humble/setup.bash && source /root/ros2_ws/install/setup.bash && tail -f /dev/null"] # Keeps container running
17+
18+
collector:
19+
<<: *eclss_base
20+
container_name: collector
21+
command: ["ros2", "run", "demo_nova_sanctum", "collector"]
22+
23+
desiccant:
24+
<<: *eclss_base
25+
container_name: desiccant
26+
command: ["ros2", "run", "demo_nova_sanctum", "desiccant"]
27+
28+
adsorbent:
29+
<<: *eclss_base
30+
container_name: adsorbent
31+
command: ["ros2", "run", "demo_nova_sanctum", "adsorbent"]
32+
33+
sabatier:
34+
<<: *eclss_base
35+
container_name: sabatier
36+
command: ["ros2", "run", "demo_nova_sanctum", "sabatier"]
37+
38+
water_pub:
39+
<<: *eclss_base
40+
container_name: water_pub
41+
command: ["ros2", "run", "demo_nova_sanctum", "water_pub"]
42+
43+
deionization_bed:
44+
<<: *eclss_base
45+
container_name: deionization_bed
46+
command: ["ros2", "run", "demo_nova_sanctum", "deionization_bed"]
47+
48+
electrolysis:
49+
<<: *eclss_base
50+
container_name: electrolysis
51+
command: ["ros2", "run", "demo_nova_sanctum", "electrolysis"]
52+
53+
whc:
54+
<<: *eclss_base
55+
container_name: whc
56+
command: ["ros2", "run", "demo_nova_sanctum", "whc"]
57+
58+
waste_collector:
59+
<<: *eclss_base
60+
container_name: waste_collector
61+
command: ["ros2", "run", "demo_nova_sanctum", "waste_collector"]
62+
63+
upa:
64+
<<: *eclss_base
65+
container_name: upa
66+
command: ["ros2", "run", "demo_nova_sanctum", "upa"]
67+
68+
filter:
69+
<<: *eclss_base
70+
container_name: filter
71+
command: ["ros2", "run", "demo_nova_sanctum", "filter"]
72+
73+
catalytic_chamber:
74+
<<: *eclss_base
75+
container_name: catalytic_chamber
76+
command: ["ros2", "run", "demo_nova_sanctum", "catalytic_chamber"]
77+
78+
ionization:
79+
<<: *eclss_base
80+
container_name: ionization
81+
command: ["ros2", "run", "demo_nova_sanctum", "ionization"]
82+
83+
clean_water_tank:
84+
<<: *eclss_base
85+
container_name: clean_water_tank
86+
command: ["ros2", "run", "demo_nova_sanctum", "clean_water_tank"]
87+
88+
ultrasound:
89+
<<: *eclss_base
90+
container_name: ultrasound
91+
command: ["ros2", "run", "demo_nova_sanctum", "ultrasound"]

docker/dockerfile

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Set the ROS distribution as an argument, defaulting to 'jazzy'
2+
ARG ROS_DISTRO=humble
3+
4+
# The base image comes from the official ROS repository hosted on Docker Hub
5+
# You can find available ROS images here: https://hub.docker.com/_/ros/tags
6+
# We're using the ros-base image which includes core ROS 2 packages
7+
FROM ros:${ROS_DISTRO}-ros-base
8+
9+
# Set the maintainer information for this Dockerfile
10+
LABEL maintainer="AutomaticAddison<[email protected]>"
11+
12+
# Set environment variables
13+
ENV PIP_BREAK_SYSTEM_PACKAGES=1
14+
ENV DEBIAN_FRONTEND=noninteractive
15+
16+
# Set the default shell to bash for RUN commands
17+
# This ensures all RUN commands use bash instead of sh
18+
SHELL ["/bin/bash", "-c"]
19+
20+
# Update the system and install essential tools
21+
# This step upgrades all packages and installs utilities needed for development
22+
RUN apt-get update -q && \
23+
apt-get upgrade -yq && \
24+
apt-get install -yq --no-install-recommends apt-utils wget curl git build-essential \
25+
vim sudo lsb-release locales bash-completion tzdata gosu gedit htop nano libserial-dev
26+
27+
# Install additional tools required for ROS 2 development
28+
# These packages help with building and managing ROS 2 workspaces
29+
RUN apt-get update -q && \
30+
apt-get install -y gnupg2 iputils-ping usbutils \
31+
python3-argcomplete python3-colcon-common-extensions python3-networkx python3-pip python3-rosdep python3-vcstool
32+
33+
# Set up the ROS 2 environment
34+
# This ensures that ROS 2 commands are available in the shell
35+
# rosdep is a tool for installing system dependencies for ROS packages
36+
RUN rosdep update && \
37+
grep -F "source /opt/ros/${ROS_DISTRO}/setup.bash" /root/.bashrc || echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> /root/.bashrc && \
38+
grep -F "source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash" /root/.bashrc || echo "source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash" >> /root/.bashrc
39+
40+
# Install additional ROS 2 packages
41+
RUN apt-get update && \
42+
apt-get install -y \
43+
ros-${ROS_DISTRO}-joint-state-publisher-gui \
44+
ros-${ROS_DISTRO}-xacro \
45+
ros-${ROS_DISTRO}-demo-nodes-cpp \
46+
ros-${ROS_DISTRO}-demo-nodes-py \
47+
ros-${ROS_DISTRO}-rviz2 \
48+
ros-${ROS_DISTRO}-rqt-reconfigure
49+
50+
# Install Mesa graphics drivers
51+
# Mesa is an open-source implementation of OpenGL and other graphics APIs
52+
# It's crucial for 3D rendering in many applications, including RViz in ROS
53+
RUN apt-get update && \
54+
apt-get install -y software-properties-common && \
55+
DEBIAN_FRONTEND=noninteractive add-apt-repository ppa:kisak/kisak-mesa
56+
57+
# Create necessary directories
58+
RUN mkdir -p /etc/udev/rules.d && \
59+
mkdir -p /root/ros2_ws/src/demo_nova_sanctum
60+
61+
# Copy the entire project into the container
62+
# Since we're using the parent directory as context, we can copy everything
63+
COPY . /root/ros2_ws/src/demo_nova_sanctum
64+
65+
# Copy configuration files from docker directory
66+
# Note the docker/ prefix since we're in the parent context
67+
COPY docker/workspace.sh /root/
68+
COPY docker/entrypoint.sh /root/
69+
COPY docker/bash_aliases.txt /root/.bashrc_aliases
70+
71+
# Make scripts executable
72+
RUN chmod +x /root/workspace.sh /root/entrypoint.sh
73+
74+
# Add custom bash aliases
75+
RUN cat /root/.bashrc_aliases >> /root/.bashrc
76+
77+
# Run the workspace setup script
78+
# This typically installs workspace dependencies and builds the ROS 2 packages
79+
WORKDIR /root
80+
RUN ./workspace.sh
81+
82+
# Ensure the ROS 2 workspace is sourced in every new shell
83+
RUN echo "source /root/ros2_ws/install/setup.bash" >> /root/.bashrc
84+
85+
# Set the entrypoint for the container
86+
# This script will be run every time the container starts
87+
ENTRYPOINT ["/root/entrypoint.sh"]
88+
89+
# Set the default command
90+
# This keeps the container running indefinitely, allowing you to exec into it
91+
RUN echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
92+
RUN echo "source /root/ros2_ws/install/setup.bash" >> ~/.bashrc
93+
CMD ["/bin/bash", "-c", "tail -f /dev/null"]

docker/entrypoint.sh

Whitespace-only changes.

docker/workspace.sh

Whitespace-only changes.

0 commit comments

Comments
 (0)