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.
Related
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 ...
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 gem server protected by http basic authentication. Currently, I'm storing the credentials as environment variables and have this line at the top of my Gemfile:
source "https://#{ENV['GEMS_USERNAME']}:#{ENV['GEMS_PASSWORD']}#gems.myserver.com"
So far so good, and when I run bundle everything seems to work. But than I looked at the generated Gemfile.lock and noticed that the credentials for my server got hardcoded there.
GEM
remote: https://rubygems.org/
remote: https://username:password#gems.myserver.com/
Is there a way to prevent this from happening? I don't want to push my credentials into the git repo.
If you are using bundler >= 1.6 you can simply do something like this:
bundle config http://gems.myserver.com username:password
And it should put those credentials in your .bundle/config file so you don't need to explicitly include them on your Gemfile(.lock) anymore.
I am trying to build a rails project and because the host I am working on doesn't have access to the Internet for the the git:// protocol (port 9418) I get errors like
Fetching git://github.com/pivotal/jasmine.git
fatal: unable to connect to github.com:
github.com[0: 192.30.252.130]: errno=Connection refused
when running bundle install.
The relevant line in the GemFile doesn't specify git:// as a protocol, it just points to GitHub as the source for the gem
gem 'jasmine', :github => 'pivotal/jasmine-gem'
What do I have to do to make bundler to use https:// rather than git:// for pulling gems from GitHub?
Edit:
Is there a way other than editing every affected line in the GemFile? I'd prefer to avoid any merging issues down the line if the project's GemFile is updated.
Use bundle config github.https true
Git provides URL rewriting functionality using the url..insteadOf configuration option.
So to make all connections to github.com use https:// rather than git://
git config --global url."https://github.com".insteadOf git://github.com
The --global switch sets the config option for all git operations by the current user, so there are times where it may be too intrusive. But it does avoid changing the git config in the current project.
You can do:
gem 'jasmine', git: 'https://github.com/pivotal/jasmine-gem.git'
If you want this just for all the gems in one Gemfile you can add these lines at the top of the file:
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
Alternatively you can use bundle config github.https true. But this affects only your current environment.
This won't be necessary anymore with Bundler 2.0.
if you're deploying to heroku, you can just add BUNDLE_GITHUB__HTTPS (note the double underscore) as an environment variable and set it to true (in your heroku app's dashboard under the Settings tab in the Config Vars section). this will switch the protocol from git:// to https:// for all such requests.
You should be able to put a complete Git URL in your Gemfile. For example:
gem 'jasmine', :git => 'https://github.com/pivotal/jasmine-gem.git'
If a solution that requires a special obscure setting to be performed on every installation you make for just a teeny weeny bit of syntactic sugar isn't a solution.
That's why I'm proposing this as an answer:
just use :https & report a security bug with bundler that the unencrypted protocol is default.
I'm cloning this repo:
https://github.com/freeformz/sinatra-jruby-heroku.git
to try and use JRuby/Sinatra on Heroku's Cedar stack. I follow the included instructions and everything runs great locally with a 'foreman start'. I then git push to Heroku and it initially loads up fine but when I try to access the site I get an error in the logs:
jruby: No such file or directory -- trinidad (LoadError)
So it seems jruby can't find the "/app/.gems/bin/trinidad" file. I initially thought it wasn't there because .gems/ is in the .gitignore file, but I'm pretty sure Heroku creates that server side on a git push.
$APPDIR/.gems is added to the PATH so Heroku should be able to see the trinidad script. I've also tried to change the Procfile around to play with the path like:
web: script/jruby -S bin/trinidad -p $PORT
But no dice. Has anyone had any success deploying anything JRuby to Heroku cedar?
Thanks
As of Bundler 1.2 you are now able to specify the Ruby implementation and version in your Gemfile. The nice thing about this is that Heroku will understand these settings and prepare the your Heroku application for your environment.
Take this Gemfile for example:
source "https://rubygems.org"
ruby "1.9.3"
gem "rails"
gem "puma"
What's cool about this is that by default Celadon Cedar uses Ruby 1.9.2. However, when you specify ruby "1.9.3" in the Gemfile it'll actually compile Ruby 1.9.3 for your Heroku environment.
Now, if you want to add a different Ruby implementation to your Heroku environment, you can do so like this:
source "https://rubygems.org"
ruby "1.9.3", :engine => "jruby", :engine_version => "1.7.0.preview1"
gem "rails"
gem "puma"
Now it'll install and use JRuby 1.7.0.preview1 in Ruby 1.9 mode for your Heroku application upon deployment. It'll also even define the proper JVM options in the Heroku environment variables.
Best of all is that this comes with the official Heroku buildpack, so there is no need to switch to a 3rd party buildpack to get the JRuby/JVM going on Heroku. Although I haven't gotten it to work yet, this should also work with Rubinius, but I believe it's currently bugged. Either that, or I'm doing it wrong.
This is in my opinion an awesome and scalable feature. Just define the Ruby implementation/version/mode you're using in your Gemfile along with your other dependencies and Heroku will ensure the environment is prepared.
Now, with all this in place, Heroku should create binstubs (through Bundler) in APP_ROOT/bin so what you can do is for example this:
web: bin/trinidad -p $PORT -e $RACK_ENV --threaded
Just don't use bundle exec since JRuby doesn't play nice with that. Always use the binstubs provided by Bundler which are always located in APP_ROOT/bin on Heroku.
I believe the details about including gems on this blog entry might be helpful to you:
http://chris.chowie.net/2011/08/28/Sinatra-with-JRuby-on-Heroku/
I suspect that your gems are not in /app/.gems but rather in /app/vendor/bundle
You can find out by running this command:
heroku run ls /app/.gem
heroku run ls /app/vendor/bundle
Either way, you should probably add the GEM_HOME/bin to the path, and not the GEM_HOME as you state.
I've got a blog post on running Jruby and Trinidad on Heroku here:
http://deployingjruby.blogspot.com/2012/03/deploying-with-trinidad-on-heroku.html
And an example app here:
https://github.com/jkutner/jruby-trinidad-heroku
Some of the other material you may find is a little out of date.