Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create ros2-ws image that has ros2-control installed #107

Merged
merged 4 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/reusable-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,21 @@ jobs:

- id: tags
run: |
BUILD_FLAGS=()
BUILD_FLAGS=()

BASE_TAG=${{ inputs.ros_distro }}
BUILD_FLAGS+=(--build-arg BASE_TAG=${BASE_TAG})
echo "::debug::Using base image tag ${BASE_TAG}"
echo "build_flags=${BUILD_FLAGS[@]}" >> $GITHUB_OUTPUT

VERSION_TAG="v${{ needs.check-version.outputs.version }}"
IMAGE_TAGS="${VERSION_TAG},${VERSION_TAG}-${{ inputs.ros_distro}}","${{ inputs.ros_distro}}"
GIT_TAG="${VERSION_TAG}-${{ inputs.ros_distro}}"
BUILD_FLAGS+=(--build-arg VERSION=${GIT_TAG})

echo "::debug::Using base image tag ${BASE_TAG}"
echo "Build flags: ${BUILD_FLAGS[@]}"
echo "Image tags: ${IMAGE_TAGS}"
echo "Git tag: ${GIT_TAG}"
echo "build_flags=${BUILD_FLAGS[@]}" >> $GITHUB_OUTPUT
echo "image_tags=${IMAGE_TAGS}" >> $GITHUB_OUTPUT
echo "git_tag=${GIT_TAG}" >> $GITHUB_OUTPUT

Expand Down
25 changes: 0 additions & 25 deletions ros2_control/Dockerfile.galactic

This file was deleted.

26 changes: 0 additions & 26 deletions ros2_control/Dockerfile.humble

This file was deleted.

38 changes: 0 additions & 38 deletions ros2_control/Dockerfile.iron

This file was deleted.

65 changes: 0 additions & 65 deletions ros2_control/build.sh

This file was deleted.

118 changes: 10 additions & 108 deletions ros2_ws/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,108 +1,10 @@
ARG BASE_TAG=humble
FROM ros:${BASE_TAG} as environment-variables
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONWARNINGS=ignore:::setuptools.command.install,ignore:::setuptools.command.easy_install,ignore:::pkg_resources
ENV PIP_NO_CACHE_DIR 1
ENV USER ros2
ENV HOME /home/${USER}
ENV ROS2_WORKSPACE /home/${USER}/ros2_ws
ENV COLCON_HOME ${HOME}/.colcon
ENV COLCON_DEFAULTS_FILE ${COLCON_HOME}/defaults.yaml
ENV COLCON_WORKSPACE=${ROS2_WORKSPACE}
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib


FROM environment-variables as base-dependencies

# disable suggested and recommended install
RUN apt-config dump | grep -we Recommends -e Suggests | sed s/1/0/ \
| sudo tee /etc/apt/apt.conf.d/999norecommend

