Bundler: bundle pack, vendor/cache... - bundler

According to Bundler (http://bundler.io/v1.3/rationale.html)
The --deployment flags adds the following defaults:
...
If you have run bundle pack, checked in the vendor/cache directory,
and do not have any git gems, Bundler will not contact the internet
while installing your bundle.
Questions:
is bundle pack the same as bundle package? If not then, as bundle -h doesn't show any details about bundle pack, how do you find out more about bundle pack (other than trawling through Google results!)
does "checked in the vendor/cache" mean checked into git? And, if so, how does bundler know you've checked it in?

is bundle pack the same as bundle package? If not then, as bundle -h doesn't show any details about bundle pack, how do you find out more about bundle pack (other than trawling through Google results!)
Yes. Both bundle package and bundle pack accomplish the same. Refer to this line in lib/bundler/cli.rb. The map command inside a Thor::CLI aliases the command(s) given to it as an argument. In this case, it converts "pack" to :package which is a recognized task.
does "checked in the vendor/cache" mean checked into git? And, if so, how does bundler know you've checked it in?
Bundler doesn't check if the vendor/cache is checked into git repo or not. It only checks if the directory exists and sets the --local flag appropriately when bundle install is run. The last paragraph in bundle package man page gives a subtle reason why there is a need to check-in the vendor/cache directory into source control. Other than that, I couldn't find any code that necessitates checking in the vendor/cache directory into source control for the purposes of the bundle command.

Related

Going to project folder before "bundle install"

I'm trying to install jekyll based on instructions here (via rbenv): https://gist.github.com/r-brown/a0b50d56cfb3596e0d17
Before the "bundle install" step, it states:
go to the project folder
However, I'm new and simply truly confused as to what this refers to? I don't actually have a project folder right now, because I am merely in the process of installing jekyll?
Or is that referring to a specific location based on the earlier installation steps?
I attempted to skip this step and directly input bundle install, but that yielded this error
"Could not locate Gemfile".
Referring to this post: Could not locate Gemfile was unfortunately not useful as no one explicitly stated what "project folder" entails...
Why do you want to use jekyll? Usually you would use it as part of a project - which probably entails writing the line:
gem 'jekyll'
...inside the Gemfile of your project. And then, to install the library (along with all other dependencies, you can run bundle install.
This is why the next line of the guide talks about running the command: bundle exec jekyll serve ... -- because the author is assuming that you have a project set up.
However, if you just want to install the gem globally (i.e. not within the context of a project), then you don't need to do anything with bundle. Just run:
gem install jekyll

IMPORTANT: Remember to use the included executable `certifed-update` regularly to keep your certificate bundle up to date

$ gem install bundler
gives me (at the end of the successful install):
Post-install message from certified:
IMPORTANT: Remember to use the included executable `certifed-update` regularly to keep your certificate bundle up to date.
I can't see how I'm going to remember to keep this executable indefinitely up to date. Any suggestions?
There is a typo in the message: certifed-update does not exist, it's certified-update (notice the missing "i"). It's strange as this typo is fixed in latest gem code (maybe the author forgot to publish a new version, who knows)
You can run this tool manually with:
bundle exec certified-update
Which yields this message:
Updating ca-bundle from
https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt
Certificate bundle updated. Remember to do this regularly!
In order to remember to update the certificates you can configure a periodic reminder in your calendar, or you can setup a cron job or similar to make it automatically ;-)
It seems you're using this gem and it's getting run somehow after gem install bundler. Try deleting it via gem uninstall certified and rerun gem install bundler.

Missing File in Gem after Build

TL;DR:
Don't run bundle within an existing git repository. Weird things will happen without any error messages.
Original Question:
I've built a gem by adapting the steps in this tutorial:
http://net.tutsplus.com/tutorials/ruby/gem-creation-with-bundler/
As a final step, I've run gem build .gemspec
This succeeds, but when I install the gem I find the critical file, the one which contains my code, isn't in the gem. Another file in the same (lib) directory, "version.rb", does exist in the gem.
I don't know how to start debugging this...how does bundler/gem build decide which files to include in the gem?
Edit:
My workflow is:
gem build <project_name>.gemspec
gem unpack <project_name>
=> confirm file does not exist in <unpacked>/lib/
gem install <project name>
=> confirm file structure in ~/home/stefan/.rvm/... contains gem, but does not contain desired file
Edit 2 / Resolution:
I was finally able to get this working by committing all my code to a remote repository, creating a clean clone, and building the gem. The new gem included all the required files.
A bit of history...I originally created the code and committed it before thinking about making a gem (this is my first gem). I then used bundle inside the original repository, which didn't complain, but was probably the reason for the weirdness.
One of the things bundler did for you is start a local git repo to version-manage your gem code. Check that you have added the file in git
git add lib/gem_name/missing_file.rb
Bundler generated gems use git internally to track "membership" of source files for the gem. You can see this in the .gemspec where it uses backticks to call out to git and generate a file list:
gem.files = `git ls-files`.split($/)
Note this also means you should pay attention to what you list in .gitignore

Where are "asset group" gems installed?

I have some gems that are only used for the asset pipeline. One example is:
gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
Unfortunately, I can not find exactly where this gem is installed. "gem list --local" does not even show it.
I need to fix it, because I am trying to use Bootstrap styling in datatables, which is allowed in the latest version. But the version of datatables included with the gem is old.
Does anybody know where these gems go? I am very, very confused by the asset pipeline.
I such cases, I fork the project on github and make my changes, and adjust my Gemfiles accordingly. This also makes it reuseable in different projects.
The asset pipeline and Bundler grouping has nothing to do with where gems are installed on your system. You can always run bundle open gemname to open the source of a Gem in your $EDITOR and make quick changes (i.e. for debugging). If you want to actually include changes in a release, though, you are going to want to fork the Gem and make your changes there, then specify the git path in your Gemfile.
As a side note, make sure you run bundle install (or really, just bundle) after making changes to your Gemfile to ensure the Gems all get installed.

Bundler: two caches in the vendor folder, why run bundle package then?

I ran:
bundle install --path vendor as the first Bundler install. I then ran:
bundle package, which creates a vendor/cache directory and puts in the gems. But, there is also a vendor/ruby/1.9.1/cache/ directory too. It has the same contents (I md5'ed them).
So, what's the point of bundle package then?
Any insight is much appreciated.
bundle package stores the .gem source files in vendor/cache, which guarantees smooth deploys and allows reviving old projects easily. This is especially useful when using a fork of a gem because the author can close their repo at any time, leaving your app incomplete.
The vendor/ruby directory contains the installed gems, which in some cases will be the same. But some gems build with native extensions so these can't be used in deployment due to different architecture. You should add vendor/ruby to your .gitignore file.

Resources