From 9d94a555dd76f4fb71aa143d791b8cd56bb68076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ellensohn?= Date: Wed, 2 Aug 2023 11:34:51 +0200 Subject: [PATCH] fixed multi platform builds: now working adm64/arm64 images --- dependencies.amd64.repos | 2 +- docker-compose.yaml | 22 +++++++++++++++++-- docker/Dockerfile | 46 +++++++++++++++++++++++++++++++++++----- 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/dependencies.amd64.repos b/dependencies.amd64.repos index 3daafd6..2536029 100644 --- a/dependencies.amd64.repos +++ b/dependencies.amd64.repos @@ -5,7 +5,7 @@ repositories: segwayrmp: type: git url: https://github.com/bjoernellens1/segwayrmp - version: x86 + version: humble segway_msgs: type: git diff --git a/docker-compose.yaml b/docker-compose.yaml index f2320a4..e65e215 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -12,7 +12,8 @@ services: x-bake: platforms: - linux/arm64 - #- linux/amd64 + - linux/amd64 + # Interactive shell stdin_open: true tty: true @@ -44,7 +45,24 @@ services: x-bake: platforms: - linux/arm64 - # - linux/amd64 + - linux/amd64 + + # Overlay image containing the project specific source code. + final: + extends: overlay + image: ghcr.io/bjoernellens1/ros2_rmp/rmp:final + build: + context: . + dockerfile: docker/Dockerfile + tags: + - ghcr.io/bjoernellens1/ros2_rmp/rmp:final + target: final + x-bake: + platforms: + - linux/arm64 + - linux/amd64 + command: > + ros2 launch cps_rmp220_support rsp.launch.py # Robot State Publisher robot_state_publisher: diff --git a/docker/Dockerfile b/docker/Dockerfile index 5049515..bdf2976 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -12,6 +12,8 @@ ARG TARGETPLATFORM ######################################## FROM ros:${ROS_DISTRO} as base ENV ROS_DISTRO=${ROS_DISTRO} +#ENV TARGETPLATFORM=$TARGETPLATFORM + SHELL ["/bin/bash", "-c"] # Create Colcon workspace with external dependencies @@ -23,7 +25,11 @@ COPY dependencies.amd64.repos . # Choose correct sources for architecture: # Copy platform-specific files # Use if condition to copy different files for different platforms -RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ +#RUN echo "TARGETPLATFORM is $TARGETPLATFORM" +RUN echo "Hardware platform is: $(uname -m)" +RUN uname -a + +RUN if [ "$(uname -m)" = "x86_64" ]; then \ echo "Copying files for linux/amd64"; \ mv dependencies.amd64.repos dependencies.repos; \ else \ @@ -31,8 +37,9 @@ RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ mv dependencies.arm64.repos dependencies.repos; \ fi -RUN vcs import < dependencies.repos - +#RUN vcs import < dependencies.repos +RUN vcs import < dependencies.repos; + # Build the base Colcon workspace, installing dependencies first. WORKDIR /rmp_ws RUN source /opt/ros/${ROS_DISTRO}/setup.bash \ @@ -63,8 +70,7 @@ COPY overlay.repos . RUN vcs import < overlay.repos WORKDIR /overlay_ws -# COPY ./tb3_autonomy/ ./src/tb3_autonomy/ -# COPY ./tb3_worlds/ ./src/tb3_worlds/ + RUN source /rmp_ws/install/setup.bash \ && colcon build --symlink-install \ && apt-get update \ @@ -83,4 +89,34 @@ RUN chmod +x /localization_startup.sh ENTRYPOINT [ "/entrypoint.sh" ] +########################################### +# Packing it up into a smaller image by starting from scratch and copying related stuff # +########################################### +FROM ros:${ROS_DISTRO}-ros-core AS final +COPY --from=overlay /overlay_ws/ /overlay_ws/ +COPY --from=overlay /opt/ros /opt/ros/ +COPY --from=overlay /usr/local/ /usr/local/ +# COPY --from=overlay /lib/x86_64-linux-gnu/libm.so.6 /lib/x86_64-linux-gnu/ +# COPY --from=overlay /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/ +# COPY --from=overlay /lib/x86_64-linux-gnu/libpthread.so.0 /lib/x86_64-linux-gnu/ +# COPY --from=overlay /lib/x86_64-linux-gnu/librt.so.1 /lib/x86_64-linux-gnu/ +# COPY --from=overlay /lib/x86_64-linux-gnu/libgcc_s.so.1 /lib/x86_64-linux-gnu/ +# COPY --from=overlay /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/ +# COPY --from=overlay /lib64/ld-linux-x86-64.so.2 /lib64/ + +# Set up environment variables +ENV LD_LIBRARY_PATH=/usr/local/lib:/opt/ros/${ROS_DISTRO}/lib:/opt/ros/${ROS_DISTRO}/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH +ENV PATH=/opt/ros/${ROS_DISTRO}/bin:$PATH + +# Copy necessary entrypoint and scripts +COPY ./docker/entrypoint.sh / +COPY ./controller_startup.sh / +COPY ./localization_startup.sh / + +# Set permissions for scripts +RUN chmod +x /entrypoint.sh /controller_startup.sh /localization_startup.sh + +# Set up the entrypoint +ENTRYPOINT [ "/entrypoint.sh" ] + LABEL org.opencontainers.image.source=https://github.com/bjoernellens1/ros2_rmp \ No newline at end of file