Repository navigation
ci: Build the ROS test image with a layer cache - #1303
MatthijsBurgh wants to merge 1 commit into
Conversation
Every CI job rebuilt the rosbridge test image from scratch inside the test setup, taking 45-135s per job, and three times per ROS distro (once per Node.js version). Build the image in the workflow with Buildx and a GitHub Actions cache scoped per distro, and add ROSLIB_SKIP_IMAGE_BUILD so the test setup uses that image instead of rebuilding it. Locally the tests still build the image unless the variable is set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the CI image-caching and prebuilt-image reuse changes.
No open issues 🎉
What changed in this PR
This PR moves ROS test-image builds into the CI workflow so Docker layers can be cached across runs, while preserving the default local test setup.
Changes:
- Build and load test images with a per-ROS-distro GitHub Actions layer cache before installing dependencies.
- Add
ROSLIB_SKIP_IMAGE_BUILDto reuse an existing image, with a missing-image check. - Document prebuilt-image usage and when manual rebuilding is needed.
| File | Description |
|---|---|
packages/roslib/test/setup/ros-backend.ts |
Supports reusing a prebuilt image and checks that it exists. |
packages/roslib/README.md |
Documents the skip-build option and rebuild requirements. |
.github/workflows/main.yml |
Adds cached image builds and enables image reuse during tests. |
Review effort: Balanced
|
Timings with a warm cache (rerun of this PR's CI). The baseline is a recent
The first run on a new cache is slower (image step 73–166s) because it also saves the layers. That only happens when the noetic is still the slowest image step (~45s), mostly from pulling its base image and loading the result into Docker. |
There was a problem hiding this comment.
I'm not sure we should need any changes to this file; if the built image is identical, the docker daemon should handle that for us, I would think
Problem
Most of each CI job's time goes to building the rosbridge test image. The test setup (
test/setup/ros-backend.ts) rebuilt it from scratch in every job, with no layer cache, which took 45–135s per job (noetic is slowest). The tests themselves take about 20s. The same image was also built three times per ROS distro, once per Node.js version.Change
roslibjs-test:<distro>withdocker/build-push-actionbefore the tests. It uses a GitHub Actions layer cache (type=gha) scoped per distro, so theapt-get update+rosdep installlayer is only rebuilt when theDockerfileorpackage.xmlchanges. All jobs of a distro share the cache, and PRs read the cache saved bydevelop. The image is built beforenpm ciso the build context stays small.ROSLIB_SKIP_IMAGE_BUILDvariable. When set, the tests use the existingroslibjs-test:$ROS_DISTROimage instead of rebuilding it, and fail with a clear message if the image doesn't exist. Locally nothing changes unless you set it. It's documented in the README next toROSLIB_EXTERNAL_BACKEND.Testing
Run locally against jazzy:
docker buildx build --loadfollowed byROSLIB_SKIP_IMAGE_BUILD=1 npm test: 16 test files passed and 2 skipped; 95 tests passed and 7 skipped (the skips are distro-specific).Image roslibjs-test:jazzy not found. Build it first, or unset ROSLIB_SKIP_IMAGE_BUILD ….Expected effect, to be confirmed by CI
The first run on this PR has a cold cache, so it will be about as slow as before. Later runs, and runs after this lands on
develop, should mostly pull the base image and restore cached layers. One unknown:load: trueexports the full image, base layers included, from Buildx into the Docker daemon. On the 2-core runners that export may cost more than expected, especially for humble and jazzy, which built fastest before. I'll compare step timings on a warm-cache run before merging.🤖 Generated with Claude Code