Skip to content

feat: add --image-mount flag to bake images-to-mount init scripts#121

Open
feloy wants to merge 3 commits into
openkaiden:mainfrom
feloy:imaes-to-mount
Open

feat: add --image-mount flag to bake images-to-mount init scripts#121
feloy wants to merge 3 commits into
openkaiden:mainfrom
feloy:imaes-to-mount

Conversation

@feloy

@feloy feloy commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Add support for loading images-to-mount YAML files and appending their shell init snippets to /sandbox/.bashrc and /sandbox/.zshrc inside the built image.

  • src/image_mount.rs (new): parse images-to-mount YAML files (local path or URL), derive the mount name from the filename stem, and replace $MOUNT with /sandbox/mnt/ in the init value.

  • src/containerfile.rs: introduce ContainerfileOptions struct to replace the positional argument list in generate(); add image_mount_inits field that emits printf calls appending each resolved init snippet to .bashrc and .zshrc in the same RUN layer that creates the profile files; add init_for_printf() helper that escapes backslashes, newlines, and single quotes for safe use in a single-quoted shell printf argument; add unit tests covering ordering, multiple mounts, single-quote escaping, and the no-mount-no-zshrc invariant.

  • src/main.rs: add --image-mount <PATH|URL> CLI flag (clap Append action, repeatable); thread image_mounts through run(); add unit tests for single mount, multiple mounts, and invalid path error.

  • tests/integration_test.rs: add image_mount module with integration tests (marked #[ignore] for those requiring podman) covering .bashrc and .zshrc content, sandbox ownership, and absence of .zshrc when the flag is not used; add non-ignored binary smoke-test for the invalid-path error path; register cleanup of the new test image tag.

  • README.md: document the new flag — YAML format, $MOUNT substitution rule, files written, CLI examples, and option table entry.

How to use:

openshell-image-builder \
  --runtime podman \
  --agent claude \
  --image-mount https://raw.githubusercontent.com/feloy/images-to-mount/refs/heads/main/curl.yaml \
  --image-mount https://raw.githubusercontent.com/feloy/images-to-mount/refs/heads/main/git.yaml \
  claude-curl-git:1

DRIVER_CONFIG_JSON='{
  "podman": {
    "mounts": [
      {
        "type": "bind",
        "source": "'"$PWD"'",
        "target": "/sandbox/work",
        "read_only": false
      },
      {
        "type": "image",
        "source": "registry.access.redhat.com/hi/curl:latest",
        "target": "/sandbox/mnt/curl",
        "read_only": true
      },
      {
        "type": "image",
        "source": "registry.access.redhat.com/hi/git:latest",
        "target": "/sandbox/mnt/git",
        "read_only": true
      }
    ]
  }
}'

openshell sandbox create \
  --from claude-curl-git:1 \
  --driver-config-json "$DRIVER_CONFIG_JSON" \
  ...

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@feloy, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 37 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 26d88475-0649-4377-875a-fcab9bf8f6e7

📥 Commits

Reviewing files that changed from the base of the PR and between bfe1e0e and d75e815.

📒 Files selected for processing (3)
  • src/containerfile.rs
  • src/image_mount.rs
  • src/main.rs
📝 Walkthrough

Walkthrough

The PR adds --image-mount support to the image builder, from YAML loading and CLI wiring through Dockerfile generation, documentation, and integration tests. It appends resolved init snippets to both shell profile files inside the image and verifies the behavior end to end.

Changes

Image-mount build path

Layer / File(s) Summary
Docs and CLI flag
README.md, src/main.rs
The README and CLI definition describe --image-mount as a repeatable YAML path-or-URL input and add it to the option reference.
YAML loading and init expansion
src/image_mount.rs
The new module reads local or remote YAML, derives the mount name, expands $MOUNT in the init snippet, and verifies that behavior with unit tests.
Run wiring and generation inputs
src/main.rs
The binary threads mount arguments into run, loads each mount init, and passes the collected snippets into containerfile generation; related tests were updated for the new signature and mount-path errors.
Containerfile output
src/containerfile.rs
The containerfile generator now accepts grouped options, escapes mount init text for shell printf, writes it into both shell rc files, and expands unit coverage for ordering and escaping.
Integration coverage
tests/integration_test.rs
The integration test suite builds a cached image with --image-mount, checks the generated shell profile contents and ownership, and cleans up the new image tag.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding the --image-mount flag for image-to-mount init scripts.
Description check ✅ Passed The description matches the changeset and accurately describes the new flag, parsing, containerfile updates, tests, and docs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@feloy feloy force-pushed the imaes-to-mount branch from babb09b to fa28e69 Compare July 2, 2026 12:13
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.52809% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/image_mount.rs 93.69% 7 Missing ⚠️
src/main.rs 95.95% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/main.rs (1)

152-165: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

run() accepts 12 positional parameters, several of the same type.

Adjacent params like with_policy: bool, with_agent_settings: bool (and now with image_mounts inserted between other options) make call sites error-prone to read and easy to reorder incorrectly since the compiler won't catch a swap of two bool/Option<&str> args. The PR already introduces ContainerfileOptions for the sibling containerfile::generate call — applying the same pattern to run() would be more consistent and safer for future flag additions.

