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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ CATKIN_IGNORE

# Hik camera log files
MvFGSdkLog
MvSdkLog
MvSdkLog

# SSH key files
id_rsa
id_rsa.pub

3 changes: 3 additions & 0 deletions .script/service-remote.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

/bin/ssh remote "service rmcs $1"
48 changes: 48 additions & 0 deletions .script/service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#! /bin/bash

set -e

start() {
if [[ -z "$HOME" ]]; then
export HOME=/root
fi
source /opt/ros/humble/setup.bash
source /rmcs_install/setup.bash
nohup ros2 launch rmcs_bringup rmcs.launch.py &> rmcs.launch.out 2>&1 & echo $! > /tmp/rmcs.pid
}

stop() {
if [ -f "/tmp/rmcs.pid" ]; then
pkill -P "$(cat /tmp/rmcs.pid)"
fi
}

check_running() {
if [ -f "/tmp/rmcs.pid" ]; then
if ps -p "$(cat /tmp/rmcs.pid)" > /dev/null
then
echo 'Fatal: RMCS daemon is still running!'
exit 1
fi
fi
}

case "$1" in
start)
check_running
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo 'Usage: /etc/init.d/rmcs {start|stop|restart}'
exit 1
;;
esac

exit 0
32 changes: 32 additions & 0 deletions .script/set-remote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/python3

import sys
import re
import os

if len(sys.argv) == 1:
print("Fatal: No arguments provided. Please provide the IP of the remote host.")
sys.exit(1)
elif len(sys.argv) > 2:
print(
"Fatal: Too many arguments provided. Please provide only the IP of the remote host."
)
sys.exit(1)

ssh_path = os.path.join(os.getenv("HOME"), ".ssh", "config")
try:
with open(ssh_path, "r") as file:
config = file.read()
updated_config, updated_count = re.subn(
r"Host remote\n HostName [^\n]+",
f"Host remote\n HostName {sys.argv[1]}",
config,
)
if updated_count == 0:
print("Fatal: Cannot find any place to modify in SSH config.")
sys.exit(1)
with open(ssh_path, "w") as file:
file.write(updated_config)
except FileNotFoundError:
print("Fatal: SSH config file not found.")
sys.exit(1)
3 changes: 3 additions & 0 deletions .script/ssh-remote.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

ssh remote
6 changes: 6 additions & 0 deletions .script/sync-remote.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

SRC_DIR=rmcs_ws/install
DST_DIR=ssh://remote//rmcs_install

unison -auto -batch -repeat watch -times ${SRC_DIR} ${DST_DIR} -force ${SRC_DIR}
6 changes: 6 additions & 0 deletions .ssh/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Host remote
HostName 127.0.0.1
Port 2022
User root
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
98 changes: 71 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# 23.0 is the minimum docker engine version that required to build.
# If your docker engine lower than this version, please upgrade it or manually enable the BuildKit.



# Base container, provides a runtime environment
FROM ros:humble AS rmcs-base

WORKDIR /

# Change bash as default shell instead of sh
SHELL ["/bin/bash", "-c"]

