Skip to content

Extend chroot mount helper to include cache directories #8186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2025

Conversation

benhoff
Copy link
Collaborator

@benhoff benhoff commented May 13, 2025

Description

This change enhances the mount_chroot() and umount_chroot() helper functions to:

  • Bind-mount the host’s /armbian/cache into ${target}/armbian/cache so that build artifacts and source caches are shared between host and chroot.
  • Update the unmount logic to detect and cleanly unmount the new mount.

Motivation & Context:

Current chroot helper does not bind the Armbian cache directory. When customizing the image, each build starts “from cold,” losing all previously downloaded sources and compiled artifacts. By adding this mounts, we:

  • Reuse download/build caches across chroot sessions, dramatically speeding up iterative development.

No downstream dependencies introduced.

How Has This Been Tested?

Tested working both cache and check the image to make sure that the cache was not included in the image.

Checklist

  • My code follows the project’s style guidelines
  • I have performed a self-review of my own code
  • [] I have commented hard-to-understand areas
  • [] My changes generate no new warnings
  • [] Any dependent changes have been merged and published in downstream modules

@benhoff benhoff requested a review from a team as a code owner May 13, 2025 01:29
Copy link
Contributor

coderabbitai bot commented May 13, 2025

Walkthrough

The mount_chroot function was updated to create the ${target}/armbian/cache directory and bind mount the host's /armbian/cache directory into this location within the chroot environment. The umount_chroot function was also modified to include ${target}/armbian/cache in its unmounting routine, ensuring this directory is unmounted during cleanup. No changes were made to function signatures or public entity declarations; all modifications are internal to the logic of the existing functions.

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added size/small PR with less then 50 lines 05 Milestone: Second quarter release Needs review Seeking for review Framework Framework components labels May 13, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
lib/functions/general/chroot-helpers.sh (4)

21-22: Ensure cache mountpoint exists and guard against missing host directory.

The new mkdir -p "${target}/armbian/cache" correctly creates the mount point inside the chroot. However, if the host’s /armbian/cache directory doesn’t exist, the subsequent bind mount will fail. Consider adding a check or a warning before creating and mounting:

+ if [[ ! -d /armbian/cache ]]; then
+   display_alert "Host cache directory /armbian/cache not found; skipping cache mount" "$target" "warn"
+ else
+   mkdir -p "${target}/armbian/cache"
+ fi

32-32: Bind-mount the host cache directory.

Binding /armbian/cache into the chroot is vital for sharing build and download caches. To tighten mount propagation and avoid leaking host mounts into the chroot (or vice versa), you could add a private propagation flag:

- mount --bind /armbian/cache "${target}/armbian/cache"
+ mount --bind /armbian/cache "${target}/armbian/cache"
+ # Make this bind-mount private to the chroot
+ mount --make-rprivate "${target}/armbian/cache"

43-43: Updated unmount loop to include cache.

Great catch on extending the grep -Eq pattern to cover armbian/cache. This ensures the cache bind-mount is recognized in the unmount loop. As a follow-up, you may want to update the downstream debug logging on line 54 to reflect all mount points:

-run_host_command_logged grep -E "'${target}/(dev|proc|sys|tmp)'" /proc/mounts "||" true
+run_host_command_logged grep -E "'${target}/(dev|proc|sys|tmp|var/tmp|run/user/0|armbian/cache)'" /proc/mounts "||" true

52-52: Unmount the cache directory.

Including umount "${target}/armbian/cache" || true guarantees cleanup of the cache bind mount. You might also consider a recursive unmount to catch nested mounts and removing the now-unused directory:

- umount "${target}/armbian/cache" || true
+ umount --recursive "${target}/armbian/cache" || true
+ rm -rf "${target}/armbian/cache"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c897044 and 916ffc8.

📒 Files selected for processing (1)
  • lib/functions/general/chroot-helpers.sh (4 hunks)

@benhoff benhoff marked this pull request as draft May 13, 2025 06:41
@benhoff benhoff changed the title [DRAFT] Extend chroot mount helper to include cache directories Extend chroot mount helper to include cache directories May 13, 2025
@benhoff benhoff marked this pull request as ready for review May 13, 2025 10:40
Copy link
Member

@igorpecovnik igorpecovnik left a comment

Choose a reason for hiding this comment

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

LGTM, should not make troubles.

@igorpecovnik igorpecovnik added the Ready to merge Reviewed, tested and ready for merge label May 14, 2025
@igorpecovnik igorpecovnik merged commit 9eaa276 into armbian:main May 14, 2025
1 check passed
@igorpecovnik
Copy link
Member

igorpecovnik commented May 14, 2025

should not make troubles.

🥲

When running without Docker:

./compile.sh build BOARD=bananapif3 BRANCH=current BUILD_DESKTOP=no BUILD_MINIMAL=yes KERNEL_CONFIGURE=no PREFER_DOCKER=no RELEASE=trixie

[🌱] Cleaning up after debootstrap [ debootstrap cleanup ]
mount: /home/igorp/Development/build/.tmp/rootfs-69e922e8-5398-47bb-9a19-f66b67db37f5/armbian/cache: special device /armbian/cache does not exist.
dmesg(1) may have more information after failed mount system call.
[💥] Cleaning up [ please wait for cleanups to finish ]

@benhoff
Copy link
Collaborator Author

benhoff commented May 15, 2025

should not make troubles.

🥲

When running without Docker:

./compile.sh build BOARD=bananapif3 BRANCH=current BUILD_DESKTOP=no BUILD_MINIMAL=yes KERNEL_CONFIGURE=no PREFER_DOCKER=no RELEASE=trixie

[🌱] Cleaning up after debootstrap [ debootstrap cleanup ] mount: /home/igorp/Development/build/.tmp/rootfs-69e922e8-5398-47bb-9a19-f66b67db37f5/armbian/cache: special device /armbian/cache does not exist. dmesg(1) may have more information after failed mount system call. [💥] Cleaning up [ please wait for cleanups to finish ]

Oh no! I didn't think about running without docker.

@igorpecovnik want to revert and I'll find a fix and then resubmit?

@igorpecovnik
Copy link
Member

If you can check / fix this within a week, we can wait. Its corner case.

@davidandreoletti
Copy link
Contributor

Armbian / Ubuntu Noble 24.04.x for native building or any Docker capable Linux for containerised

This is from the official aembizn doc. I am using the "native" build method and it's broken currently.

If that's acceptable, would you mind reverting until there is fix for "native builds"?

@igorpecovnik
Copy link
Member

OK, reverted until fixed.

@davidandreoletti
Copy link
Contributor

@igorpecovnik Thank you.

Is there a plan to phase out the "native build" at some point in favor of "docker based" build ?

@igorpecovnik
Copy link
Member

Is there a plan to phase out the "native build" at some point in favor of "docker based" build ?

No such plan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
05 Milestone: Second quarter release Framework Framework components Needs review Seeking for review Ready to merge Reviewed, tested and ready for merge size/small PR with less then 50 lines
Development

Successfully merging this pull request may close these issues.

3 participants