perf: reduce docker#13
Conversation
…on + ML workflows - Fix CUDA waste: drop /usr/local/cuda-11.6 (torch cu121 is self-contained via bundled nvidia-* pip packages). Pin --no-nvidia in build.sh and retire the -cuda tag variants. - Add docker/slim.sh (export/import flatten) to reclaim bytes that union FS whiteouts leave behind (apt purge of openjdk, pipx venv, non-English locales, __pycache__). --mode buildable is the default and preserves the C/C++ toolchain, ROS/Autoware headers, .a files (rviz_ogre_vendor re-exports libOgreGLSupport.a via CMake) and libLLVM (Mesa llvmpipe). --mode ml-only is available for pytorch-only variants. - Restore apt packages that were implicitly pulled by the old CUDA build and are required by aichallenge-racingkart's colcon build: xacro, topic_tools, nav2_msgs, rviz2 + 5 rviz siblings, qtbase5-dev, qttools5-dev, libgeographic-dev, geographiclib-tools, libboost-dev, python3-plotly. - Runtime cleanup in Dockerfile no longer deletes /usr/lib/gcc, /usr/include, /opt/ros/humble/include or Autoware install headers — those broke downstream compilation (cc1 / Scrt1.o / rclcpp.hpp / autoware_auto_control_msgs missing). Verified on RTX 2080 Ti host: - Upstream ./docker/build.sh produces :humble-latest at 7.56 GB - aichallenge-racingkart ./docker_build.sh dev + make autoware-build (colcon 22/22 packages) + make dev (AWSIM + Autoware containers running) - ml_workspace/tiny_lidar_net train.py runs 3 epochs on CUDA with loss decreasing; convert_weight.py produces .npy output
…Dockerfile - Wrap `pip uninstall ansible … || true` in braces so the fallback does not mask failures of the preceding `setup-dev-env.sh` run (SC2015). - Add `# hadolint ignore=DL3042` above the devel-stage pip install since the build intentionally relies on a BuildKit cache mount rather than `--no-cache-dir`.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fe95915035
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| WORKDIR {{ .Config.WorkingDir }} | ||
| USER {{ .Config.User }} | ||
| ENTRYPOINT {{ json .Config.Entrypoint }} | ||
| CMD {{ json .Config.Cmd }} | ||
| {{ range $p, $_ := .Config.ExposedPorts }}EXPOSE {{ $p }} |
There was a problem hiding this comment.
Preserve SHELL metadata when flattening images
This flattening path reconstructs image config from a fixed --change list that excludes SHELL, so the imported runtime image falls back to Docker’s default /bin/sh -c instead of the Dockerfile’s bash shell. Because downstream images commonly rely on bash-only RUN forms like source ..., this can break derivative Dockerfiles even though buildable is intended to preserve that workflow; docker image import only supports metadata changes such as CMD/ENTRYPOINT/ENV/.../WORKDIR, not SHELL.
Useful? React with 👍 / 👎.
| which gcc-11 g++-11 cmake colcon | ||
| test -d /opt/ros/humble/include && echo "ros headers OK" | ||
| test -d /usr/include/c++ && echo "c++ headers OK" | ||
| ' || echo "⚠ smoke test failed — inspect before using" |
There was a problem hiding this comment.
Make smoke-test failures block publishing
The smoke test result is explicitly ignored with || echo, so slimming can produce an image missing torch/rclpy/build tools and still exit successfully. Since docker/build.sh unconditionally runs slim.sh and then tags the result as ...-latest-runtime and ...-latest, this allows broken images to be promoted to canonical tags without any hard failure.
Useful? React with 👍 / 👎.
Reduce Docker image size while preserving colcon + ML training workflows
Summary
ghcr.io/automotiveaichallenge/autoware-universe:humble-latestを 13.8 GB → 7.56 GB(−45%) に削減。aichallenge-racingkart下流のcolcon build/ AWSIM 起動 / ml_workspace の PyTorch 学習が全て動作することを実機で確認済。Motivation
humble-latest(旧 13.8 GB) は/usr/local/cuda-11.6(~3.9 GB、torch は pip 経由nvidia-*で自己完結しているため未使用)、pipx ansible venv (~422 MB)、/usr/share/doc(~160 MB)、および Docker union FS の下層レイヤーで whiteout'd されたが物理削除されていないデータを多量に含んでいた。aichallenge-racingkartは ML 学習 (pytorch) + Autoware ノードビルド + AWSIM シミュレータを同じベースイメージの上で走らせる。軽量化に伴い必要な apt 依存が暗黙に切れていたため、packages.txt を拡充して build 可用性を保証。Changes
docker/autoware-universe/Dockerfilesetup-dev-env.sh --no-nvidiaをビルドスクリプトで固定し、base stage の同一 RUN でrm -rf /usr/local/cuda*を実行(union FS レイヤー原則により、同一 RUN でないと物理削除されない)。/usr/lib/gcc(cc1 等を含む)、/usr/include(libstdc++ のbits/を含む)、/opt/ros/humble/include、/autoware/install/*/include、全.aファイルを保持。これらは下流colcon buildが参照するため。/root/.local/pipxはパス誤りで 422 MB 残っていた →/root/.local/share/pipxを追加。/root/.ansible,/usr/share/doc-base,/usr/share/info。ARG SETUP_ARGS廃止(常に--no-nvidia)。docker/build.sh--no-nvidiaオプションと-cudaサフィックス付きタグ生成を廃止(torch cu121 は pip 同梱nvidia-*で完全自己完結するため CUDA 変種は存在意義がない)。docker/slim.sh --mode buildableを自動実行。:humble-latestを:humble-latest-runtimeのエイリアスとして付与(racingkart 等の下流互換性のため)。--allow=ssh明示対応。docker/slim.sh(新規)docker export | docker importによる flatten で、Docker union FS では物理削除できないサイズを回収する後処理スクリプト。--mode buildable(default): colcon build 可用性を維持。openjdk-*,/usr/lib/jvm,__pycache__, 非英語 locale のみ削除。/usr/lib/llvm-*は Mesa の swrast/llvmpipe がlibLLVM.soに動的リンクしているため保持(CPU-only インスタンスで rviz2 をソフトウェアレンダリング起動する際に必要)。--mode ml-only: さらに C/C++ toolchain とヘッダーも削除(ML 学習専用、rclpy は削除される)。apt-mark manualでpython3 / rclpy / ros-humble-ros-core等を保護。docker/test_ml_workspace.sh(新規)ml_workspace の tiny_lidar_net パイプライン相当(torch GPU + TinyLidarNet 構築 + forward/backward/optim 5 step)を実データなしで回す smoke test。
packages.txt(拡充)--no-nvidia化に伴い暗黙に欠落していた apt パッケージを明示追加:ros-humble-xacro,ros-humble-topic-tools,ros-humble-nav2-msgsros-humble-rviz2+rviz-common/rviz-default-plugins/rviz-rendering/rviz-ogre-vendor/rviz-assimp-vendor(autoware_overlay_rviz_pluginがament_auto_find_build_dependencies経由で rviz_common 側のfind_dependency(Qt5)に依存してqt5_wrap_cppを取得する、暗黙の推移的連鎖を成立させるため)qtbase5-dev,qttools5-devlibgeographic-dev,geographiclib-toolslibboost-dev,python3-plotly.github/workflows/update-docker-manifest.yamllatest-cuda/latest-prebuilt-cudaエイリアスジョブ削除。docker/reduce.md/CLAUDE.md運用注意と不変条件を更新。
Image size comparison
ghcr.io/.../autoware-universe:humble-latesthumble-latest-runtime(=humble-latest)humble-latest-develhumble-latest-prebuiltaichallenge-2025-dev(下流)Verified items
Upstream (awsim-autoware)
./docker/build.shが成功 (humble-latest-runtime= 7.56 GB)slim.sh --mode buildableが自動実行され.aと C/C++ toolchain を保持ARG SETUP_ARGS廃止後も CIdocker-build-and-push-main.yamlが動く (matrix のsetup-argsは以後 no-op)import torch; torch.cuda.is_available()でTrue(RTX 2080 Ti 実機確認)echo 'int main(){}' | gcc -xc -がリンクまで通る#include <rclcpp/rclcpp.hpp>が/opt/ros/humble/include/rclcppから解決/autoware/install/autoware_auto_control_msgs/include等の Autoware パッケージヘッダーが保持/usr/local/cuda*が存在しない(torch の ldd でlibcudart.so.12が/usr/local/lib/python3.10/dist-packages/nvidia/cuda_runtime/lib/から解決されることを確認)/root/.local/share/pipxが削除済(422 MB 回収)/usr/share/doc/doc-base/info/ 非英語 locale 削除済Downstream (aichallenge-racingkart)
./docker_build.sh dev成功 →aichallenge-2025-dev:latest(8.91 GB) ビルドmake autoware-buildでcolcon buildが 22/22 packages 成功(エラーゼロ、stderr 出力は ament の "header install destination" 警告のみ)make devで AWSIM + Autoware の 2 コンテナ起動、20 秒以上連続稼働ros2 node listで Autoware ノード群が登録済(ekf_localizer, gyro_odometer, mpc_controller, racing_kart_gnss_poser, rviz2 等)ros2 topic listで AWSIM 連携 topic (/awsim/control_cmd,/awsim/state等) と Autoware 制御 topic (/control/command/control_cmd等) が publish されているmake downでクリーンシャットダウンML training (ml_workspace/tiny_lidar_net) — GPU 実機
python3 train.pyが Hydra config を正しく読み込みMultiSeqConcatDatasetで複数シーケンスを ConcatDataset 化(2 train seq + 1 val seq, 1000/200 samples).to(device)成功best_model.pth/last_model.pth保存成功(/tmp/ckpts/)convert_weight.py --model tinylidarnet --ckpt best_model.pthがweights/converted_weights.npyを出力(deploy 用の .pth→.npy 変換)hydra-core,omegaconf,tensorboard,h5py,hdf5plugin,jaxtyping,tqdm,rosbagsの import がすべて通る3 variant smoke test (GPU 学習 forward/backward) — 参考
--mode buildable(本 PR 採用)--mode ml-onlyTest plan
./docker/build.sh --clean-cache(フレッシュビルド) で 7.56 GB の runtime image が生成されるaichallenge-racingkartで./docker_build.sh dev && make autoware-build && make devがエラーなく完走docker run --gpus all aichallenge-2025-dev:latest python3 /aichallenge/ml_workspace/tiny_lidar_net/train.py ...で実学習が回るros2 node list/ros2 topic listで Autoware + AWSIM の通信を確認humble-latestを pull できること(別 PR で実施予定、権限調整待ち)Known caveats
--no-nvidia固定のため、tensorrt_yolo / lidar_centerpoint 等の CUDA ベースノードは実行不可。pytorch は pip 同梱nvidia-*で動作する。必要になった場合はdocker/reduce.mdの巻き戻し手順を参照。apt installを再実行しても動くよう/var/lib/apt/listsを再取得可能な状態で保持: ただしapt-mark manualによる保護リストに無いros-humble-*を purge する際はカスケードに注意。.a/ headers は意図的に保持:rviz_ogre_vendorがlibOgreGLSupport.aをIMPORTEDtarget として export する CMake 設定があるため。削除すると下流 CMake が "file does not exist" で fail する(実機で再現確認済)。References
docker/reduce.md— 本作業の経緯と Docker union FS 原則の詳説docker/slim.sh— flatten 方式の後処理スクリプトdocker/test_ml_workspace.sh— ml_workspace 用 smoke test