I want to use a hosted private gem on my Ruby project. This gem is hosted on GitLab.
So I need help on what to add in my Ruby Gemfile to "import" this privately hosted gem.
I am able to use private gems from GitHub or Gemfury but need help with GitLab.
To use a private hosted gem on gitlab you need to create an access token it should have api access. Then after you set in your ENV you can add the following to your gemfile:
gem 'mygem', git: "https://oauth2:#{ENV['GITLAB_TOKEN']}#gitlab.com/mygroup/mygem.git"
I would not put my gitlab username and password in my gemfile because then they exist in your source code for everyone whom has access to see them. It is important to note that your oauth token will be printed in your Gemfile.lock if you use this method.
Yes you can add gem from git lab.
You will need to pass username and password in the url part of the gem.
Example:
gem 'gem_name', 'version', :git => "http://<username>:<password>#myprivate_gitlab_host/private_gems/my_great_gem.git"
see here Is it possible to install gem from private gitlab host from Heroku
I think the :git refers to git and not to github, they are NOT the same...
Could be :git => 'github.com' or :git => gitlab.com or :git => myprivgit.com ...
Related
I created an in-house gem to use with a Rails project that I want to include in my Gemfile.
The gem is hosted in a private repo on Github.com (so :git is not an option) so I am assuming the best direction to include the gem is :path, e.g.
gem 'mygem', :path => '/path/to/gem/dir'
I am curious though:
Where is the ideal place for the gem to be included? (vendor/ ?)
If vendor is the best place, then I don't need to add the gem to my project repository (since vendor/ is ignored by default)
I am using Capistrano to deploy my project; how should Capistrano be aware of the local gem so that it can deploy it as well?
You can go for the vendor location and have the authentication information for the private gem in the gemfile like this:
gem 'foo', :git => 'https://my_username:my_password#github.com/my_github_account/my_repo.git'
However, I am guessing that you will be uncomfortable exposing such sensitive information in the gemfile so you can use a git protocol based url in your gem file like this:
git://github.com/username/repo.git
git protocol based urls are read only so your private repo should be intact.
Also, I am sure you can write a capistrano task to deploy a private gem to vendor directory but that might involve putting in your github username/password in the capistrano task. Also, you can prompt for the username/password during deployment as opposed to putting it in the capistrano task.
I have a private gitlab host, which host private codes and project, and I host my app in heroku, in that heroku app, we use Gemfile to manage dependence of that heroku app, one of those dependence is from private gitlab host. so my Gemfile is something like this:
gem 'my_greate_gem', '0.0.1', :git => "http://myprivate_gitlab_host/private_gems/my_great_gem.git"
It's seems there's not any tutorial mentions about using private gitlab host to hosting gem in Heroku, but I really don't want to use gemfury. Is there any possible solution for this?
Without using Gemfury you would have to pass a username and password in the URL of the gem dependency
gem 'my_greate_gem', '0.0.1', :git => "http://<username>:<password>#myprivate_gitlab_host/private_gems/my_great_gem.git"
The other answer didn't work for me. Also, I prefer a method that allows me to keep credentials out of source. I put the following in my gemfile:
gem 'mygem', git: "https://oauth2:#{ENV['GITLAB_TOKEN']}#gitlab.com/mygroup/mygem.git"
The gitlab token I created has API access. This works for me on heroku if I manually set the GITLAB_TOKEN in the environment variables in settings.
Hope that helps.
Has anyone worked with Mozenda in ruby on rails project before?
I am looking for gem or wrapper of Mozenda API.
Searched online there were two library 'mozenda' and 'mozenda-api'.
Unfortunately, both cannot be found when i tried to install them.
Install one of them as a git repo by adding the proper record into Gemfile:
gem 'mozenda', :git => 'https://github.com/jefferyf/mozenda.git'
or
gem 'mozenda-api', :git => 'https://github.com/darrikmazey/mozenda-api.git'
Then issue:
$ bundle install
I'm not new to programming, but brand new to Ruby. Everything's working, but I'm still missing a key concept: how do you install a plugin and where/how do you include it in an app?
Example:
I'm trying to use the Facebooker2 plugin: https://github.com/mmangino/facebooker2. In the readme, step 1 is to "Install facebooker2 as a plugin in your rails app." I've run the command git clone https://github.com/mmangino/facebooker2.git to download a read only version of the repository.
Do I then bundle that up using Bundler, or do I need to create a gem file in some way? Do I simply
use gem to install it, or do I need to compile it into a gem?
Any help (terminal commands or otherwise) are extremely helpful.
I looked at the repo and it's set up as a gem. You can simply add
gem 'facebooker2'
to your Gemfile (in the root of your project) and run
bundle install
to download it and add it to your list of installed gems, both in development and in production.
Rails used to include the concept of plugins (added to your /vendor/plugins directory) but that's been dropped in favor of gems.
If you're source is source 'https://rubygems.org' but the gem you need is specific to github and not part of the rubygems.org library, then you can add the git method to your gemfile. You can also select a specific branch version. For example, here I have the gem cancan being pulled from the github repository on the 2.0 branch.
gem "cancan", :git => "git://github.com/ryanb/cancan.git", :branch => "2.0"
Forked wicked_pdf and added to Gemfile
gem 'wicked_pdf', '= 0.7.2', :git => 'git://github.com/geoffcorey/wicked_pdf.git'
Capistrano deploy does
bundle install --path vendor/gems --without development
All gems show up in vendor/gems/ruby/1.9.1/gems except wicked_pdf which the repo is cloned to vendor/gems/ruby/1.9.1/bundler/gems.
bundle list will show the wicked_pdf (0.7.2 156782e) but when I fire up the application via Apache/Passenger, Rails 3.1.3 cannot find wicked_pdf.
Is there something else I should be doing as part of the deploy to have the wicked_pdf build the gem and install as a separate task?
I am having exactly the same problem here (but hosting on heroku).
http://gembundler.com/man/bundle-package.1.html
"In Bundler 1.0, the bundle package command only packages .gem files, not gems specified using the :git or :path options. This will likely change in the future."
Have a look at:
Bundler: `bundle package` with a :git source
and maybe use:
http://underpantsgnome.com/2011/01/05/how-to-install-private-gems-on-heroku
to install the gem.
Your problem may be that (a) you're locking it to an exact version "=0.7.2", but you don't specify a commit ID on the git repo. These two things are in conflict. It's possible that the version entry in the gemspec is no longer 0.7.2 at the tip of the branch you're pulling from git.
If you specify a git location for a gem, it's best not to specify a version, but instead the commit ID you want, i.e.:
gem 'wicked_pdf', :git => 'git://github.com/geoffcorey/wicked_pdf.git', :ref => 'commit_id_on_github_you_want'