How to use private repo gem in Rails app? - ruby-on-rails

I would like to load a private gem in my rails app (I'm using docker and rails 5).
So first I add the gem in my gemfile :
gem 'my_gem', '0.1.4', git: "https://#{ENV['GITHUB_TOKEN']}#github.com/Orga/my_gem"
Then when I try to docker-compose build, this is what I get :
fatal: could not read Username for 'https://github.com': No such device or address
So I tried docker-compose run web bundle install. They ask me for my login. I've got no error, but the gemfile is updated as below :
GIT
remote: https://#github.com/Orga/my_gem
revision: 391ae38ff06dfd360eb42a09256f4a5463fba559
specs:
my_gem (0.1.4)
rails (>= 5.0.0.beta3, < 5.1)
roo (~> 2.1.0)
GEM
remote: https://rubygems.org/
...
This line seems really weird to me : remote: https://#github.com/Orga/my_gem .
So is it the good way to load a private gem ?
When I bundle install it asks for my login, so it will probably cause trouble in production right ?
EDIT
When I put direclty the token into the gemfile everything works.
So the env var is not called properly.
I tried :
.env
GITHUB_TOKEN=...
gemfile
gem 'my_gem', '0.1.4', git: "https://#{ENV['GITHUB_TOKEN']}#github.com/Orga/my_gem"
AND also tried
secrets.yml
development:
github_token: ...
gemfile
gem 'my_gem', '0.1.4', git: "https://#{Rails.application.secrets.github_token}#github.com/Orga/my_gem"

The best and most secure way of doing this is using bundle configuration
In your Gemfile, you should have:
source 'https://gem.fury.io/youraccount/' do
gem "your_service", "~> 1.0.0"
end
And then, if you need to authenticate, this can be achieved by running the following terminal command:
bundle config https://gem.fury.io/youraccount/ yourauthtoken
I hope this helps answer your question!
Ben

Related

Globalid and pg not existing when in gemfile

I am trying to rails server from a cloned repo, I have updated ruby, and rails, followed the rvm process, updated all my gem files, and when I go to serve I receive the message
Could not find globalid-0.3.7 in any of the sources Run bundle
install to install missing gems.
So I do bundle install, then get the error
An error occurred while installing pg (0.20.0), and Bundler cannot
continue. Make sure that gem install pg -v '0.20.0' succeeds before
bundling.
Try to insall that and then get
ERROR: Could not find a valid gem 'globalid-0.3.7' (>= 0) in any
repository ERROR: Possible alternatives: globalid, globalize3
I have googled everything and asked many.
globalid is a dependency of the Rails core gem ActiveJob so it is a required gem to have in your Gemfile.lock. See if it is listed in your Gemfile.lock file. If not you could add it to the top of your gemfile including the version
# gemfile
gem 'globalid', '0.3.7'
Then bundle install. If it works, then you can delete it from your gemfile since it should load automatically when Rails loads (since it is a dependency of Rails' ActiveJob). I've run into a similar issue with another gem and this process worked for me.
It could be a version error. Try using gem 'globalid', '~> 0.4.0' in your gemfile and bundling.

How to use rails 3.2 engine in rails 4.1 engine development?

When developing rails 4.1 engine module_infox, there include gem authentify which is developed in rails 3.2 in module_infox's gemfile:
gem 'authentify', :path => '../authentify'
Gem authentify sits locally and its gemfile.lock was deleted to remove the version lock.
When bundle install under module_infox, there is an error:
$ bundle install
Fetching gem metadata from http://rubygems.org/.........
Fetching gem metadata from http://rubygems.org/..
Resolving dependencies...
Bundler could not find compatible versions for gem "rails":
In Gemfile:
authentify (>= 0) x86-mingw32 depends on
rails (= 3.2.12) x86-mingw32
module_infox (>= 0) x86-mingw32 depends on
rails (4.1.0.beta1)
Based on our reading, old version gem can be used in newer version gem. Both gemfile.lock in authentify and module_infox were deleted before bundle install. But there is the same error. What's right way to do so?
I think the specific dependency on Rails 3.2.12 on authentify gem is the reason of conflict.
Solution 1: Direct fix
The most intuitive solution would be changing this hard dependency. Say, revise the gemspec as rails, '> 3.2'.
However, your authentify gem itself may not be ready for Rails 4 yet. So using this would be a bit aggressive.
Solution 2: Use git brach
The better alternative is to add a branch in authentify gem say "rails-4", then change the gemspec as above.
Then you need to specify this git branch in Gemfile.
If you use Github to host this gem
gem 'authentify', git: 'git://github.com/username/authentify', branch: 'rails-4'
If you are not going to opensource this gem, you can still use local path. But you need to setup Bundle to recognize it.
$ bundle config local.authentify ~/Work/git/authentify
Then set it in Gemfile
# gem 'authentify', :github => 'authentify/authentify', :branch => 'master'
I commented out the last line of code because I just copied it from Bundle doc but not verified that before. You can check the doc and experiment by yourself. http://bundler.io/v1.2/git.html

Deploy on Heroku failed: Could not find devise-1.4.4 in any of the sources

I follow a deploy article by Getting Started with Heroku.
I tried to deploy my app to heroku. At the beginning I had this problem
-----> Gemfile detected, running Bundler version 1.0.7
Unresolved dependencies detected; Installing...
Using --without development:test
Fetching source index for http://rubygems.org/
Could not find devise-1.4.4 in any of the sources
FAILED: http://devcenter.heroku.com/articles/bundler
Heroku push rejected, failed to install gems via Bundler
Then I tried some solutions, for example heroku-deploy-cant-find-devise-1-4-6.
I followed these steps
bundle update
git add .
git commit -a "please work"
git push heroku master
but it still have problem.
Here's my Gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.9'
gem 'kaminari'
gem "paperclip", "~> 2.4"
gem "devise"
gem 'web-app-theme', '>= 0.6.2'
gem 'gmaps4rails'
gem 'populator'
gem 'mysql2', '~> 0.2.6'
gem 'capistrano'
and Gemfile.lock
...
capistrano-ext (1.2.1)
capistrano (>= 1.0.0)
cocaine (0.2.0)
crack (0.3.1)
devise (1.4.8)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
warden (~> 1.0.3)
...
It seem to be good.
But why it still have the same problem.
Could not find devise-1.4.4 in any of the sources
Why my Gemfile.lock uses devise 1.4.8 but it still deploy devise-1.4.4? How do I solve this problem?
Devise 1.4.4 was yanked on RubyGems, you need to use any version greater than 1.4.4.
You don't seem to use 1.4.4 in any source. Make sure to specify a version, otherwise other gems might force bundler to use the yanked version.
# Gemfile
gem "devise", "~> 1.4.8"
Then run
$ bundle update devise
Also, make sure the Gemfile.lock file is stored in your git repository. Otherwise Heroku will try to resolve the dependencies on its own. Commit the changes, then push to Heroku.
try putting in your gemfile
gem "devise", "~> 1.4.4"
and then run bundle install before recommiting
It looks like one of your other gems is requiring devise 1.4.4, which was yanked from rubyforge. Check your gemfile.lock for any other mentions of devise under other gems.
Just to eliminate any other possible funny business, try this in your gemfile:
gem "devise", "1.4.8"
And then running:
bundle update devise
git commit
git push heroku master
I try stupid and complicated method, but work for me.
I git my project into Github before.
So I try my former codes which didn't have FB plugin.(maybe it was rfacebook problem !?)
mkdir test-for-another-sol
cd test-for-another-sol
git init
git pull git#github.com:your_name/your_git.git feature/your_former_project
bundle update devise
git add .
git commit -a "please work"
git push git#heroku.com:your_app_in_heroku.git master
It work!

Heroku's trying to install development gems even after I've told it not to

I'm diving into RoR and I'm using Heroku to host the test app I'm building. When I do a push to Heroku, it crashes when trying to intall the linecache19 gem (which is used by ruby-debug19 gem)...
Installing ruby_core_source (0.1.4)
Installing linecache19 (0.5.11) with native extensions /usr/ruby1.8.7/lib/ruby/site_ruby/1.8/rubygems/installer.rb:483:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
After searching all over the web for this problem, everyone's solution was...
heroku config: add BUNDLE_WITHOUT="test development" --app app_name
But the push to Heroku still crashes even after I did that. Here's my Gemfile...
source 'http://rubygems.org'
gem 'rails', '3.0.5'
gem "carrierwave"
gem "mini_magick"
gem "fog"
group :development do
gem 'annotate-models', '1.0.4'
gem 'sqlite3'
gem 'ruby-debug19'
gem 'sqlite3-ruby', :require => 'sqlite3'
end
I even uninstalled the ruby-debug19 gem and it's still crashing and trying to install the linecache19 gem. Why won't this linecache19 gem go away? I'm new to all this and, as such, I'm sure I'm missing something obvious. Your thoughts?
Thanks for your wisdom!
Your heroku config command is malformed. You have a space before add and you are missing the colon between development and test.
$ heroku config:add BUNDLE_WITHOUT="development:test" --app app_name
Docs are here.
Also, are you remembering to run bundle install locally and commit both your Gemfile and Gemfile.lock into git?

Pushing rails app to heroku not working

I'm trying to use git push heroku master to upload my rails 3 app to heroku, but I keep getting the following error:
-----> Heroku receiving push
-----> Removing .DS_Store files
-----> Rails app detected
! Heroku Bamboo does not include any Rails gems by default.
! You'll need to declare it in either .gems or Gemfile.
! See http://docs.heroku.com/gems for details on specifying gems.
! Heroku push rejected, no Rails gem specified.
error: hooks/pre-receive exited with error code 1
I've tried deleting the on the heroku website and starting again, i've also tried wiping out my git repo and doing init again, and I keep getting the same error. My Gemfile is as follows:
source :rubygems
gem 'rails', '3.0.3'
gem 'recaptcha', :require => 'recaptcha/rails'
gem 'devise', '1.1.3'
gem 'acts-as-taggable-on'
gem 'ruby-debug'
# for sass
gem 'haml'
gem 'mocha'
gem 'ruby-pg'
I've run bundle package to package teh gems into vendor cache, but it doesn't seem to change the result.
I upgraded this app from rails 2.3, so i'm wondering if that has anything to do with it?
This is the answer I got from Heroku:
Hi,
The problem seems to be that your Gemfile is called GemFile. While that'll work on some platforms like the Mac, that won't work on a strictly case-sensitive filesystem, such as ours.
In order to rename the file in a case-retaining, case-insensitive file system like HFS or NTFS, you'll need to do it in two steps:
git mv GemFile Gemfile.temp
git mv Gemfile.temp Gemfile
Try adding these to your Gemfile
gem 'pg' # Heroku's DB runs on postgresql
gem 'heroku'

Resources