This would require updating the ~15 test call sites in this same file, so it's a larger change; flagging for awareness rather than as a blocking issue.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main.rs` around lines 152 - 165, run() has too many positional arguments,
including multiple adjacent bool and Option<&str> parameters, which makes call
sites easy to mix up. Refactor the run() API to take a single options struct,
similar to ContainerfileOptions used for containerfile::generate, and update the
internal callers and test call sites in main.rs to pass that struct instead of
many positional args. Use the run function and the nearby ContainerfileOptions
pattern as the main references when locating the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/containerfile.rs`:
- Around line 256-264: The init_for_printf helper currently escapes backslashes,
newlines, and single quotes, but it still leaves percent signs unescaped, which
can break shell printf formatting for user-provided init text. Update
init_for_printf to also escape % by doubling it before wrapping it in the
single-quoted printf string, and add a regression test covering an init value
containing % so the emitted containerfile output stays literal.

In `@src/image_mount.rs`:
- Around line 54-60: The URL branch in load_yaml_content currently uses the
default ureq::get(...).call(), which leaves socket timeouts unset and can block
indefinitely on slow or stalled URLs. Update the HTTP fetch path to use a
ureq::Agent configured with explicit read and write timeouts, then perform the
request through that agent instead of the default client. Keep the file path
branch unchanged and make sure the timeout-configured client is used only in the
HTTP/HTTPS branch of load_yaml_content.

In `@src/main.rs`:
- Around line 223-237: The image mount setup currently allows multiple
`--image-mount` entries to resolve to the same mount name and silently merge
their init snippets. Add a duplicate-name check in the `src/main.rs` flow that
builds `image_mount_inits` before calling `containerfile::generate`, using the
mount-name derivation from `image_mount::mount_name`/`load_init` to detect
collisions and return an error when two entries map to the same mount path. Keep
the fix localized to the image-mount collection path so
`containerfile::generate` only receives unique mount names.

---

Nitpick comments:
In `@src/main.rs`:
- Around line 152-165: run() has too many positional arguments, including
multiple adjacent bool and Option<&str> parameters, which makes call sites easy
to mix up. Refactor the run() API to take a single options struct, similar to
ContainerfileOptions used for containerfile::generate, and update the internal
callers and test call sites in main.rs to pass that struct instead of many
positional args. Use the run function and the nearby ContainerfileOptions
pattern as the main references when locating the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c1ff4a49-4991-42cc-bb9c-784ce7661bab

📥 Commits

Reviewing files that changed from the base of the PR and between babb09b and 6692467.

📒 Files selected for processing (5)
  • README.md
  • src/containerfile.rs
  • src/image_mount.rs
  • src/main.rs
  • tests/integration_test.rs
✅ Files skipped from review due to trivial changes (1)
  • README.md

Comment thread src/containerfile.rs
Comment thread src/image_mount.rs
Comment thread src/main.rs
@feloy feloy requested a review from jeffmaury July 6, 2026 07:30
@feloy feloy force-pushed the imaes-to-mount branch from 3511960 to fcd4b41 Compare July 6, 2026 07:52
feloy and others added 2 commits July 7, 2026 12:52
Add support for loading images-to-mount YAML files and appending their
shell init snippets to /sandbox/.bashrc and /sandbox/.zshrc inside the
built image.

- src/image_mount.rs (new): parse images-to-mount YAML files (local
  path or URL), derive the mount name from the filename stem, and
  replace $MOUNT with /sandbox/mnt/<name> in the init value.

- src/containerfile.rs: introduce ContainerfileOptions struct to
  replace the positional argument list in generate(); add
  image_mount_inits field that emits printf calls appending each
  resolved init snippet to .bashrc and .zshrc in the same RUN layer
  that creates the profile files; add init_for_printf() helper that
  escapes backslashes, newlines, and single quotes for safe use in a
  single-quoted shell printf argument; add unit tests covering
  ordering, multiple mounts, single-quote escaping, and the
  no-mount-no-zshrc invariant.

- src/main.rs: add --image-mount <PATH|URL> CLI flag (clap Append
  action, repeatable); thread image_mounts through run(); add unit
  tests for single mount, multiple mounts, and invalid path error.

- tests/integration_test.rs: add image_mount module with integration
  tests (marked #[ignore] for those requiring podman) covering .bashrc
  and .zshrc content, sandbox ownership, and absence of .zshrc when
  the flag is not used; add non-ignored binary smoke-test for the
  invalid-path error path; register cleanup of the new test image tag.

- README.md: document the new flag — YAML format, $MOUNT substitution
  rule, files written, CLI examples, and option table entry.

Co-authored-by: Claude <claude@anthropic.com>
Signed-off-by: Philippe Martin <phmartin@redhat.com>
mount_name() was using rsplit('/') to extract the filename from all
inputs. On Windows, local temp paths use backslash separators, so
the entire path was returned as the "last component" instead of just
the filename, producing broken mount paths like:
  /sandbox/mnt/C:\Users\...\curl.yaml

Fix by delegating to std::path::Path::file_name() for local paths,
which handles OS-native separators correctly. URL inputs (http/https)
continue to use rsplit('/') since URL paths always use forward slashes.

Co-authored-by: Claude <claude@anthropic.com>
Signed-off-by: Philippe Martin <phmartin@redhat.com>
@feloy feloy force-pushed the imaes-to-mount branch from fcd4b41 to bfe1e0e Compare July 7, 2026 12:57
- Escape % in init_for_printf so printf does not treat user-provided
  init text (e.g. export DATE_FMT=%Y-%m-%d) as format specifiers;
  add regression test.
- Add explicit 30 s read/write timeouts to the ureq agent used when
  fetching --image-mount URLs to prevent indefinite blocking.
- Reject duplicate --image-mount entries that resolve to the same
  mount name before calling containerfile::generate.

Co-authored-by: Claude <claude@anthropic.com>
Signed-off-by: Philippe Martin <phmartin@redhat.com>
@feloy feloy force-pushed the imaes-to-mount branch from bfe1e0e to d75e815 Compare July 7, 2026 13:19
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.

1 participant