From 50ddd1c2ab00eb04bcdcab7c28f5b965e87932ac Mon Sep 17 00:00:00 2001 From: ML1907 Date: Thu, 19 Dec 2024 11:46:10 +0100 Subject: [PATCH] First working building. fix: colcon build because of catkin used in cmakefiles. --- docker/Dockerfile.base | 52 ++++++++++++++++++++++-------------------- entrypoint | 21 +++++++++++------ requirements.txt | 2 +- util/config.sh | 8 +++---- 4 files changed, 46 insertions(+), 37 deletions(-) diff --git a/docker/Dockerfile.base b/docker/Dockerfile.base index d06582e5..21dc2ad6 100644 --- a/docker/Dockerfile.base +++ b/docker/Dockerfile.base @@ -1,7 +1,8 @@ -# Dockerfile for base SVEA image +# Dockerfile for base SVEA image (ROS2 Jazzy Jalisco) # # Author: Kaj Munhoz Arfvidsson +# Dynamically set the base image using BUILD_TAG and ROSDISTRO ARG BUILD_TAG ARG ROSDISTRO ARG WORKSPACE @@ -12,37 +13,45 @@ ARG WORKSPACE FROM ${BUILD_TAG:-ros:latest} +# Arguments for dynamic configuration ARG ROSDISTRO ARG WORKSPACE ARG DEBIAN_FRONTEND=noninteractive -## Install dependencies from apt-get - -RUN apt-get update -y && \ - apt-get upgrade -y && \ +# Install core dependencies using apt-get +RUN apt-get update -y && apt-get upgrade -y && \ apt-get install --no-install-recommends -y \ - apt-utils lsb-release \ - build-essential cmake \ - git vim nano curl iputils-ping \ + apt \ + lsb-release \ + build-essential \ + cmake \ + git \ + vim \ + nano \ + curl \ + inetutils-ping \ python3-tk \ python3-pip \ python3-numpy \ python3-matplotlib \ - python3-catkin-tools \ - && \ - python3 -m pip install -U pip && \ + python3-colcon-common-extensions \ + python3-rosdep && \ rm -rf /var/lib/apt/lists/* -## Create svea workspace +# Initialize rosdep for resolving dependencies +RUN rosdep init || echo "rosdep already initialized" +RUN rosdep update --rosdistro $ROSDISTRO + +# Create the SVEA workspace WORKDIR $WORKSPACE -# Need to copy src and util separately because docker COPY rules are iffy. -# https://docs.docker.com/engine/reference/builder/#copy +# Copy workspace files and utilities COPY src ./src COPY util ./util COPY entrypoint requirements.txt ./ +# Install ROS2 dependencies and Python packages RUN cp -f entrypoint /ros_entrypoint.sh && \ apt-get update -y && \ rosdep update \ @@ -54,20 +63,13 @@ RUN cp -f entrypoint /ros_entrypoint.sh && \ --ignore-src \ -qry \ && \ - pip install -r requirements.txt && \ + pip install -r requirements.txt --break-system-packages && \ rm -rf /var/lib/apt/lists/* -# Run catkin build on workspace (improves build speeds later on). -RUN catkin config \ - --init \ - --mkdirs \ - --extend /opt/ros/$ROSDISTRO \ - > /dev/null \ - && \ - catkin build - -## Container entrypoint (executes util/entrypoint) +# Build workspace +RUN colcon build --symlink-install +# Container entrypoint (executes util/entrypoint) ENTRYPOINT ["/ros_entrypoint.sh"] # bash is run by default when user starts diff --git a/entrypoint b/entrypoint index 36dce654..4e9e0105 100755 --- a/entrypoint +++ b/entrypoint @@ -1,6 +1,6 @@ #! /bin/bash # -# This entrypoint script will be called everytime a container is started. +# This entrypoint script will be called every time a container is started. # # Author: Kaj Munhoz Arfvidsson @@ -9,15 +9,22 @@ set -e # Get project information source util/config.sh -# Set ROS_IP etc. for e.g. rviz remote connection +# Set ROS_IP etc. for e.g., RViz remote connection # https://stackoverflow.com/a/65912397 remote_ros() { source util/remote_ros.sh; }; remote_ros -# To build anything that has been added by volume... -catkin build +# Build the ROS2 workspace if files have been added or modified by volume +if [ -d "$WORKSPACE/src" ]; then + echo "Building the ROS2 workspace..." + . /opt/ros/$ROSDISTRO/setup.bash + colcon build --symlink-install --base-paths "$WORKSPACE" +fi -# https://github.com/osrf/docker_images/issues/114 -printf "\nsource '$PWD/devel/setup.bash'" >> $HOME/.bashrc +# Source the ROS2 workspace setup file +if [ -f "$WORKSPACE/install/setup.bash" ]; then + printf "\nsource '$WORKSPACE/install/setup.bash'" >> $HOME/.bashrc + . "$WORKSPACE/install/setup.bash" +fi +# Execute the container's command exec "$@" - diff --git a/requirements.txt b/requirements.txt index a10d9f8d..cfa3e39d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,4 +13,4 @@ pyubx2 geopy utm # This is for NMPC -casadi==3.5.5 +casadi>=3.6.0,<4.0.0 diff --git a/util/config.sh b/util/config.sh index c9f5c231..831d0eca 100644 --- a/util/config.sh +++ b/util/config.sh @@ -13,12 +13,12 @@ main() { withdefault DEBUG "0" - withdefault ROSDISTRO "noetic" + withdefault ROSDISTRO "jazzy" withdefault WORKSPACE "/svea_ws" withdefault REPOSITORY_PATH "$(climb entrypoint)" withdefault REPOSITORY_NAME "$(basename "$REPOSITORY_PATH")" + withdefault BUILD_CONFIG "base" - withdefault BUILD_CONFIG "default" if [ "$BUILD_CONFIG" = "default" ]; then # building for host platform withdefault BUILD_PLATFORM "$(uname -m)" @@ -32,8 +32,8 @@ main() { withdefault BUILD_PLATFORM "$(uname -m)" withdefault BUILD_CONTEXT "$REPOSITORY_PATH" withdefault BUILD_FILE "docker/Dockerfile.base" - withdefault BUILD_TAG "ros:$ROSDISTRO" - withdefault IMAGE_TAG "ghcr.io/kth-sml/svea:latest" + withdefault BUILD_TAG "osrf/ros:${ROSDISTRO}-desktop" + withdefault IMAGE_TAG "ghcr.io/kth-sml/svea-base:${ROSDISTRO}" withdefault IMAGE_PUSH "0" elif [ "$BUILD_CONFIG" = "base-amd64" ]; then # building for x86_64