From 7d3b0457c943d8ad06856f0705fb6bcc749f1ee3 Mon Sep 17 00:00:00 2001 From: Daisuke Sato Date: Mon, 27 May 2024 00:25:39 +0900 Subject: [PATCH] feat: Add ROS 2 Iron (#56) --- .github/dependabot.yml | 9 ++---- .github/workflows/deploy.yml | 1 + .github/workflows/test.yml | 15 +++++++++ iron/Dockerfile | 36 +++++++++++++++++++++ iron/ros_entrypoint.sh | 62 ++++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 6 deletions(-) create mode 100644 iron/Dockerfile create mode 100755 iron/ros_entrypoint.sh diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b601047..56769aa 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -10,11 +10,8 @@ updates: - "Type: CI" - package-ecosystem: "docker" - directory: "/foxy" - schedule: - interval: "daily" - - - package-ecosystem: "docker" - directory: "/humble" + directories: + - "/humble" + - "/iron" schedule: interval: "daily" diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 908979d..fe1ab1b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -29,6 +29,7 @@ jobs: - foxy - galactic - humble + - iron steps: - name: Checkout diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a0a8c4a..8779446 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,8 +24,23 @@ jobs: - foxy - galactic - humble + - iron steps: + - name: Free Up GitHub Actions Ubuntu Runner Disk Space + uses: hirnidrin/free-disk-space@main + # uses: jlumbroso/free-disk-space@main + with: + # This might remove tools that are actually needed, if set to "true" but frees about 6 GB + tool-cache: false + # All of these default to true, but feel free to set to "false" if necessary for your workflow + android: true + dotnet: true + haskell: true + large-packages: true + docker-images: false + swap-storage: true + - name: Checkout uses: actions/checkout@v3 diff --git a/iron/Dockerfile b/iron/Dockerfile new file mode 100644 index 0000000..56d672e --- /dev/null +++ b/iron/Dockerfile @@ -0,0 +1,36 @@ +FROM ubuntu:jammy-20240427 AS builder +RUN apt-get update +RUN apt-get install -y curl +RUN apt-get install -y --no-install-recommends gcc libc-dev +RUN curl -o /usr/local/bin/su-exec.c https://raw.githubusercontent.com/ncopa/su-exec/master/su-exec.c +RUN gcc -Wall /usr/local/bin/su-exec.c -o/usr/local/bin/su-exec +RUN chown root:root /usr/local/bin/su-exec +RUN chmod 0755 /usr/local/bin/su-exec + + +FROM ubuntu:jammy-20240427 +ARG TARGETPLATFORM +LABEL maintainer="Daisuke Sato " +RUN apt-get update -q && \ + apt-get upgrade -yq && \ + DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends keyboard-configuration language-pack-en && \ + DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends wget curl git build-essential ca-certificates tzdata tmux gnupg2 \ + vim sudo lsb-release locales bash-completion zsh iproute2 iputils-ping net-tools dnsutils && \ + rm -rf /var/lib/apt/lists/* +ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8 +RUN locale-gen en_US.UTF-8 +ENV ROS_DISTRO=iron +RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg && \ + echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null && \ + apt-get update && \ + apt-get install -y --no-install-recommends ros-${ROS_DISTRO}-desktop && \ + apt-get install -y --no-install-recommends python3-argcomplete python3-colcon-common-extensions python3-rosdep python3-colcon-mixin python3-vcstool && \ + if [ ! "$TARGETPLATFORM" = "linux/arm64" ]; then apt-get install -y --no-install-recommends ros-${ROS_DISTRO}-gazebo-ros-pkgs; fi && \ + apt-get install -y --no-install-recommends ros-${ROS_DISTRO}-xacro ros-${ROS_DISTRO}-joint-state-publisher-gui && \ + rm -rf /var/lib/apt/lists/* +RUN rosdep init && \ + rosdep update +COPY --from=builder /usr/local/bin/su-exec /sbin/ +COPY ./ros_entrypoint.sh / +ENTRYPOINT ["/ros_entrypoint.sh"] +CMD ["/bin/bash"] diff --git a/iron/ros_entrypoint.sh b/iron/ros_entrypoint.sh new file mode 100755 index 0000000..39c74be --- /dev/null +++ b/iron/ros_entrypoint.sh @@ -0,0 +1,62 @@ +#!/bin/bash +set -e + +DEFAULT_USER=${DEFAULT_USER:-'ubuntu'} +DEFAULT_USER_UID=${USER_UID:-'1000'} +DEFAULT_USER_GID=${USER_GID:-'1000'} +NOPASSWD=${NOPASSWD:-''} # set 'NOPASSWD:' to disable asking sudo password + +if [[ $(id -u) -eq 0 ]]; then + echo "Set disable_coredump false" >> /etc/sudo.conf +else + echo "Set disable_coredump false" | sudo tee -a /etc/sudo.conf > /dev/null +fi + +# override if $USER env exists +if [[ ! -z "$USER" ]]; then + DEFAULT_USER=$USER +fi + +# create development user +if [[ $(id -u) -eq 0 ]]; then + EXEC="exec /sbin/su-exec ${DEFAULT_USER}" + + # create_user + if [[ ! -e /home/${DEFAULT_USER} ]]; then + groupadd -g "${DEFAULT_USER_GID}" "${DEFAULT_USER}" + useradd --create-home --home-dir /home/${DEFAULT_USER} --uid ${DEFAULT_USER_UID} --shell /bin/bash \ + --gid ${DEFAULT_USER_GID} --groups sudo ${DEFAULT_USER} + echo "${DEFAULT_USER}:${DEFAULT_USER}" | chpasswd && \ + echo "${DEFAULT_USER} ALL=(ALL) ${NOPASSWD}ALL" >> /etc/sudoers + touch /home/${DEFAULT_USER}/.sudo_as_admin_successful + fi + + # setup ros environment + mkdir -p /home/${DEFAULT_USER}/ros2_ws/src \ + echo 'source /opt/ros/${ROS_DISTRO}/setup.bash' >> /home/${DEFAULT_USER}/.bashrc + + chown -R ${DEFAULT_USER}:${DEFAULT_USER} /home/${DEFAULT_USER} + + # mount develop workspace + if [ -e /ws ]; then + ln -s /ws /home/${DEFAULT_USER}/ros2_ws/src + fi + + DEFAULT_USER_UID="$(${EXEC} id -u)" + DEFAULT_USER_GID="$(${EXEC} id -g)" +else # use existing user + EXEC="exec" + DEFAULT_USER="$(whoami)" + DEFAULT_USER_UID="$(id -u)" + DEFAULT_USER_GID="$(id -g)" +fi + +echo "Launched container with user: $DEFAULT_USER, uid: $DEFAULT_USER_UID, gid: $DEFAULT_USER_GID" + +if which "$1" > /dev/null 2>&1 ; then + source /opt/ros/${ROS_DISTRO}/setup.bash + $EXEC "$@" +else + echo $@ | $EXEC $SHELL -li +fi +