Skip to content
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

Install rbenv automatically if missing #13034

Merged
merged 2 commits into from
Dec 17, 2024

Conversation

mkllnk
Copy link
Member

@mkllnk mkllnk commented Dec 12, 2024

What? Why?

This small script addition will allow us to remove the rbenv installation from our Ansible provisioning scripts.

Ansible has become hard to maintain and the rbenv installation caused an issue today. Somehow it didn't install Ruby with the specified jemalloc flag.

What should we test?

  • We need to test that this works on different machines.
  • Run ./script/rbenv-install.sh to make sure it doesn't run anything unnecessarily.
  • Temporarily move your rbenv installation and verify that the script installs it for you.
  • Restore your old installation, if you wish.

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

This small script addition will allow us to remove the rbenv
installation from our Ansible provisioning scripts.
@mkllnk mkllnk added the technical changes only These pull requests do not contain user facing changes and are grouped in release notes label Dec 12, 2024
@mkllnk mkllnk self-assigned this Dec 12, 2024
@mkllnk mkllnk marked this pull request as ready for review December 12, 2024 06:20
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Nice!
It would be nice to mention this script at https://github.com/openfoodfoundation/openfoodnetwork/blob/master/GETTING_STARTED.md?plain=1#L32

And also I think the os-specific guides could be simplified.

@mkllnk
Copy link
Member Author

mkllnk commented Dec 13, 2024

What if we modify this part?

# Check ruby version
RUBY_VERSION=$(cat .ruby-version)
if command -v rbenv > /dev/null; then
./script/rbenv-install.sh
elif command -v rvm > /dev/null; then
rvm install $RUBY_VERSION
fi
if ! ruby --version | grep $RUBY_VERSION > /dev/null; then
printf "${RED}Open Food Network requires ruby ${RUBY_VERSION}${NO_COLOR}. "
printf "Have a look at your ruby version manager: https://github.com/rbenv/rbenv\n or https://rvm.io/"
exit 1
fi

If neither rbenv nor rvm are installed, we could just install rbenv. If somebody objects then they probably have the knowledge to fix this. They could add their own version manager in the setup script or just make sure that they have the right ruby version installed.

Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

Looks good 👍

@rioug
Copy link
Collaborator

rioug commented Dec 15, 2024

Tested on my machine, all good 🟢

@dacook
Copy link
Member

dacook commented Dec 15, 2024

If neither rbenv nor rvm are installed, we could just install rbenv.

That's a great idea, it streamlines the setup even further 👍

It's perhaps worth mentioning that for Mac, rbenv recommend using the package manager. But they don't recommend it on Linux because packages are out of date.
I guess you have to manually update the git version. But that's probably fine.

Anyways, the user can still install rbenv with a package manager if they want to.

@mkllnk
Copy link
Member Author

mkllnk commented Dec 17, 2024

I guess you have to manually update the git version. But that's probably fine.

No. Our rbenv-install script does that for you. Well, at least it updates ruby-build to get the latest build information for new rubies. It doesn't actually update rbenv. There was one release this year and one in 2019. So really not that common but we could add a line to this script as well.

@dacook
Copy link
Member

dacook commented Dec 17, 2024

I tested this and it didn't go so smoothly on my Mac :(

Run ./script/rbenv-install.sh to make sure it doesn't run anything unnecessarily.

Temporarily move your rbenv installation and verify that the script installs it for you.

~/projects/openfoodnetwork $ brew uninstall rbenv
Uninstalling /usr/local/Cellar/rbenv/1.2.0... (35 files, 106.8KB)
~/projects/openfoodnetwork $ ./script/rbenv-install.sh
fatal: destination path '/Users/dcook/.rbenv' already exists and is not an empty directory.
...

The uninstaller didn't remove the old data, so I did that and tried again:

