Skip to content

ci: Build the ROS test image with a layer cache - #1303

Open
MatthijsBurgh wants to merge 1 commit into
developfrom
ci/cache-ros-test-image
Open

MatthijsBurgh wants to merge 1 commit into
developfrom
ci/cache-ros-test-image

Conversation

@MatthijsBurgh

Copy link
Copy Markdown
Contributor

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

  • Workflow: build roslibjs-test:<distro> with docker/build-push-action before the tests. It uses a GitHub Actions layer cache (type=gha) scoped per distro, so the apt-get update + rosdep install layer is only rebuilt when the Dockerfile or package.xml changes. All jobs of a distro share the cache, and PRs read the cache saved by develop. The image is built before npm ci so the build context stays small.
  • Test setup: new ROSLIB_SKIP_IMAGE_BUILD variable. When set, the tests use the existing roslibjs-test:$ROS_DISTRO image 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 to ROSLIB_EXTERNAL_BACKEND.

Testing

Run locally against jazzy:

  • docker buildx build --load followed by ROSLIB_SKIP_IMAGE_BUILD=1 npm test: 16 test files passed and 2 skipped; 95 tests passed and 7 skipped (the skips are distro-specific).
  • With the variable set and no image present: the setup fails with 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: true exports 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

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>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 10:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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_BUILD to 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

@MatthijsBurgh

Copy link
Copy Markdown
Contributor Author

Timings with a warm cache (rerun of this PR's CI). The baseline is a recent develop-based run (#1291) that also had an npm cache hit:

Before Warm cache
Image build per job 45–135s (inside npm test) 16–48s (own step)
Job total 126–226s (avg ~164s) 92–148s (avg ~121s)
Slowest job (noetic, sets wall-clock time) 226s 148s

The first run on a new cache is slower (image step 73–166s) because it also saves the layers. That only happens when the Dockerfile or package.xml changes, or when the cache is evicted.

noetic is still the slowest image step (~45s), mostly from pulling its base image and loading the result into Docker. npm ci (25–50s) is now the largest remaining cost per job; see the --ignore-scripts idea discussed separately.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants