From 05b0e0f2e6448fe1f235fcf6a61a92bcb46eb919 Mon Sep 17 00:00:00 2001 From: "Ana C. Huaman Quispe" Date: Wed, 6 Mar 2024 10:19:23 -0600 Subject: [PATCH 1/2] Simplify docker compose, make a big dockerfile for easiness --- brash.Dockerfile | 173 ++++++++++++++++++++++++++++++++++++++++ docker-compose-dev.yml | 9 +-- docker-compose-prod.yml | 13 +-- ros_base.Dockerfile | 44 ---------- rosfsw.Dockerfile | 65 --------------- rosgsw.Dockerfile | 46 ----------- scripts/build_images.sh | 37 +-------- 7 files changed, 181 insertions(+), 206 deletions(-) create mode 100644 brash.Dockerfile delete mode 100644 ros_base.Dockerfile delete mode 100644 rosfsw.Dockerfile delete mode 100644 rosgsw.Dockerfile diff --git a/brash.Dockerfile b/brash.Dockerfile new file mode 100644 index 0000000..a19367b --- /dev/null +++ b/brash.Dockerfile @@ -0,0 +1,173 @@ +################################################ +# Build ros-base # +# (ROS2 image with default packages) # +################################################ +FROM osrf/ros:humble-desktop AS ros-base +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update \ +# Needed for OpenGL fix for Rviz to display + && apt-get install -y software-properties-common \ + && add-apt-repository -y ppa:kisak/kisak-mesa \ + && apt update \ + && apt -y upgrade + +RUN apt-get install -y \ + python3-pip \ + libnlopt-dev \ + libnlopt-cxx-dev \ + ros-humble-xacro \ + ros-humble-joint-state-publisher \ + ros-humble-srdfdom \ + ros-humble-rqt* + +RUN pip3 install cfdp + +# Switch to bash shell +SHELL ["/bin/bash", "-c"] + +# Create a brash user +ENV USERNAME=brash_user +ENV HOME_DIR=/home/${USERNAME} +ENV CODE_DIR=/code + +# Dev container arguments +ARG USER_UID=1000 +ARG USER_GID=${USER_UID} + +# Create new user and home directory +RUN groupadd --gid ${USER_GID} ${USERNAME} \ +&& useradd --uid ${USER_UID} --gid ${USER_GID} --create-home ${USERNAME} \ +&& echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} \ +&& chmod 0440 /etc/sudoers.d/${USERNAME} \ +&& mkdir -p ${CODE_DIR} \ +&& chown -R ${USER_UID}:${USER_GID} ${CODE_DIR} + +USER ${USERNAME} +WORKDIR ${CODE_DIR} + +################################################ +# Build rosgsw-dev # +################################################ + +FROM ros-base AS rosgsw-dev +ENV DEBIAN_FRONTEND=noninteractive + +RUN sudo apt-get install -y \ + libnlopt-dev \ + libnlopt-cxx-dev \ + ros-humble-xacro \ + ros-humble-joint-state-publisher \ + ros-humble-srdfdom \ + ros-humble-joint-state-publisher-gui \ + ros-humble-geometric-shapes \ + ros-humble-rqt-robot-steering \ + ros-humble-rqt* \ + libdwarf-dev \ + libelf-dev \ + libsqlite3-dev \ + sqlitebrowser + +# Set up sourcing +COPY --chown=${USERNAME}:${USERNAME} config/rosgsw_entrypoint.sh ${CODE_DIR}/entrypoint.sh +RUN echo 'source ${CODE_DIR}/entrypoint.sh' >> ~/.bashrc + +# Get ready with brash workspace +RUN mkdir -p ${CODE_DIR}/brash +WORKDIR ${CODE_DIR}/brash + +################################################ +# Build rosfsw-dev # +################################################ + +FROM rosgsw-dev AS rosfsw-dev +ENV DEBIAN_FRONTEND=noninteractive + +RUN sudo apt-get install -y \ + ros-humble-controller-interface \ + ros-humble-realtime-tools \ + ros-humble-control-toolbox \ + ros-humble-geometric-shapes \ + ros-humble-controller-manager \ + ros-humble-joint-trajectory-controller \ + ros-humble-rqt* \ + ignition-fortress \ + ros-humble-ros-gz-sim \ + ros-humble-ros-gz-bridge \ + ros-humble-robot-localization \ + ros-humble-interactive-marker-twist-server \ + ros-humble-twist-mux \ + ros-humble-joy-linux \ + ros-humble-imu-tools \ + ros-humble-ign-ros2-control \ + ros-humble-joint-state-broadcaster \ + ros-humble-diff-drive-controller + +# Build a rover_ws into container +WORKDIR ${CODE_DIR} +RUN mkdir -p ${CODE_DIR}/rover_ws +WORKDIR ${CODE_DIR}/rover_ws + +# Copy rover repos and robot config file required +COPY --chown=${USERNAME}:${USERNAME} ./config/rover.repos rover.repos +COPY --chown=${USERNAME}:${USERNAME} ./config/robot.yaml robot.yaml +RUN mkdir src && vcs import src < rover.repos + +# Build the rover workspace +RUN source /opt/ros/humble/setup.bash && \ + colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release + +# Set up sourcing +COPY --chown=${USERNAME}:${USERNAME} ./config/rosfsw_entrypoint.sh ${CODE_DIR}/entrypoint.sh +RUN echo 'source ${CODE_DIR}/entrypoint.sh' >> ~/.bashrc + + +# Source from rover_ws +WORKDIR ${CODE_DIR}/brash + + + +################################################## +# Build rosgsw (Production) +################################################## +FROM rosgsw-dev AS rosgsw + +# Copy brash= +COPY --chown=${USERNAME}:${USERNAME} brash ${CODE_DIR}/brash + +# Build the brash workspace +WORKDIR ${CODE_DIR}/brash +RUN source /opt/ros/humble/setup.bash && \ + colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release + +# Build juicer +#COPY --chown=${USERNAME}:${USERNAME} juicer ${CODE_DIR}/juicer +#WORKDIR ${CODE_DIR}/juicer +#RUN make + +# Set workspace +WORKDIR ${CODE_DIR}/brash + + + +################################################## +# Build rosfsw (Production) +################################################## +FROM rosfsw-dev AS rosfsw + +# Copy brash +COPY --chown=${USERNAME}:${USERNAME} brash ${CODE_DIR}/brash + +# Build the brash workspace +WORKDIR ${CODE_DIR}/brash +RUN source ${CODE_DIR}/rover_ws/install/setup.bash && \ + colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release + +# Build juicer +#COPY --chown=${USERNAME}:${USERNAME} juicer ${CODE_DIR}/juicer +#WORKDIR ${CODE_DIR}/juicer +#RUN make + +# Set workspace +WORKDIR ${CODE_DIR}/brash + diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 13bf1fd..dd524ed 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -19,7 +19,7 @@ services: build: # NOTE: Actual build process must be executed discretely for dev mounts context: . - dockerfile: rosgsw.Dockerfile + dockerfile: brash.Dockerfile target: rosgsw-dev volumes: - "./brash:/code/brash" @@ -31,7 +31,7 @@ services: image: "rosfsw-dev" build: context: . - dockerfile: rosfsw.Dockerfile + dockerfile: brash.Dockerfile target: rosfsw-dev volumes: - "./brash:/code/brash" @@ -40,10 +40,7 @@ services: extends: file: docker-compose-prod.yml service: novnc - ros_base: - extends: - file: docker-compose-prod.yml - service: ros_base + # NOTE: networks apparently can't be imported from related file? networks: spaceip: diff --git a/docker-compose-prod.yml b/docker-compose-prod.yml index ded01e7..7715e2b 100644 --- a/docker-compose-prod.yml +++ b/docker-compose-prod.yml @@ -28,7 +28,7 @@ services: ipv4_address: 10.5.0.2 build: context: . - dockerfile: rosgsw.Dockerfile + dockerfile: brash.Dockerfile target: rosgsw args: - USER_UID=${UID:-1000} @@ -45,7 +45,7 @@ services: ipv4_address: 10.5.0.4 build: context: . - dockerfile: rosfsw.Dockerfile + dockerfile: brash.Dockerfile target: rosfsw args: - USER_UID=${UID:-1000} @@ -62,15 +62,6 @@ services: spaceip: ipv4_address: 10.5.0.5 - ros_base: - image: "ros-base" - build: - context: . - dockerfile: ros_base.Dockerfile - target: ros-base - args: - - USER_UID=${UID:-1000} - networks: spaceip: driver: bridge diff --git a/ros_base.Dockerfile b/ros_base.Dockerfile deleted file mode 100644 index ccb6812..0000000 --- a/ros_base.Dockerfile +++ /dev/null @@ -1,44 +0,0 @@ -FROM osrf/ros:humble-desktop AS ros-base -ENV DEBIAN_FRONTEND=noninteractive - -RUN apt-get update \ -# Needed for OpenGL fix for Rviz to display - && apt-get install -y software-properties-common \ - && add-apt-repository -y ppa:kisak/kisak-mesa \ - && apt update \ - && apt -y upgrade - -RUN apt-get install -y \ - python3-pip \ - libnlopt-dev \ - libnlopt-cxx-dev \ - ros-humble-xacro \ - ros-humble-joint-state-publisher \ - ros-humble-srdfdom \ - ros-humble-rqt* - -RUN pip3 install cfdp - -# Switch to bash shell -SHELL ["/bin/bash", "-c"] - -# Create a brash user -ENV USERNAME=brash_user -ENV HOME_DIR=/home/${USERNAME} -ENV CODE_DIR=/code - -# Dev container arguments -ARG USER_UID=1000 -ARG USER_GID=${USER_UID} - -# Create new user and home directory -RUN groupadd --gid ${USER_GID} ${USERNAME} \ -&& useradd --uid ${USER_UID} --gid ${USER_GID} --create-home ${USERNAME} \ -&& echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} \ -&& chmod 0440 /etc/sudoers.d/${USERNAME} \ -&& mkdir -p ${CODE_DIR} \ -&& chown -R ${USER_UID}:${USER_GID} ${CODE_DIR} - -USER ${USERNAME} -WORKDIR ${CODE_DIR} - diff --git a/rosfsw.Dockerfile b/rosfsw.Dockerfile deleted file mode 100644 index 07edf0f..0000000 --- a/rosfsw.Dockerfile +++ /dev/null @@ -1,65 +0,0 @@ -FROM rosgsw-dev AS rosfsw-dev -ENV DEBIAN_FRONTEND=noninteractive - -RUN sudo apt-get install -y \ - ros-humble-controller-interface \ - ros-humble-realtime-tools \ - ros-humble-control-toolbox \ - ros-humble-geometric-shapes \ - ros-humble-controller-manager \ - ros-humble-joint-trajectory-controller \ - ros-humble-rqt* \ - ignition-fortress \ - ros-humble-ros-gz-sim \ - ros-humble-ros-gz-bridge \ - ros-humble-robot-localization \ - ros-humble-interactive-marker-twist-server \ - ros-humble-twist-mux \ - ros-humble-joy-linux \ - ros-humble-imu-tools \ - ros-humble-ign-ros2-control \ - ros-humble-joint-state-broadcaster \ - ros-humble-diff-drive-controller - -# Build a rover_ws into container -WORKDIR ${CODE_DIR} -RUN mkdir -p ${CODE_DIR}/rover_ws -WORKDIR ${CODE_DIR}/rover_ws - -# Copy rover repos and robot config file required -COPY --chown=${USERNAME}:${USERNAME} ./config/rover.repos rover.repos -COPY --chown=${USERNAME}:${USERNAME} ./config/robot.yaml robot.yaml -RUN mkdir src && vcs import src < rover.repos - -# Build the rover workspace -RUN source /opt/ros/humble/setup.bash && \ - colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release - -# Set up sourcing -COPY --chown=${USERNAME}:${USERNAME} ./config/rosfsw_entrypoint.sh ${CODE_DIR}/entrypoint.sh -RUN echo 'source ${CODE_DIR}/entrypoint.sh' >> ~/.bashrc - - -# Source from rover_ws -WORKDIR ${CODE_DIR}/brash - -################################################## -# Production -################################################## -FROM rosfsw-dev AS rosfsw - -# Copy brash -COPY --chown=${USERNAME}:${USERNAME} brash ${CODE_DIR}/brash - -# Build the brash workspace -WORKDIR ${CODE_DIR}/brash -RUN source ${CODE_DIR}/rover_ws/install/setup.bash && \ - colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release - -# Build juicer -#COPY --chown=${USERNAME}:${USERNAME} juicer ${CODE_DIR}/juicer -#WORKDIR ${CODE_DIR}/juicer -#RUN make - -# Set workspace -WORKDIR ${CODE_DIR}/brash diff --git a/rosgsw.Dockerfile b/rosgsw.Dockerfile deleted file mode 100644 index 25e5393..0000000 --- a/rosgsw.Dockerfile +++ /dev/null @@ -1,46 +0,0 @@ -FROM ros-base AS rosgsw-dev -ENV DEBIAN_FRONTEND=noninteractive - -RUN sudo apt-get install -y \ - libnlopt-dev \ - libnlopt-cxx-dev \ - ros-humble-xacro \ - ros-humble-joint-state-publisher \ - ros-humble-srdfdom \ - ros-humble-joint-state-publisher-gui \ - ros-humble-geometric-shapes \ - ros-humble-rqt-robot-steering \ - ros-humble-rqt* \ - libdwarf-dev \ - libelf-dev \ - libsqlite3-dev \ - sqlitebrowser - -# Set up sourcing -COPY --chown=${USERNAME}:${USERNAME} config/rosgsw_entrypoint.sh ${CODE_DIR}/entrypoint.sh -RUN echo 'source ${CODE_DIR}/entrypoint.sh' >> ~/.bashrc - -# Get ready with brash workspace -RUN mkdir -p ${CODE_DIR}/brash -WORKDIR ${CODE_DIR}/brash - -################################################## -# Production -################################################## -FROM rosgsw-dev AS rosgsw - -# Copy brash= -COPY --chown=${USERNAME}:${USERNAME} brash ${CODE_DIR}/brash - -# Build the brash workspace -WORKDIR ${CODE_DIR}/brash -RUN source /opt/ros/humble/setup.bash && \ - colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release - -# Build juicer -#COPY --chown=${USERNAME}:${USERNAME} juicer ${CODE_DIR}/juicer -#WORKDIR ${CODE_DIR}/juicer -#RUN make - -# Set workspace -WORKDIR ${CODE_DIR}/brash diff --git a/scripts/build_images.sh b/scripts/build_images.sh index 40e0f9b..96f1749 100755 --- a/scripts/build_images.sh +++ b/scripts/build_images.sh @@ -14,46 +14,15 @@ done echo "...Using COMPOSE_FILE: ${COMPOSE_FILE}..." echo "" -echo "##### Building fsw #####" +echo "##### Building fsw, rosgsw and rosfsw #####" echo "" -env UID=${UID} docker compose -f ${COMPOSE_FILE} build fsw +env UID=${UID} docker compose -f ${COMPOSE_FILE} build ret=$? if [ $ret -ne 0 ]; then - echo "!! Failed in building base image for fsw service !!" + echo "!! Failed in building base image for fsw, rosgsw and rosfsw services !!" return 1 fi -echo "" -echo "##### Building ros_base #####" -echo "" -env UID=${UID} docker compose -f ${COMPOSE_FILE} build ros_base -ret=$? -if [ $ret -ne 0 ]; then - echo "!! Failed in building base image for ros_base (base for rosgsw and rosfsw) !!" - return 1 -fi - -echo "" -echo "##### Building rosgsw #####" -echo "" -env UID=${UID} docker compose -f ${COMPOSE_FILE} build rosgsw -ret=$? -if [ $ret -ne 0 ]; then - echo "!! Failed in building base image for rosgsw !!" - return 1 -fi - -echo "" -echo "##### Building rosfsw #####" -echo "" -env UID=${UID} docker compose -f ${COMPOSE_FILE} build rosfsw -ret=$? -if [ $ret -ne 0 ]; then - echo "!! Failed in building base image for rosfsw !!" - return 1 -fi - - echo "" echo "##### Done! #####" return 0 From bfdb482c1a0e6716d004ee308ab8721bec92a2a4 Mon Sep 17 00:00:00 2001 From: "Ana C. Huaman Quispe" Date: Wed, 6 Mar 2024 10:23:02 -0600 Subject: [PATCH 2/2] Delete unnecessary description on title --- scripts/build_images.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build_images.sh b/scripts/build_images.sh index 96f1749..3350de2 100755 --- a/scripts/build_images.sh +++ b/scripts/build_images.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash echo "" -echo "##### Building base images (needs to be in order for image dependencies) #####" +echo "##### Building base images #####" echo "" COMPOSE_FILE="docker-compose-dev.yml"