~/projects/openfoodnetwork $ ls ~/.rbenv/
shims/    sources/  version   versions/
~/projects/openfoodnetwork $ rm -rf ~/.rbenv/
~/projects/openfoodnetwork $ ./script/rbenv-install.sh
Cloning into '/Users/dcook/.rbenv'...
remote: Enumerating objects: 3348, done.
remote: Counting objects: 100% (498/498), done.
remote: Compressing objects: 100% (257/257), done.
remote: Total 3348 (delta 285), reused 386 (delta 225), pack-reused 2850 (from 1)
Receiving objects: 100% (3348/3348), 692.93 KiB | 1.60 MiB/s, done.
Resolving deltas: 100% (2075/2075), done.
writing ~/.bash_profile: now configured for rbenv.
./script/rbenv-install.sh: line 16: rbenv: command not found
./script/rbenv-install.sh: line 19: rbenv: command not found
mkdir: /plugins: Read-only file system
./script/rbenv-install.sh: line 20: rbenv: command not found
fatal: could not create leading directories of '/plugins/ruby-build': Read-only file system
./script/rbenv-install.sh: line 23: rbenv: command not found
Upgrading rbenv's ruby-build:
./script/rbenv-install.sh: line 27: rbenv: command not found
fatal: cannot change to '/plugins/ruby-build': No such file or directory
./script/rbenv-install.sh: line 29: rbenv: command not found

I checked, and ~/.rben/shims was added to the PATH. But the folder doesn't exist, because it's not in the git repo. I'm confused, how is that supposed to work?

So I had a go with rbenv-installer and it went ahead and installed it with Homebrew for me.

Now that rbenv is installed, it seems to be installing ruby fine:

~/projects/openfoodnetwork $ ./script/rbenv-install.sh
ruby-build: using openssl@3 from homebrew
==> Downloading ruby-3.1.4.tar.gz...

script/rbenv-install.sh Outdated Show resolved Hide resolved
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Cool, so that latest update makes it work after cloning ✅

~/projects/openfoodnetwork $ script/rbenv-install.sh
Cloning into '/Users/dcook/.rbenv'...
remote: Enumerating objects: 3348, done.
remote: Counting objects: 100% (280/280), done.
remote: Compressing objects: 100% (113/113), done.
remote: Total 3348 (delta 223), reused 168 (delta 167), pack-reused 3068 (from 2)
Receiving objects: 100% (3348/3348), 700.84 KiB | 804.00 KiB/s, done.
Resolving deltas: 100% (2071/2071), done.
skipping ~/.bash_profile: already configured for rbenv.
Cloning into '/Users/dcook/.rbenv/plugins/ruby-build'...
remote: Enumerating objects: 16604, done.
remote: Counting objects: 100% (4873/4873), done.
remote: Compressing objects: 100% (417/417), done.
remote: Total 16604 (delta 4640), reused 4591 (delta 4443), pack-reused 11731 (from 1)
Receiving objects: 100% (16604/16604), 3.21 MiB | 2.49 MiB/s, done.
Resolving deltas: 100% (11803/11803), done.
ruby-build: using openssl@3 from homebrew
==> Downloading ruby-3.1.4.tar.gz...
-> curl -q -fL -o ruby-3.1.4.tar.gz https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.4.tar.gz

Regarding the issue when rbenv isn't installed, but the ~/.rbenv/ dir still exists: I think that's probably ok and the user can decide what do to.

@mkllnk
Copy link
Member Author

mkllnk commented Dec 17, 2024

Regarding the issue when rbenv isn't installed, but the ~/.rbenv/ dir still exists: I think that's probably ok and the user can decide what do to.

I never tried the uninstaller. I just move the whole directory ~/.rbenv out of the way. But for a proper test, I also removed my bash integration (PATH and init).

@mkllnk mkllnk merged commit 0f706a9 into openfoodfoundation:master Dec 17, 2024
51 checks passed
@mkllnk mkllnk deleted the rbenv-install branch December 17, 2024 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical changes only These pull requests do not contain user facing changes and are grouped in release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants