对照原 rdk-sandbox 实现 (entrypoint 契约 + compose + SOP) 补齐: - Dockerfile 增 Node.js + OpenClaw 网关层 (原沙箱镜像同款) - entrypoint 增三项沙箱动作: 每次启动重生成 SSH host key (同镜像 容器不共享密钥)、/workspace 全新样例工作副本、openclaw gateway 后台启动; PYTHONPATH 补 /app/pydev_demo - build.sh 打沙箱 compose 契约别名 tag: nashem -> rdk-sandbox-ssh, nashp -> rdk-sandbox-ssh-s600 (平台 docker-compose*.yml 免改直接换) - ros2 源装 ROS 官方公钥 (F42ED6FBAB17C654) 并从 trusted=true 改 signed-by, 消除 apt-get update GPG 告警 双板验收全绿: sshd 横幅/别名 tag/node v24/openclaw 网关进程/workspace 副本/hostkey 重启后变化/apt update 0 告警; verify 11/11
208 lines
10 KiB
Docker
208 lines
10 KiB
Docker
# rdk_runtime 板端运行时镜像 (全内置版)
|
|
#
|
|
# 与 app_base 的"通用镜像 + 运行时挂载"路线相反, 本镜像把板卡环境全部内置:
|
|
# - TROS/ROS/hobot 栈: 走与宿主机完全相同的 apt 源 (d-robotics + tuna ros2),
|
|
# 并锁定为宿主机当前版本 (build.sh 生成 pkg-pins.txt), 固件同源一致;
|
|
# - /app 案例与硬件 python 包 (hbm_runtime/Hobot.GPIO): 直接从目标板拷贝,
|
|
# 保证镜像内 APP 源与板卡一致、python 包与固件 ABI 匹配;
|
|
# - 运行时仅 --device 透传 (见 run.sh), 不 bind-mount 任何宿主目录。
|
|
#
|
|
# 板型参数 (build.sh 自动传入, 也可手动):
|
|
# nashem (S100/S100P): BASE_IMAGE=ubuntu:22.04 RDK_SUITE=ubuntu-rdk-s100-beta CODENAME=jammy ROS_DISTRO=humble PYTHON_VER=3.10
|
|
# nashp (RDK S600): BASE_IMAGE=ubuntu:24.04 RDK_SUITE=ubuntu-rdk-s600-beta CODENAME=noble ROS_DISTRO=jazzy PYTHON_VER=3.12
|
|
#
|
|
# 构建上下文由 build.sh 在目标板上组装 (app/ pkg-pins.txt requirements.lock
|
|
# py_overrides/ board-etc-version build-info.txt app-manifest.txt), 不要手动 docker build。
|
|
ARG BASE_IMAGE=ubuntu:22.04
|
|
FROM ${BASE_IMAGE}
|
|
|
|
ARG RDK_SUITE=ubuntu-rdk-s100-beta
|
|
ARG CODENAME=jammy
|
|
ARG ROS_DISTRO=humble
|
|
ARG PYTHON_VER=3.10
|
|
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
ENV ROS_DISTRO=${ROS_DISTRO}
|
|
|
|
# ============================================================
|
|
# apt 源: tuna 基础源 (arm64 base 默认源在 ports.ubuntu.com, 极慢)
|
|
# + d-robotics 专属源 (hobot 栈 / TROS, 与宿主机 sunrise.list 同源)
|
|
# + tuna ros2 源 (ROS 发行版, 与宿主机 multistrap-tsinghua-ros2.list 同源)
|
|
# ============================================================
|
|
RUN sed -i 's|ports.ubuntu.com/ubuntu-ports|mirrors.tuna.tsinghua.edu.cn/ubuntu-ports|g' /etc/apt/sources.list 2>/dev/null || true; \
|
|
sed -i 's|ports.ubuntu.com/ubuntu-ports|mirrors.tuna.tsinghua.edu.cn/ubuntu-ports|g' /etc/apt/sources.list.d/*.sources 2>/dev/null || true
|
|
COPY apt/sunrise.gpg /usr/share/keyrings/sunrise.gpg
|
|
RUN printf 'deb [arch=arm64 signed-by=/usr/share/keyrings/sunrise.gpg] http://archive.d-robotics.cc/%s %s main\n' "$RDK_SUITE" "$CODENAME" > /etc/apt/sources.list.d/sunrise.list \
|
|
&& printf 'deb [arch=arm64 trusted=true] http://mirrors4.tuna.tsinghua.edu.cn/ros2/ubuntu %s main\n' "$CODENAME" > /etc/apt/sources.list.d/ros2.list
|
|
|
|
# ============================================================
|
|
# 通用工具层 (沿用 app_base 已验证清单: 工具链/调试/网络/SSH)
|
|
# ============================================================
|
|
RUN apt-get update && apt-get install -y \
|
|
build-essential \
|
|
cmake \
|
|
pkg-config \
|
|
libgflags-dev \
|
|
libfmt-dev \
|
|
libcjson-dev \
|
|
nlohmann-json3-dev \
|
|
gdb \
|
|
strace \
|
|
python3 \
|
|
python3-pip \
|
|
python3-venv \
|
|
python-is-python3 \
|
|
python3-colcon-common-extensions \
|
|
git \
|
|
wget \
|
|
curl \
|
|
vim \
|
|
tmux \
|
|
less \
|
|
file \
|
|
bzip2 \
|
|
xz-utils \
|
|
iputils-ping \
|
|
net-tools \
|
|
iproute2 \
|
|
htop \
|
|
rsync \
|
|
sudo \
|
|
alsa-utils \
|
|
kmod \
|
|
i2c-tools \
|
|
libsndfile1-dev \
|
|
libsamplerate0-dev \
|
|
openssh-server \
|
|
locales \
|
|
&& mkdir -p /var/run/sshd \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# 配置中文 locale (防止终端中文乱码)
|
|
RUN locale-gen zh_CN.UTF-8 && update-locale LANG=zh_CN.UTF-8
|
|
|
|
# SSH 调试入口 (root:root, 与 app_base / 沙箱镜像一致)
|
|
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config \
|
|
&& sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config \
|
|
&& echo "MaxAuthTries 3" >> /etc/ssh/sshd_config \
|
|
&& echo "MaxStartups 3:50:10" >> /etc/ssh/sshd_config \
|
|
&& echo "LoginGraceTime 30" >> /etc/ssh/sshd_config \
|
|
&& echo "ClientAliveInterval 60" >> /etc/ssh/sshd_config \
|
|
&& echo "ClientAliveCountMax 3" >> /etc/ssh/sshd_config \
|
|
&& ssh-keygen -A \
|
|
&& echo 'root:root' | chpasswd
|
|
|
|
# ============================================================
|
|
# pip 引导 + hbm_runtime 源码构建工具链 (与宿主机同版本, build.sh 生成锁)
|
|
# hobot-dnn 的 postinst 会现场构建 hbm_runtime wheel 并以 clean 收尾:
|
|
# 新版 scikit-build-core CLI 无 clean 子命令(rc!=0)会令 postinst 失败,
|
|
# 预置宿主机版本后 postinst 的 "pip3 show 已装则跳过" 会直接沿用。
|
|
# (先升级 pip 以统一支持 --break-system-packages, 22.04 自带 pip 无此选项)
|
|
# ============================================================
|
|
COPY pip-build-tools.lock /tmp/pip-build-tools.lock
|
|
# 22.04 自带 pip 22.x 无 --break-system-packages 选项, 需先升级 pip;
|
|
# 24.04 自带 pip 24.0 已支持该选项, 跳过升级 (升级 debian 管理的 pip 会因
|
|
# RECORD 缺失失败)。后续层的硬编码 --break-system-packages 在两条线上都成立。
|
|
RUN set -e; \
|
|
if pip3 install --help 2>/dev/null | grep -q -- --break-system-packages; then \
|
|
PIPFLAG="--break-system-packages"; \
|
|
else \
|
|
pip3 install --no-cache-dir --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple; \
|
|
PIPFLAG="--break-system-packages"; \
|
|
fi; \
|
|
pip3 install --no-cache-dir $PIPFLAG -i https://pypi.tuna.tsinghua.edu.cn/simple -r /tmp/pip-build-tools.lock; \
|
|
rm -f /tmp/pip-build-tools.lock
|
|
|
|
# ============================================================
|
|
# 板卡栈层: TROS / ROS / hobot (与宿主机同源同版本)
|
|
# pkg-pins.txt 由 build.sh 按宿主机 dpkg 版本生成, 形如 "pkg=version"
|
|
# (或 --no-pin 模式下的纯包名)。tros 元包会带上全部 tros-* 组件与模型包。
|
|
# ============================================================
|
|
COPY pkg-pins.txt /tmp/pkg-pins.txt
|
|
RUN apt-get update \
|
|
&& xargs -a /tmp/pkg-pins.txt apt-get install -y --allow-downgrades \
|
|
&& apt-get install -y ros-${ROS_DISTRO}-ros-base \
|
|
&& rm -f /tmp/pkg-pins.txt \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# hobot 包未声明 Depends 的系统库 + devmem 适配补丁层:
|
|
# 1. libdnn.so / hrt_model_exec / hbm_runtime 均链 libcjson.so.1 (宿主机由
|
|
# ubuntu 仓库 libcjson1 提供), 缺它 BPU 全链路不可用;
|
|
# 2. hobot-utils 的 /usr/hobot/bin/devmem 是包装脚本, 实际调 /var/busybox/devmem
|
|
# (该路径任何包都不提供), 用 busybox 的 devmem applet 补位。
|
|
# 独立成层是为了不打破上方重型 apt 层的构建缓存。
|
|
RUN apt-get update && apt-get install -y --no-install-recommends libcjson1 busybox \
|
|
&& mkdir -p /var/busybox && ln -sf /bin/busybox /var/busybox/devmem \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# ============================================================
|
|
# Python 层
|
|
# 1. numpy/opencv/scipy 与宿主机同版本 (requirements.lock 由 build.sh 生成);
|
|
# 2. hobot_vio 来自 hobot-spdev apt 包自带的 wheel (上一步已装出 /usr/lib/hobot_spdev);
|
|
# 3. hbm_runtime / Hobot.GPIO 不走 pip, 由下一层从板端直接拷入 (与固件 ABI 匹配)。
|
|
# ============================================================
|
|
COPY requirements.lock /tmp/requirements.lock
|
|
RUN pip3 install --no-cache-dir --break-system-packages \
|
|
-i https://pypi.tuna.tsinghua.edu.cn/simple \
|
|
-r /tmp/requirements.lock \
|
|
&& pip3 install --no-cache-dir --break-system-packages /usr/lib/hobot_spdev/*.whl \
|
|
&& rm -f /tmp/requirements.lock
|
|
|
|
# ros2 源密钥规范化: 早期层用 trusted=true 引入源后, 此处装入 ROS 官方公钥
|
|
# (F42ED6FBAB17C654) 并改为 signed-by, 消除 apt-get update 的 GPG 告警
|
|
RUN set -e; \
|
|
curl -fsSL 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xF42ED6FBAB17C654' \
|
|
| gpg --dearmor --yes -o /usr/share/keyrings/ros-archive-keyring.gpg; \
|
|
sed -i 's|trusted=true|signed-by=/usr/share/keyrings/ros-archive-keyring.gpg|' /etc/apt/sources.list.d/ros2.list
|
|
|
|
# ============================================================
|
|
# Node.js 22 + OpenClaw (沙箱平台 AI 网关, 与原 rdk-sandbox 镜像对齐)
|
|
# ============================================================
|
|
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
|
|
&& apt-get install -y nodejs \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
RUN curl -fsSL https://openclaw.ai/install.sh | bash -s -- --no-onboard
|
|
|
|
# ============================================================
|
|
# 板端内容层: 硬件 python 包 overlay / 板卡标识 / 构建信息 / /app 全量案例
|
|
# /app 放最后一层 (体积最大, 便于其余层跨构建复用缓存)
|
|
# ============================================================
|
|
COPY py_overrides/ /usr/local/lib/python${PYTHON_VER}/dist-packages/
|
|
COPY board-etc-version /etc/version
|
|
COPY build-info.txt app-manifest.txt /etc/rdk-runtime-image/
|
|
COPY app/ /app/
|
|
|
|
# ============================================================
|
|
# 环境层: 路径与 app_base 约定一致, 但不再有 /host_lib /host_inc ——
|
|
# 板卡库/头文件已在镜像内真实路径上 (apt 装出 /usr/hobot, ldconfig 已覆盖)
|
|
# ============================================================
|
|
# ros2 CLI 在下层 /opt/ros/<distro>/bin (ros-base 包), TROS 本体无 bin/;
|
|
# 双路径让 docker exec (不经 entrypoint source) 也能直接用 ros2
|
|
ENV PATH=/opt/ros/${ROS_DISTRO}/bin:/opt/tros/${ROS_DISTRO}/bin:/usr/hobot/bin:/app/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|
ENV AMENT_PREFIX_PATH=/opt/ros/${ROS_DISTRO}:/opt/tros/${ROS_DISTRO}
|
|
ENV PYTHONPATH=/opt/ros/${ROS_DISTRO}/lib/python${PYTHON_VER}/site-packages:/opt/tros/${ROS_DISTRO}/lib/python${PYTHON_VER}/site-packages:/app/pydev_demo
|
|
ENV LD_LIBRARY_PATH=/opt/ros/${ROS_DISTRO}/lib:/opt/tros/${ROS_DISTRO}/lib:/usr/hobot/lib:/usr/hobot/lib/sensor
|
|
ENV CPATH=/usr/hobot/include:/usr/include/cjson:/usr/include/opencv4
|
|
ENV LIBRARY_PATH=/usr/hobot/lib
|
|
ENV HOBOT_ROOTFS_DIR=/usr/hobot
|
|
ENV GST_PLUGIN_PATH=/usr/hobot/lib/gst-plugins
|
|
ENV LANG=zh_CN.UTF-8
|
|
ENV LC_ALL=zh_CN.UTF-8
|
|
ENV PYTHONUNBUFFERED=1
|
|
ENV ROS_DOMAIN_ID=0
|
|
|
|
# 交互 shell 自动加载 TROS 环境 (entrypoint 已导出给 sshd 子进程, 此处兜底)
|
|
RUN echo '[ -f /opt/tros/$ROS_DISTRO/setup.bash ] && . /opt/tros/$ROS_DISTRO/setup.bash || { [ -f /opt/ros/$ROS_DISTRO/setup.bash ] && . /opt/ros/$ROS_DISTRO/setup.bash; }' >> /root/.bashrc
|
|
|
|
# rdkos_info 适配: 内核不允许 bind-mount 到 /proc 下, 容器内 /proc/device-tree
|
|
# 无法提供; run.sh 会把宿主设备树挂到 /mnt/device-tree, 这里把读取路径指过去
|
|
RUN sed -i 's|/proc/device-tree|/mnt/device-tree|g' /usr/bin/rdkos_info
|
|
|
|
COPY entrypoint.sh /entrypoint.sh
|
|
RUN chmod +x /entrypoint.sh
|
|
ENTRYPOINT ["/entrypoint.sh"]
|
|
CMD ["/usr/sbin/sshd", "-D"]
|
|
|
|
WORKDIR /app
|