Skip to content

Commit

Permalink
Merge pull request #103 from hmakelin/add-custom-network
Browse files Browse the repository at this point in the history
Use Docker bridge networks instead of sharing host network
  • Loading branch information
hmakelin authored Feb 10, 2024
2 parents f041e62 + d104cba commit 21e029d
Show file tree
Hide file tree
Showing 18 changed files with 329 additions and 150 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,12 @@ include docker/Makefile

.PHONY: docs
docs:
mkdir -p docs/_build && \
d2 --font-regular="docs/_static/fonts/Poppins Regular.ttf" \
--theme=0 --dark-theme=200 \
--font-bold="docs/_static/fonts/Poppins Medium.ttf" \
--font-italic="docs/_static/fonts/Poppins Regular.ttf" \
docs/pages/developer_guide/offboard/_external_interfaces.d2 \
docs/_build/external_interfaces.html
@$(MAKE) -C docs html
@cd docs/_build/html && touch .nojekyll # for GitHub Pages
2 changes: 1 addition & 1 deletion docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ $(eval $(call compose_template,offboard-sitl-dev,offboard-sitl-middleware,,$$* q
$(eval $(call compose_template,demo,offboard-sitl-dev,,gisnav))

# List of Docker Compose service names that need GUI access
GUI_SERVICES = px4 ardupilot qgc rviz
GUI_SERVICES = px4 ardupilot qgc rviz qgis gisnav

# Expose xhost to containers that need GUI (see x11 extension in docker-compose.yaml)
expose-xhost:
Expand Down
59 changes: 36 additions & 23 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
version: "3.4"

networks:
gis:
driver: bridge
mavlink:
driver: bridge

x-mavlink-net: &mavlink-net
networks:
- mavlink

x-gis-net: &gis-net
networks:
- gis

x-all-net: &all-net
networks:
- mavlink
- gis

# platforms is a sequence not a mapping so careful when merging
# with something that defines its own platforms
x-base: &base
build:
dockerfile: Dockerfile
#platforms:
# - "linux/amd64"
network_mode: host
#networks:
# - gisnav-network
#network_mode: host

# devices is a sequence not a mapping so careful when merging
# with something that defines its own devices
Expand Down Expand Up @@ -44,7 +61,7 @@ x-tty: &tty

services:
mapserver:
<<: *base
<<: [*base, *gis-net]
build:
context: mapserver
args:
Expand All @@ -55,7 +72,7 @@ services:
command: /usr/local/bin/start-server

micro-ros-agent:
<<: [*base, *ros]
<<: [*base, *ros, *mavlink-net]
build:
context: micro-ros-agent
#platforms:
Expand All @@ -64,7 +81,7 @@ services:
command: udp4 -p 8888

mavros:
<<: [*base, *ros]
<<: [*base, *ros, *mavlink-net]
build:
context: mavros
args:
Expand All @@ -75,7 +92,7 @@ services:
command: ros2 run mavros mavros_node --ros-args --param fcu_url:=udp://:14540@localhost:14557

qgc:
<<: [*base, *x11]
<<: [*base, *x11, *mavlink-net]
build:
context: qgc
volumes:
Expand All @@ -87,8 +104,10 @@ services:
# Note: build context is repository root
# Note 2: The "docker buildx build" command in the push_gisnav_images.yml workflow
# duplicates these build arguments. They should be changed together.
# *x11 anchor is needed for debugging (cv2 visualization of matches) for this
# service
gisnav:
<<: [*base, *ros, *tty, *nvidia-gpu]
<<: [*base, *x11, *ros, *tty, *nvidia-gpu, *all-net]
#image: "ghcr.io/hmakelin/gisnav:${TAG:-latest}"
image: ghcr.io/hmakelin/gisnav:latest
build:
Expand All @@ -99,19 +118,17 @@ services:
command: ros2 launch gisnav px4.dev.launch.py

px4:
<<: [*base, *x11, *tty, *nvidia-gpu]
<<: [*base, *x11, *tty, *nvidia-gpu, *mavlink-net]
build:
context: px4
args:
ROS_VERSION: foxy
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix:ro
- /dev/shm:/dev/shm
- /dev/dri:/dev/dri
command: make px4_sitl gazebo-classic_typhoon_h480__ksql_airport

ardupilot:
<<: [*base, *x11, *nvidia-gpu]
<<: [*base, *x11, *nvidia-gpu, *mavlink-net]
build:
context: ardupilot
volumes:
Expand All @@ -123,15 +140,15 @@ services:

# Note: build context is repository root
rviz:
<<: [*base, *x11, *ros, *nvidia-gpu]
<<: [*base, *x11, *ros, *nvidia-gpu, *mavlink-net]
build:
context: rviz
args:
ROS_VERSION: humble
command: rviz2 -d gisnav_config.rviz

gscam:
<<: [*base, *ros]
<<: [*base, *ros, *mavlink-net]
build:
context: gscam
args:
Expand All @@ -148,7 +165,7 @@ services:
- "camera_info_url:=file:///camera_calibration.yaml"

autoheal:
<<: [*base]
<<: [*base, *all-net]
image: willfarrell/autoheal
restart: always
environment:
Expand All @@ -157,22 +174,18 @@ services:
- /var/run/docker.sock:/var/run/docker.sock

qgis:
<<: [*base, *x11]
<<: [*base, *x11, *gis-net]
build:
context: qgis
command: qgis

postgres:
<<: [ *base ]
<<: [*base, *gis-net]
build:
context: postgres
ports:
- "5432:5432" # Map PostgreSQL's default port to the host
#ports:
# - "5432:5432" # Map PostgreSQL's default port to the host
environment:
POSTGRES_DB: gisnav
POSTGRES_USER: gisnav
POSTGRES_PASSWORD: gisnav

#networks:
# gisnav-network:
# driver: bridge
5 changes: 4 additions & 1 deletion docker/gisnav/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN cd gisnav/gisnav && \

# TODO: no need to install egm96-5 separately after pygeodesy was refactored out in gisnav-gpu branch?
# Install GIS related dependencies
RUN apt-get -y install software-properties-common python3-pip wget && \
RUN apt-get -y install software-properties-common python3-pip wget curl && \
add-apt-repository ppa:ubuntugis/ppa && \
apt-get update && \
apt-get -y install gdal-bin libgdal-dev geographiclib-tools && \
Expand All @@ -46,6 +46,9 @@ RUN source /opt/ros/${ROS_VERSION}/setup.bash && \
cd .. && \
colcon build --packages-ignore mavros mavros_extras libmavconn

# Install D2 for building diagrams in docs
RUN curl -fsSL https://d2lang.com/install.sh | sh -s --

# TODO: proper health check - check that public facing topics are publishing
HEALTHCHECK --interval=10s --timeout=3s \
CMD /bin/bash -c "source /opt/ros/${ROS_VERSION}/setup.bash && \
Expand Down
8 changes: 4 additions & 4 deletions docker/gscam/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ FROM ros:${ROS_VERSION}
ARG ROS_VERSION
ENV ROS_VERSION=${ROS_VERSION}

COPY camera_calibration.yaml gscam_params.yaml /
COPY --chmod=755 entrypoint.sh /

RUN apt-get update && \
apt-get -y dist-upgrade && \
apt-get -y install gstreamer1.0-tools libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
Expand All @@ -17,7 +14,10 @@ RUN apt-get update && \

HEALTHCHECK --interval=10s --timeout=3s \
CMD /bin/bash -c "source /opt/ros/${ROS_VERSION}/setup.bash && \
ros2 node list | grep -q gscam_node" || exit 1
ros2 node list | grep -q gscam_publisher" || exit 1

COPY camera_calibration.yaml gscam_params.yaml /
COPY --chmod=755 entrypoint.sh /

SHELL ["/bin/bash", "-c"]
ENTRYPOINT ["/entrypoint.sh"]
2 changes: 1 addition & 1 deletion docker/mapserver/mapfiles/mapserver.map
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MAP
METADATA
"wms_title" "GISNav WMS"
"wms_abstract" "GISNav simulation maps for KSQL airport area"
"wms_onlineresource" "http://localhost:80/wms"
"wms_onlineresource" "http://gisnav-mapserver-1:80/wms"
"wms_srs" "EPSG:3857 EPSG:4326"
"wms_enable_request" "GetMap GetFeatureInfo GetCapabilities"
"wms_feature_info_mime_type" "text/plain"
Expand Down
38 changes: 29 additions & 9 deletions docker/px4/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
ARG ROS_VERSION

FROM px4io/px4-dev-ros2-${ROS_VERSION}
ARG ROS_VERSION
FROM ubuntu:focal

LABEL maintainer="Harri Makelin <[email protected]>"

# Update and upgrade packages, then install required packages
RUN apt-get update && \
apt-get -y dist-upgrade && \
apt-get -y install ros-${ROS_VERSION}-gazebo-ros-pkgs gstreamer1.0-plugins-bad gstreamer1.0-libav gstreamer1.0-gl && \
apt-get -y upgrade && \
DEBIAN_FRONTEND=noninteractive apt-get -y install git python3-pip lsb-release sudo wget gstreamer1.0-plugins-bad gstreamer1.0-libav gstreamer1.0-gl && \
rm -rf /var/lib/apt/lists/* && \
apt clean

Expand All @@ -24,13 +21,25 @@ RUN git clone --branch v1.14.0 --single-branch --depth 1 \
submodule update --init --recursive && \
bash Tools/setup/ubuntu.sh

# Explicitly add required \
# Build and install MAVLink router
RUN cd $HOME && \
git clone --branch v3 --depth 1 https://github.com/mavlink-router/mavlink-router.git && \
cd mavlink-router && \
git submodule update --init --recursive && \
apt install -y git ninja-build pkg-config gcc g++ systemd && \
pip3 install meson>=0.55 && \
meson setup build . && \
ninja -C build && \
ninja -C build install

WORKDIR PX4-Autopilot

COPY merge_xml.py merge_yaml.py dds_topics.yaml iris_hitl_ksql_airport.world 6011_typhoon_h480 .
COPY . .

# Setup ksql_airport.world for HIL
RUN pip install --no-cache-dir lxml && \
# empy must be version 3.3.4, see below commit
# https://github.com/PX4/PX4-containers/commit/80df74db476adbf7a71d08c9b392023756cc1bb0
RUN pip install --no-cache-dir lxml empy==3.3.4 && \
python3 merge_xml.py iris_hitl_ksql_airport.world Tools/simulation/gazebo-classic/sitl_gazebo-classic/worlds/hitl_iris.world

# Configure XRCE-DDS bridge
Expand All @@ -39,5 +48,16 @@ RUN python3 merge_yaml.py dds_topics.yaml src/modules/uxrce_dds_client/dds_topic
# Apply configuration files
#RUN cat 6011_typhoon_h480 >> ROMFS/px4fmu_common/init.d-posix/airframes/6011_gazebo-classic_typhoon_h480

# The hostname of the gscam service in the network is assumed to be gisnav-gscam-1
ENV PX4_VIDEO_HOST_IP=gisnav-gscam-1

RUN mkdir -p /etc/mavlink-router && \
mv etc/mavlink-router/main.conf /etc/mavlink-router/main.conf && \
chmod +x ./entrypoint.sh

# Make initial builds (for faster startup in the future)
RUN DONT_RUN=1 make px4_sitl gazebo-classic_typhoon_h480__ksql_airport

# No health check - if simulation dies makes no sense to restart via autoheal

ENTRYPOINT ["./entrypoint.sh"]
29 changes: 29 additions & 0 deletions docker/px4/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
set -e

# Use MAVLink router to forward packets to remote QGC and MAVROS
# https://docs.px4.io/main/en/simulation/#use-mavlink-router
# See description of how PX4 uses ports for simulation here:
# https://docs.px4.io/main/en/simulation/#default-px4-mavlink-udp-ports
export QGC_IP=$(getent hosts gisnav-qgc-1 | awk '{ print $1 }')
export MAVROS_IP=$(getent hosts gisnav-mavros-1 | awk '{ print $1 }')
echo "Setting up MAVLink router to QGC host ${QGC_IP:-127.0.0.1}"
mavlink-routerd -e ${QGC_IP:-127.0.0.1}:14550 127.0.0.1:14550 &
echo "Setting up MAVLink router to MAVROS host ${MAVROS_IP:-127.0.0.1}"
mavlink-routerd -e ${MAVROS_IP:-127.0.0.1}:14540 127.0.0.1:14540 &

# Setup uXRCE agent IP
# PX4 needs the IP as int32 - convert_ip.py script does the conversion
# https://docs.px4.io/main/en/middleware/uxrce_dds.html#starting-the-client
# UDP port 8888 used by default for SITL simulation
export UXRCE_AGENT_IP=$(getent hosts gisnav-micro-ros-agent-1 | awk '{ print $1 }')
export UXRCE_DDS_AG_IP=$(python3 Tools/convert_ip.py $UXRCE_AGENT_IP)
echo "Connecting uXRCE client with agent at ${UXRCE_AGENT_IP:-127.0.0.1} (${UXRCE_DDS_AG_IP})."
#echo "uxrce_dds_client start -h ${UXRCE_AGENT_IP}" >> ROMFS/px4fmu_common/init.d-posix/airframes/6011_gazebo-classic_typhoon_h480

# Restart the uXRCE client in the main SITL startup script (rcS) with
# the correct DDS agent IP address (rcS hard codes 127.0.0.1)
echo "uxrce_dds_client stop" >> ROMFS/px4fmu_common/init.d-posix/rcS
echo "uxrce_dds_client start -h ${UXRCE_AGENT_IP}" >> ROMFS/px4fmu_common/init.d-posix/rcS

exec "$@"
3 changes: 3 additions & 0 deletions docker/px4/etc/mavlink-router/main.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[General]
# Disable listening on 5760/TCP
TcpServerPort = 0
Loading

0 comments on commit 21e029d

Please sign in to comment.