# install base dependencies
RUN apt-get update && apt-get install --no-install-recommends -y \
autoconf \
automake \
curl \
featherpad \
gdb \
git \
iputils-ping \
libboost-all-dev \
libtool \
mesa-utils \
nano \
python3-pip \
ros-${ROS_DISTRO}-xacro \
ros-${ROS_DISTRO}-robot-state-publisher \
ros-${ROS_DISTRO}-rviz2 \
rsync \
software-properties-common \
ssh \
unzip \
wget \
&& rm -rf /var/lib/apt/lists/*

RUN echo "Set disable_coredump false" >> /etc/sudo.conf

# configure sshd server settings
RUN ( \
echo 'LogLevel DEBUG2'; \
echo 'PubkeyAuthentication yes'; \
echo 'Subsystem sftp /usr/lib/openssh/sftp-server'; \
) > /etc/ssh/sshd_config_development \
&& mkdir /run/sshd


FROM base-dependencies as base-workspace

# create and configure a new user
ARG UID=1000
ARG GID=1000
RUN addgroup --gid ${GID} ${USER}
RUN adduser --gecos "ROS2 User" --uid ${UID} --gid ${GID} ${USER} && yes | passwd ${USER}
RUN usermod -a -G dialout ${USER}
RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/99_aptget
RUN chmod 0440 /etc/sudoers.d/99_aptget && chown root:root /etc/sudoers.d/99_aptget

# configure sshd entrypoint to authorise the new user for ssh access and
# optionally update UID and GID when invoking the container with the entrypoint script
COPY ./config/sshd_entrypoint.sh /sshd_entrypoint.sh
RUN chmod 744 /sshd_entrypoint.sh

# crete user group with realtime permissions and add user to it
RUN groupadd -g 3719 realtime && usermod -aG realtime ${USER}
RUN echo "@realtime soft rtprio 99\n@realtime hard rtprio 99\n" > \
/etc/security/limits.d/realtime.conf

# configure colcon defaults and utilities
USER ${USER}
WORKDIR ${HOME}
RUN wget https://raw.githubusercontent.com/aica-technology/.github/v0.9.0/guidelines/.clang-format
RUN mkdir -p ${COLCON_HOME}
COPY --chown=${USER}:${USER} ./config/colcon ${COLCON_HOME}
RUN /bin/bash ${COLCON_HOME}/setup.sh

# build ROS workspace
RUN mkdir -p ${ROS2_WORKSPACE}/src
WORKDIR ${ROS2_WORKSPACE}
RUN rosdep update
RUN /bin/bash -c "source /opt/ros/${ROS_DISTRO}/setup.bash; colcon build --symlink-install"

# prepend the environment sourcing to bashrc (appending will fail for non-interactive sessions)
RUN echo "source /opt/ros/${ROS_DISTRO}/setup.bash; \
source ${ROS2_WORKSPACE}/install/setup.bash" | cat - ${HOME}/.bashrc > tmp && mv tmp ${HOME}/.bashrc
# enable colorized output from ros logging
RUN echo "export RCUTILS_COLORIZED_OUTPUT=1" >> ${HOME}/.bashrc

# create the credentials to be able to pull private repos using ssh
USER root
RUN mkdir /root/.ssh/ && ssh-keyscan github.com | tee -a /root/.ssh/known_hosts
RUN echo "session required pam_limits.so" | tee --append /etc/pam.d/common-session > /dev/null


FROM environment-variables as final
COPY --from=base-workspace / /

# start as ROS user
USER ${USER}
WORKDIR ${ROS2_WORKSPACE}
ARG BASE_TAG=iron
FROM ghcr.io/aica-technology/ros2-control:${BASE_TAG}

ARG VERSION=v0.0.0
ARG BASE_TAG=iron
LABEL org.opencontainers.image.title="AICA ROS 2 image"
LABEL org.opencontainers.image.description="AICA base ROS 2 image (includes ros2_control)"
LABEL org.opencontainers.image.version="${VERSION}"
LABEL org.opencontainers.image.base.name="docker.io/library/ros:${BASE_TAG}"
LABEL tech.aica.image.metadata='{"type":"base/ws","base":{"name":"docker.io/library/ros","version":"'${BASE_TAG}'"}}'
19 changes: 4 additions & 15 deletions ros2_ws/build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

IMAGE_NAME=aica-technology/ros2-ws
BASE_TAG=humble
IMAGE_NAME=ghcr.io/aica-technology/ros2-ws
BASE_TAG=iron

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
if [[ ! -f "${SCRIPT_DIR}"/config/sshd_entrypoint.sh ]]; then
Expand Down Expand Up @@ -31,16 +31,5 @@ while [ "$#" -gt 0 ]; do
esac
done

docker pull "ros:${BASE_TAG}"
BUILD_FLAGS+=(--build-arg BASE_TAG="${BASE_TAG}")

if [[ "$OSTYPE" != "darwin"* ]]; then
USER_ID="$(id -u "${USER}")"
GROUP_ID="$(id -g "${USER}")"
BUILD_FLAGS+=(--build-arg UID="${USER_ID}")
BUILD_FLAGS+=(--build-arg GID="${GROUP_ID}")
fi

BUILD_FLAGS+=(-t "${IMAGE_NAME}":"${BASE_TAG}")

DOCKER_BUILDKIT=1 docker build "${BUILD_FLAGS[@]}" .
BUILD_FLAGS+=(--build-arg=BASE_TAG=${BASE_TAG})
docker buildx build -t "${IMAGE_NAME}":"${BASE_TAG}" "${BUILD_FLAGS[@]}" .