Expand All @@ -28,54 +31,95 @@ RUN wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCT
rm -rf /var/lib/apt/lists/* && \
rm ./GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB

# Download RMCS source, fix dependencies and compile
RUN git clone --recurse-submodules https://github.com/Alliance-Algorithm/RMCS && \
cd RMCS/rmcs_ws && \
source /etc/profile && \
# Mount rmcs source, fix dependencies and compile
RUN --mount=type=bind,target=/tmp/rmcs_ws/src,source=rmcs_ws/src,readonly \
cd /tmp/rmcs_ws && \
source /opt/ros/humble/local_setup.bash && \
apt-get update && \
rosdep install --from-paths src --ignore-src -r -y && \
rm -rf /var/lib/apt/lists/* && \
colcon build && \
mv ./install /rmcs-install && cd / && \
rm -rf RMCS


# Runtime container, will automatically launch the main program
FROM rmcs-base AS rmcs-runtime
colcon build --install-base /rmcs_install --merge-install && \
rm -rf build log

RUN echo '#!/usr/bin/bash' > /entrypoint.bash && \
echo 'source /opt/ros/humble/setup.bash' >> /entrypoint.bash && \
echo 'source /rmcs-install/setup.bash' >> /entrypoint.bash && \
echo 'ros2 launch rmcs_bringup rmcs.launch.py' >> /entrypoint.bash && \
chmod +x /entrypoint.bash
# Install unison to allow file synchronization
RUN cd /tmp && \
wget -O unison.tar.gz https://github.com/bcpierce00/unison/releases/download/v2.53.4/unison-2.53.4-ubuntu-x86_64.tar.gz && \
mkdir -p unison && tar -zxf unison.tar.gz -C unison && \
cp unison/bin/* /usr/local/bin && \
rm -rf unison unison.tar.gz

ENTRYPOINT [ "/entrypoint.bash" ]


# Developing container, works with devcontainer
FROM rmcs-base AS rmcs-develop

# Install develop tools (clangd/zsh/etc...)
# Install develop tools (ssh/clangd/zsh/etc...)
RUN apt-get update && apt-get -y install \
lsb-release software-properties-common gnupg zsh sudo && \
openssh-client \
lsb-release software-properties-common gnupg zsh sudo \
libcanberra-gtk-module libcanberra-gtk3-module && \
rm -rf /var/lib/apt/lists/* \
echo -e "\n" | bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" && \
ln -s /usr/bin/clangd-* /usr/bin/clangd

RUN apt-get -y install libcanberra-gtk-module libcanberra-gtk3-module

# Add user
RUN useradd -m developer --shell /bin/zsh && echo "developer:developer" | chpasswd && adduser developer sudo && \
echo "developer ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers && \
gpasswd --add developer dialout

# Set user
USER developer
WORKDIR /home/developer
ENV USER=developer
ENV WORKDIR=/home/developer

# Generate ssh secret key & profile unison
RUN --mount=type=bind,target=/tmp/.ssh,source=.ssh,readonly \
mkdir -p .ssh && \
if [ ! -f "/tmp/.ssh/id_rsa.pub" ]; then ssh-keygen -N "" -f ".ssh/id_rsa"; fi && \
cp -r /tmp/.ssh/* .ssh && \
mkdir -p .unison && \
echo 'confirmbigdel = false' >> ".unison/default.prf" && \
chown -R 1000:1000 .ssh .unison

USER developer

# Install oh my zsh & change theme to af-magic
RUN set -eo pipefail && \
curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh && \
sed -i 's/ZSH_THEME=\"[a-z0-9\-]*\"/ZSH_THEME="af-magic"/g' .zshrc
sed -i 's/ZSH_THEME=\"[a-z0-9\-]*\"/ZSH_THEME="af-magic"/g' .zshrc

COPY --chown=root:root .script/set-remote.py /usr/local/bin/set-remote
COPY --chown=root:root .script/ssh-remote.sh /usr/local/bin/ssh-remote
COPY --chown=root:root .script/sync-remote.sh /usr/local/bin/sync-remote
COPY --chown=root:root .script/service-remote.sh /usr/local/bin/service-remote



# Runtime container, will automatically launch the main program
FROM rmcs-base AS rmcs-runtime

# Install ssh server
RUN apt-get update && \
apt-get install -y openssh-server && \
rm -rf /var/lib/apt/lists/* && \
echo 'Port 2022' >> /etc/ssh/sshd_config && \
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config && \
echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config

# Add tini
RUN wget -O /tini https://github.com/krallin/tini/releases/download/v0.19.0/tini && \
chmod +x /tini

# Entrypoint
RUN echo '#!/usr/bin/bash' > /entrypoint.sh && \
echo 'rm -rf /tmp/*' >> /entrypoint.sh && \
echo 'service ssh restart' >> /entrypoint.sh && \
echo 'service rmcs restart' >> /entrypoint.sh && \
echo 'sleep infinity' >> /entrypoint.sh && \
chmod +x /entrypoint.sh

COPY --chown=root:root .script/service.sh /etc/init.d/rmcs
COPY --from=rmcs-develop --chmod=600 --chown=root:root /home/developer/.ssh/id_rsa.pub /root/.ssh/authorized_keys

WORKDIR /root/

ENTRYPOINT ["/tini", "--"]
CMD [ "/entrypoint.sh" ]
2 changes: 1 addition & 1 deletion rmcs_ws/src/ugas
Submodule ugas updated 2 files
+16 −8 src/main.cpp
+27 −0 src/util/fps_counter.h