Skip to content
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
68 changes: 68 additions & 0 deletions ct_data_plotter/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
ARG BASE_IMAGE=docker.io/library/ros
ARG BASE_TAG=jazzy-ros-core
ARG ROS_DISTRO=jazzy
ARG VERSION=v0.0.0

FROM ${BASE_IMAGE}:${BASE_TAG} AS environment-variables
ENV DEBIAN_FRONTEND=noninteractive
ENV PIP_NO_CACHE_DIR=1
ENV USER=ros2
ENV HOME=/home/${USER}

FROM environment-variables AS base-dependencies

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

RUN apt-get update && apt-get install --no-install-recommends -y \
sudo \
python3-pip \
python3-tk \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get clean

RUN usermod -l ${USER} ubuntu
RUN groupmod -n ${USER} ubuntu
RUN usermod -d ${HOME} -m ros2
RUN chfn -f "ROS2 User" ros2

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

RUN pip3 install --break-system-packages \
"numpy==1.26.4" \
matplotlib \
mcap \
mcap-ros2-support

USER ${USER}
WORKDIR ${HOME}

COPY --chown=${USER}:${USER} ./config/plot.py /usr/local/bin/plot.py
RUN chmod +x /usr/local/bin/plot.py

FROM environment-variables AS final
COPY --from=base-dependencies / /

USER ${USER}
WORKDIR ${HOME}

RUN echo '#!/bin/bash\n\
set -e\n\
source /opt/ros/${ROS_DISTRO}/setup.bash\n\
exec "$@"' > ${HOME}/ros_entrypoint.sh && chmod +x ${HOME}/ros_entrypoint.sh

ENTRYPOINT ["/home/ros2/ros_entrypoint.sh"]
CMD ["python3", "/usr/local/bin/plot.py", "/bag", "--save", "/export/plot.png"]

# Metadata
ARG BASE_IMAGE
ARG BASE_TAG
ARG VERSION
LABEL org.opencontainers.image.title="AICA CT data plotter"
LABEL org.opencontainers.image.description="Plots cartesian trajectory data from ROS 2 bags"
LABEL org.opencontainers.image.version="${VERSION}"
LABEL org.opencontainers.image.base.name="${BASE_IMAGE}:${BASE_TAG}"
LABEL devcontainer.metadata='[{"containerUser": "ros2"}]'
1 change: 1 addition & 0 deletions ct_data_plotter/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
68 changes: 68 additions & 0 deletions ct_data_plotter/build-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

IMAGE_NAME=ghcr.io/aica-technology/ct_data_plotter
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
VERSION=$(cat "${SCRIPT_DIR}/VERSION")

OUTPUT_DIR="${SCRIPT_DIR}/export"
OUTPUT_NAME="plot.png"
BAG_PATH=""

BUILD_FLAGS=()
while [ "$#" -gt 0 ]; do
case "$1" in
# build args
-r | --rebuild)
BUILD_FLAGS+=(--no-cache)
shift 1
;;

# run args
--bag-path)
BAG_PATH=$2
shift 2
;;
--output-dir)
OUTPUT_DIR=$2
shift 2
;;
--output-name)
OUTPUT_NAME=$2
shift 2
;;

*)
echo "Unknown option: $1" >&2
exit 1
;;
esac
done

if [ -z "$BAG_PATH" ]; then
echo "Error: You must provide a bag path."
echo "Usage: $0 --bag-path /path/to/rosbag/dir [options]"
exit 1
fi

docker buildx build --load -t "${IMAGE_NAME}":v"${VERSION}" "${BUILD_FLAGS[@]}" "${SCRIPT_DIR}"

if [ ! -d "$OUTPUT_DIR" ]; then
mkdir -p "$OUTPUT_DIR"
fi

xhost +
docker run -it --rm \
--device /dev/dri:/dev/dri \
-u ros2 \
-e DISPLAY="${DISPLAY}" \
-e XAUTHORITY="${XAUTHORITY}" \
-e ROSBAG_PATH="/bag" \
-v "$OUTPUT_DIR":/export \
-v "$BAG_PATH":/bag:ro \
-v /dev:/dev:rw \
-v /tmp/.X11-unix:/tmp/.X11-unix:rw \
--privileged \
--net host \
--name ct_data_plotter \
"${IMAGE_NAME}":v"${VERSION}" \
python3 /usr/local/bin/plot.py /bag --save /export/"$OUTPUT_NAME"
Loading