Install Gems from gemsfile.Lock

163 views
Skip to first unread message

John S

unread,
Apr 22, 2015, 9:09:26 PM4/22/15
to rubyge...@googlegroups.com
Hi All,

I have a jenkin server and plan to bundle Gemfile.lock for whole(50 Servers) to use the same file lock for all clients. On clients(Linux) just need to need to install the gems available in gemfile.lock, have puppetmaster and client so i can copy the gemfile.lock to all clients.
*Used bundle install command, but this command will create a gemfile.lock on each node again, so was checking of some other command.

No my question is there any option in any command  like 'gem' to use gemfile.lock and install all gems specified in the lock file, i think we can install like 'gem install gemname', but better was checking  single gem command read the gemfile.lock available in the directory and install what is mentioned in gemfile.lock



Regards
John

Wes Garrison

unread,
Apr 22, 2015, 9:11:36 PM4/22/15
to rubyge...@googlegroups.com
John:

With a Gemfile & Gemfile.lock, only option is `bundle install --deployment`.

There are some other options on the "deploying with Bundler" page here:
http://bundler.io/v1.9/deploying.html

HTH.

---
Wes Garrison
www.databasically.com
> --
> You received this message because you are subscribed to the Google Groups
> "rubygems.org" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubygems-org...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Jonathan Rochkind

unread,
Apr 23, 2015, 10:45:00 AM4/23/15
to rubyge...@googlegroups.com
If you copy Gemfile and Gemfile.lock to each client, and run `bundle install` there -- no new Gemfile.lock should be created. It should install exactly the versions recorded in Gemfile.lock -- this is in fact the intention of the Gemfile.lock!

Are you seeing something different? I'm confused when you say "Used bundle install command, but this command will create a gemfile.lock on each node again" -- this is not the way it ought to work. If there's already a Gemfile.lock, that was created with the Gemfile it accompanies, then 'bundle install' should install exactly the gems mentioned in the Gemfile.lock, and should not create a Gemfile.lock, since there's already one there.  Are you only copying the Gemfile.lock and not the Gemfile? I think you need both.

If you use the "--deployment" argument to bundle install, `bundle install --deployment`, then:

1) The gems will be installed to a local ./vendor/bundle directory instead of to the system, and
2) Bundler will outright refuse to install if the Gemfile.lock does not contain versions of everything mentioned in the Gemfile. Which it shouldn't anyway if you are checking in a paired Gemfile and Gemfile.lock, but if something has gone odd and bundler would ordinarily update the Gemfile.lock with a `bundle install`, the `--deployment` flag will absolutely keep it from doing so. A bundle install --deployment will never alter the Gemfile.lock. (Unless there's a bug in bundler or something).

Jonathan
Message has been deleted

Jonathan Rochkind

unread,
Apr 23, 2015, 6:06:36 PM4/23/15
to rubyge...@googlegroups.com

​When you `bundle install --deployment`, gems are installed to the local ./vendor/bundle directory instead of the system, as I mentioned before.  So they won't show up in `gem list` or `gem show`, which shows system-installed gems. You can use `bundle show` if you want, from the app directory. 


If you want them installed in the system, there might be a way to get bundler to have it's other --deployment behavior without that. I'm not sure. It's a bundler-specific question, not so much about rubygems in general, although the two are very related these days. 


If you always run a bundle install locally and check in the resultant Gemfile and Gemfile.lock together, and check them out on the deployment machine, you _should_ get the behavior you want even without `--deployment`. `bundle install` should install exactly the versions listed in the Gemfile.lock, and never change the Gemfile.lock -- in this case installing to system. 


Most people consider installing to local ./vendor/bundle in a deployment scenario to be preferable, which is why `bundle install --deployment` does that. 



From: rubyge...@googlegroups.com <rubyge...@googlegroups.com> on behalf of John S <bun...@gmail.com>
Sent: Thursday, April 23, 2015 5:46 PM
To: rubyge...@googlegroups.com
Subject: Re: [rubygems.org] Install Gems from gemsfile.Lock
 
Hi,

Thanks for the updates. I have Gemfile and Gemfile.lock and bundle should install only gems mentioned there. So i tried using bundle install --deployment, so its working.

Now if i need to update a new gem in Gemfile or i need to remove a Gem, i updated Gemfile, create a Gemfile.lock. But the new gem is showing in 'bundle show' command, but it is missing in gem list command.

Am i missing something while updating the gems.

Appreciate yours support.

Regards
John

John S

unread,
Apr 23, 2015, 6:13:27 PM4/23/15
to rubyge...@googlegroups.com
Hi,

Thanks for the updates. Sorry for the confusion,  i used Gemfile and Gemfile.lock,  as mentioned used the command sudo BUNDLE_GEMFILE='/opt/Gemfile' bundle --deployment, for first time it started working.

Now further i tried to update new gems to Gemfile, and use the same command mentioned above, result was bundle is complete..but was able to see the new gems only using bundle show command, but gem list command didnt provide the list of all gems.


Then i used a command sudo BUNDLE_GEMFILE='/opt/Gemfile' bundle --no-deployment, so this command also installed the gems into bundle, this time was able to see all gems in gem list command as well.

So which command is the correct one for maintaining the updates.


Regards
John





On Thursday, April 23, 2015 at 7:45:00 AM UTC-7, Jonathan Rochkind wrote:

Jonathan Rochkind

unread,
Apr 24, 2015, 4:23:11 PM4/24/15
to rubyge...@googlegroups.com

I am very confused as to what you are doing and what you are trying to do and why you are using BUNDLE_GEMFILE=/opt/Gemfile. That's a very weird thing to do. 


Normally your Gemfile, and it's corresponding Gemfile.lock, both exist next to each other in the project directory. If you are trying to do something else, you should probably have a good reason, and understand bundler well so you can understand what you're doing going off the usual path. 


The '--deployment' flag is 'remembered' by Bundler, usually in a project-specific `.bundle` file/directory.  So when you pass '--no-deployment', all it's doing is turning off the remembered '--deployment' configuration, doing the same thing as if you had done a `bundle install` command in the first place. 


As I explained before, bundle with --deployment stores the gems in a local ./vendor/bundle. So they do not show up in the system bundle installs. Most people consider this preferrable for deployment. Normally in your project app, where the Gemfile is too. Normally you run `bundle` commands from inside the project directory, have the Gemfile (and Gemfile.lock) in that same project directory, and that is also where --deployment locally-installed gems are installed, in ./vendor/bundle inside that same project directory. 


I don't understand what you are trying to do or why, but my suggestion would be to spend some time with the bundler documentation so you understand how it works. The docs are pretty decent. http://bundler.io. I'd recommend trying to understand how bundler actually works and what it's intended to do -- and only going away from bundler's default recommended use cases if you have a reason to do so. I don't think you're going to have much luck just trying different invocations you found on the internet without understanding what bundler is doing. 


If you still have questions after spending some time with the docs, I'd recommend asking them on StackOverflow. I don't think I can help you any further here. Good luck! 


Sent: Thursday, April 23, 2015 6:13 PM

To: rubyge...@googlegroups.com
Subject: Re: [rubygems.org] Install Gems from gemsfile.Lock
Reply all
Reply to author
Forward
0 new messages