Skip to content

Comments

[jrubyscripting] Set .bundle directory to $USERDATA/cache/automation/ruby/.bundle#19604

Draft
jimtng wants to merge 5 commits intoopenhab:mainfrom
jimtng:jruby-bundle-cache
Draft

[jrubyscripting] Set .bundle directory to $USERDATA/cache/automation/ruby/.bundle#19604
jimtng wants to merge 5 commits intoopenhab:mainfrom
jimtng:jruby-bundle-cache

Conversation

@jimtng
Copy link
Contributor

@jimtng jimtng commented Nov 1, 2025

set BUNDLE_USER_HOME=$USERDATA/cache/automation/ruby/.bundle
set BUNDLE_USER_CONFIG=<Gemfile's directory>/.bundle/config (by default $CONF/automation/ruby/.bundle/config)

Resolve #19489

openhab> jrubyscripting bundle config                                                                                               
Settings are listed in order of priority. The top value will be used.
gemfile
Set via BUNDLE_GEMFILE: "/openhab/conf/automation/ruby/Gemfile"

user_config
Set via BUNDLE_USER_CONFIG: "/openhab/conf/automation/ruby/.bundle/config"

user_home
Set via BUNDLE_USER_HOME: "/openhab/userdata/cache/automation/ruby/.bundle"


openhab> jrubyscripting bundle config get clean 
Settings for `clean` in order of priority. The top value will be used
You have not configured a value for `clean`
openhab> jrubyscripting bundle config set clean true
openhab> jrubyscripting bundle config get clean
Settings for `clean` in order of priority. The top value will be used
Set for your local app (/openhab/conf/automation/ruby/.bundle/config): true
Set for the current user (/openhab/conf/automation/ruby/.bundle/config): true
root@da1c4ae2491c:/openhab# cd conf/automation/ruby/.bundle/
root@da1c4ae2491c:/openhab/conf/automation/ruby/.bundle# ls
config
root@da1c4ae2491c:/openhab/conf/automation/ruby/.bundle# cat config 
---
BUNDLE_CLEAN: "true"

…ruby/.bundle

BUNDLE_USER_HOME=$USERDATA/cache/automation/ruby/.bundle

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
@jimtng jimtng requested a review from ccutrer as a code owner November 1, 2025 15:12
Copy link
Contributor Author

@jimtng jimtng left a comment

Choose a reason for hiding this comment

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

If there's a need to use and retain the .bundle/config file, we can add a separate path in the future.

Copy link
Contributor Author

@jimtng jimtng left a comment

Choose a reason for hiding this comment

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

We could:

  • Make it configurable?
  • Put it as a sibling of the .gem directory instead of the userdata/cache ?

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
@jimtng
Copy link
Contributor Author

jimtng commented Nov 2, 2025

Added BUNDLE_USER_CONFIG - updated the OP

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
@jimtng
Copy link
Contributor Author

jimtng commented Nov 2, 2025

Hmm, the .bundle directory is still initially created inside ~openhab/

@jimtng
Copy link
Contributor Author

jimtng commented Nov 2, 2025

Hmm, the .bundle directory is still initially created inside ~openhab/

This is caused by the gemfile / inline bundler. It doesn't honour BUNDLE_USER_HOME nor BUNDLE_APP_CONFIG env vars.

@jimtng jimtng marked this pull request as draft November 2, 2025 03:56
@jimtng
Copy link
Contributor Author

jimtng commented Nov 2, 2025

I haven't found a way to make the inline bundler to use the custom .bundle directory. I have tried setting BUNDLE_USER_HOME and BUNDLE_APP_CONFIG as system property but that didn't work either.

I haven't delved deep enough in the inline bundler code to figure out how to monkey patch it either.

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
@jimtng
Copy link
Contributor Author

jimtng commented Nov 2, 2025

Overriding Gem.@user_home works.

If this approach is chosen, we'll need to add the same line in the helper library, so that when user used the inline bundler, it won't end up in ~/.bundle again.

@jimtng jimtng marked this pull request as ready for review November 2, 2025 13:06
@lsiepel lsiepel requested a review from Copilot November 3, 2025 21:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR configures Ruby Bundler's user home and config directories to use openHAB-specific paths instead of the default system locations. This ensures Bundler's cache and configuration files are stored in a controlled location within the openHAB data structure.

  • Introduces BUNDLE_USER_HOME constant pointing to the cache directory
  • Extracts directory creation logic into a reusable ensureDirectoryExists method
  • Sets BUNDLE_USER_HOME and BUNDLE_USER_CONFIG environment variables for Ruby scripts
  • Applies the Bundler user home override in all gem management operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jimtng
Copy link
Contributor Author

jimtng commented Nov 4, 2025

Moving the comment here for easier future reference:

it seems that ENV inside Gem / Bundler have been reset (sanitized?), so our custom BUNDLE_USER_HOME is no longer there.

Whilst we can return a static string here, we won't be able to do the same trick in the helper library. Setting this aside, it seems that the ENV sanitization is the cause of the fallback into user_home in the first place.

So if we can figure out why the ENV gets sanitized and maybe prevent it, then we won't even need to touch/tinker with user_home.

#gemfile calls Bundler.unbundle_env! which resets / removes the custom BUNDLE_USER_HOME.

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
@jimtng
Copy link
Contributor Author

jimtng commented Nov 4, 2025

Overriding by prepending seems to do the trick here. We can do the same in the helper library - but only when gemfile is called.

@jimtng jimtng marked this pull request as draft November 7, 2025 02:25
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.

[jrubyscripting] Addon does not clean up its cache on openhab-cli clean-cache and on uninstalling it

2 participants