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

Installation of gem ruby-lsp fails #1745

Closed
1 task
ThomasOwens opened this issue Sep 14, 2023 · 16 comments
Closed
1 task

Installation of gem ruby-lsp fails #1745

ThomasOwens opened this issue Sep 14, 2023 · 16 comments
Labels
bug Something isn't working transferred This issue was transferred from vscode-ruby-lsp

Comments

@ThomasOwens
Copy link

ThomasOwens commented Sep 14, 2023

Operating System

Windows / devcontainer

Ruby version

3.2

Project has a bundle

  • Has bundle

Ruby version manager being used

rvm

Description

I created a new Ruby on Rails & Postgres Dev Container using VS Code, connected to it, and am attempting to start a new project.

After connecting to the devcontainer, the following error appears:

Failed to setup the bundle: Command failed: gem install ruby-lsp ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/local/rvm/gems/default directory. /usr/local/lib/ruby/3.2.0/rubygems/installer.rb:712:in verify_gem_home' /usr/local/lib/ruby/3.2.0/rubygems/installer.rb:902:in pre_install_checks' /usr/local/lib/ruby/3.2.0/rubygems/installer.rb:302:in install' /usr/local/lib/ruby/3.2.0/rubygems/resolver/specification.rb:104:in install' /usr/local/lib/ruby/3.2.0/rubygems/request_set.rb:194:in block in install' /usr/local/lib/ruby/3.2.0/rubygems/request_set.rb:182:in each' /usr/local/lib/ruby/3.2.0/rubygems/request_set.rb:182:in install' /usr/local/lib/ruby/3.2.0/rubygems/commands/install_command.rb:214:in install_gem' /usr/local/lib/ruby/3.2.0/rubygems/commands/install_command.rb:230:in block in install_gems' /usr/local/lib/ruby/3.2.0/rubygems/commands/install_command.rb:223:in each' /usr/local/lib/ruby/3.2.0/r...

I was under the impression that this was related to #1572, Shopify/vscode-ruby-lsp#664, #1787, Shopify/vscode-ruby-lsp#750 or one of the related linked issues/PRs. However, both VS Code and the Ruby LSP plugin are fully updated and this problem persists even though these issues have been marked as resolved. It's not clear if there's a regression or this is a different issue.

Since this plugin is installed out-of-the-box in the Ruby on Rails & Postgres devcontainer, I would not expect errors when creating and connecting to this devcontainer.

@ThomasOwens ThomasOwens added the bug Something isn't working label Sep 14, 2023
@andyw8
Copy link
Contributor

andyw8 commented Sep 14, 2023

Is it this devcontainer repo? https://github.com/luizkowalski/devcontainer-rails/

@ThomasOwens
Copy link
Author

ThomasOwens commented Sep 14, 2023

@andyw8 No. I'm using https://github.com/devcontainers/templates/tree/main/src/ruby-rails-postgres.

I use this directly through VS Code. I create a new workspace, open the command palette, and use Dev Containers: Add Dev Container Configuration Files. I select the "Ruby on Rails & Postgres" configuration files, which are maintained by devcontainers.

There are other options. There is a Ruby option also maintained by devcontainers along with a Ruby on Rails that is community maintained. I can experiment with these to see if they also have the issue. I don't know if this plugin is included out-of-the-box in the other configuration files, though.

I wonder if this is partially related to devcontainers/templates#188. However, even setting the BUNDLE_APP_CONFIG and BUNDLE_PATH values in devcontainer.json still results in the same error.

@andyw8
Copy link
Contributor

andyw8 commented Sep 14, 2023

You said it's "installed out-of-the-box in the Ruby on Rails & Postgres devcontainer" but I can't see any reference to Ruby LSP in there. 🤔

@ThomasOwens
Copy link
Author

ThomasOwens commented Sep 14, 2023

It's indirectly installed.

The Ruby on Rails & Postgres container is built on the Ruby container image.

The Ruby Container image includes the Ruby feature: https://github.com/devcontainers/images/blob/main/src/ruby/.devcontainer/devcontainer.json#L14

The Ruby feature installs Ruby LSP: https://github.com/devcontainers/features/blob/main/src/ruby/devcontainer-feature.json#L25

I suspect that this issue would also affect the use of the Ruby container image directly, but I could test that later.

@vinistock
Copy link
Member

Let's try to understand why we're trying install the ruby-lsp under a folder we don't have permissions for.

Can you explain in more detail what your RVM set up is? Are you using gemsets or configuring a BUNDLE_PATH? If you had to install a gem without bundler by doing gem install <something>, would you pass any other flags?

I believe it might be related to #1791. Doing gem install ruby-lsp won't work for setups where we don't have permissions to write to the default global installation path.

@ThomasOwens
Copy link
Author

@vinistock I have no idea what the RVM setup is. I'm using VS Code to create new devcontainer configuration files using the "Ruby on Rails & Postgres" configuration. When I connect to that container, I get the provided error message. I believe that I should be able to use VS Code to create a new devcontainer configuration, create a devcontainer, and connect to it with no errors. That is not the case right now, but the only errors that I've seen so far are from ruby-lsp.

This could be related to devcontainers/templates#188. It doesn't make much sense to install any version manager on a devcontainer by default. I don't know if the devcontainer team making those proposed changes would resolve the issue or not.

It's not clear to me if this is a ruby-lsp problem or a devcontainer problem. The only error messages were explicitly about ruby-lsp, so I started here.

@vinistock
Copy link
Member

Well, it could be a combination of both. We already know from #1791 that we need to improve how we handle the global installation if we don't have permissions for the default path, so that part of the issue is on the Ruby LSP side.

Whether the devcontainer should have installed RVM or not and whether the configuration for RVM is correct is the second part of the issue which is on the container side.

From the container's perspective, a possible solution could be to create a gemset where the user has permissions to install things. But it depends on how folks wanted the container to be configured.

The Ruby LSP automatically detects which version manager is installed to be able to select the right Ruby version to run. If you force the manager to be none - just picking up the default Ruby in the PATH - does the issue go away?

// Your VS Code JSON settings
{
  "rubyLsp.rubyVersionManager": "none"
}

@ThomasOwens
Copy link
Author

@vinistock I will experiment with the gemset and the version manager configuration over the next couple of days and follow-up here. I also want to experiment with starting with the base Ruby container and see if the same problems persist there.

@kmayer
Copy link

kmayer commented Sep 17, 2023

This helped me get past the issue for now: adding sudo chown ... restores ownership to the vscode user. Something, somewhere, is triggering a gem install using rvm as root

// devcontainer.json
"postCreateCommand": "sudo chown -R $(whoami) /usr/local/rvm/gems && bundle install && rake db:setup"

@ThomasOwens
Copy link
Author

@kmayer Yes. You're right.

I just checked the permissions on RVM's /usr/local/rvm/gems/default/gems and it (and all of the gems) are owned by root. However, the group is rvm. An alternative solution could be to put the vscode user into the rvm group as well, but the other RVM directories are owned by vscode, so your solution could be a good fix. It seems like this is something that is up with how this container is created.

I checked using the base Ruby devcontainer configuration. There, everything in /usr/local/rvm/gems/default/gems is owned by the vscode user. Something is happening in this Ruby on Rails & Postgres devcontainer.

I'm wondering if the better solution wouldn't be to use Ruby as the devcontainer. Or even using Alpine as the base devcontainer. From one of these, it would be possible to built it up to include Rails and Postgres (or an alternative database) without a lot of headache. It's quite unfortunate that official devcontainers are installing functionality in a way that causes them to be broken. What was supposed to be an easy "spin up a devcontainer with the exact config I need" wasn't that easy.

Someone with more knowledge of ruby-lsp should confirm, but this is looking increasingly like a devcontainer problem.

@vinistock
Copy link
Member

The thing that is triggering gem install is definitely us. We need to install the ruby-lsp gem in order to launch the language server.

And it seems that the devcontainer only has the default RVM gemset, which doesn't give you permissions to install there.

Are there not other gemsets in the container? How do people run bundle install or gem install in the container?

I think it's worth understanding if the container should be coming with a user owned gemset.

@ThomasOwens
Copy link
Author

@vinistock I don't follow. In terms of running my application, I haven't even gotten to the point where I would need to bundle install yet. I would only do that as part of creating a new Rails app (since the Rails gem is already installed in this container configuration), but I haven't because of these errors with ruby-lsp that I'm working through. Otherwise, the postCreateCommand in the devcontainer.json would be uncommented to run the commands after creating the container. During development, I run bundle install or bundle update after updating the Gemfile. Personally, I use a vendor/bundle directory in my app's directory, which is a mounted directory from my local desktop environment, so when a gem is installed into vendor/bundle, it is on my host and is loaded into the container from there.

@vinistock
Copy link
Member

I'm trying to understand the differences between a developer installing gems regularly (using bundle install) vs what we're doing.

So you always have BUNDLE_PATH pointing to vendor/bundle in the container?

That might be the reason, in which case we'll need to think about how we can improve this in the LSP. To avoid forcing people to add the ruby-lsp gem to their Gemfiles, we install it globally using gem install ruby-lsp.

But if the only place you have permissions to install gems is under vendor/bundle, that won't work. I'm not sure if gem install allows you to select a path. Maybe we could take BUNDLE_PATH into consideration and point it there?

@ThomasOwens
Copy link
Author

Considering that this gem works in the Ruby devcontainer but not the Ruby on Rails & Postgres devcontainer, I don't think it's something that you're doing. I need to dig into the installation scripts, but it looks like in the Ruby on Rails & Postgres devcontainer, something (unclear if it's RVM, the default Ruby installation, gems, or a combination of those) are being installed by the root user rather than the vscode user. This is not an error in the Ruby devcontainer, where the RVM directories are all owned by the vscode user.

The important thing is that I'm not installing ruby-lsp. That's handled by the Ruby devcontainer feature file installing the VS Code extension (see https://github.com/devcontainers/features/blob/main/src/ruby/devcontainer-feature.json#L25). However, with the RVM installation being owned by root and this being run by the vscode user, there aren't permissions.

I'm pretty sure the permissions are mangled by one of the scripts in the Ruby on Rails & Postgres devcontainer, since the only error that I'm getting in the Ruby devcontainer is the fact that my linter isn't installed. That error goes away after changing the configuration or installing a linter, though.

The question for me, though, is how much time I want to invest in this Ruby on Rails & Postgres container. The answer is probably "not much", especially if the Ruby devcontainer doesn't have these issues and it's trivial to install the Postgres client and use a compose file to include the Postgres container. I think I want to pivot and see if getting the Ruby container set up for my project is easy enough and also results in a working ruby-lsp.

@ThomasOwens
Copy link
Author

I made the changes to the Ruby on Rails & Postgres devcontainer, which resolved this issue. The changes have been merged into the devcontainer repository.

@andyw8
Copy link
Contributor

andyw8 commented Sep 27, 2023

devcontainers/templates#202

Thank you @ThomasOwens!

@st0012 st0012 added the transferred This issue was transferred from vscode-ruby-lsp label Mar 18, 2024
@st0012 st0012 transferred this issue from Shopify/vscode-ruby-lsp Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working transferred This issue was transferred from vscode-ruby-lsp
Projects
None yet
Development

No branches or pull requests

5 participants