Ruby Gem server not serving gems? - ruby

I am trying to make a new acceptance agent for teamcity...I followed this article http://docs.rubygems.org/read/chapter/18...
I created a website in IIS called gemserver and having a port 910. it has gems folder which has ancient gems like activerecord-sqlserver-adapter-1.0.0.9250...
I don't know the mime-type for .gem extension so I just put application/x-ruby-gem. Although manually when I put machinename:910/gems/Gem_Name I am able to download it.
but when i use bundle install it gives below error
Fetching source index for http://gems.github.com/
Fetching source index for my server url
Could not reach rubygems repository http://gems.github.com/, my server url:
910/, http://rubygems.org/
Fetching source index for http://rubygems.org/
Could not find gem 'activerecord-sqlserver-adapter (= 1.0.0.9250, runtime)' in a
ny of the gem sources listed in your Gemfile.
Please find below Gemfile.
source "http://computerName:910/"
source :gemcutter
gem 'rake', '0.8.7'
gem 'cucumber', '0.6.2'
gem 'watir', '1.6.5'
gem 'activerecord', '2.3.8'
gem 'activerecord-sqlserver-adapter', '1.0.0.9250'
gem 'rspec', '1.3.0'
gem 'parseexcel', '0.5.2'
gem 'win32-api', '1.4.5'
gem 'nokogiri', '1.4.1'
gem 'win32-eventlog', '0.5.2'
gem 'win32console'

Use the ip address instead of computername and see if that fixes your 504 problem
Now try to update your gems, if you get a 404 error when trying to access a folder called /quick then run the generate_index command with the --legacy option
gem generate_index --legacy
Add .rz mimetype to your IIS so that it can serve the rzip files. In IIS mime types, add the following mapping:
.rz -> application/x-rzip

I don't know the mime-type for .gem extension so I just put application/x-ruby-gem. Although manually when I put machinename:910/gems/Gem_Name I am able to download it.
Your gem client is complaining that the source index can't be reached, not the gem itself.
In the article you linked to, item 4.2.4 instructs:
Run the generate_index gem command in order to generate the yaml and yaml.Z files needed by the RubyGems client.
Make sure generate_index created the yaml and yaml.Z files in your gems directory. Check if they are accessible. This is the source index that your gems client is looking for.
For example, GitHub's gem source index file is located here: http://gems.github.com/gems/yaml

Related

Specify source when using gem install with two sources

We do have an internal gem server (http://my.gem.server) and at this server we store the gem foo-1.2.3.gem
Our users add this server to the gem source. Our gem source looks like::
*** CURRENT SOURCES ***
https://rubygems.org/
http://my.gem.server/
So far it was working wonderfully.
Then someone at the community created the foo-0.0.1.gem
Now, when our internal clients perform a gem install, the foo-0.0.1.gem from the community is installed instead of our foo-1.2.3.gem
We have tried putting our source before the standard rubygems.org but still get the same results.
Does anyone know how can I tell gem install to get the gem from our internal source?
It would be even better if it would just hit the community source if it does not find on ours.
You have two options:
Specify the source in the command
gem install --source http://my.gem.server/ install foo
Edit the ${HOME}/.gemrc file
change
:sources:
- http://rubygems.org
- http://my.gem.server
to
:sources:
- http://my.gem.server
- http://rubygems.org
In your Gemfile, separate all gems into source blocks:
source "http://my.gem.server/" do
gem "foo"
end
source "https://rubygems.org/" do
gem "rails"
end
Having global source lines and/or using :source to disambiguate can open you to security issues, as these don't actually work the way you would expect:
http://collectiveidea.com/blog/archives/2016/10/06/bundlers-multiple-source-security-vulnerability/
Any internal gem name might get claimed on rubygems.org and suddenly get installed instead.
To add on to #ptierno's answer, if you have a Gemfile or .gemspec you can use the :source parameter.
gem 'foo', :source => 'http://my.gem.server'
Which gives priority to that server for that gem only.

Bundler: using shared gem when it exists, rather than downloading from gem server

Say, I have Gemfile like following.
source "GEM_REPOSITORY"
gem 'gem_A'
# gem_A has no additional dependency
gem 'gem_B'
# gem_B depends on gem_B_1 and gem_B_2
When I run bundle install, I want Bundler to do the following.
If a gem already exists in "local system-wide gems", it copies the gem from local.
If a gem doesn't exist in local, it looks for GEM_REPOSITORY.
I looked for some related articles, and found some of likely-answers like
Ruby Bundler multiple sources in Gemfile
SOURCE PRIORITY
But none of the above looks like the answer for me.
Using source repository priority does't work. Because in the example above, if dependent gem (say, gem_B_1) exits in local but the target gem (gem_B) doesn't exist in local, it'll download both of above from the remote repository.
Are there any work around for doing this?
If not, don't you guys think it's necessary considering the cost of the implementation and the effect?
This is the current behavior.
When running gem install, directly or via bundle install, gem will first build a dependency graph with all the needed gems. If the gem is found locally it will use it, otherwise it will try to download it from the specified source.
If you want, try it yourself.
bundle gem gem_a
bundle gem gem_b
cd gem_a
vim gem_a.gemspec
add
spec.add_dependency 'multi_json', '~> 1.10.1'
or any dependency you want to the gem and run bundle install.
cd ../gem_b
vim Gemfile
and add
gem 'gem_a', path: '../gem_a'
then run
bundle install --verbose
you will see that the multi_json or whatever dependency of gem_a uses the local version and does not download anything.
This is of course also true for gems from remote sources.

How to use gem from GitHub on Heroku?

I've forked the redis depository on github to https://github.com/lmirosevic/redis-rb
I added it to my Gemfile:
gem 'redis', :github => 'lmirosevic/redis-rb'
And I require the gem inside my Sinatra app:
require 'redis'
However it fails with the following error:
/app/vendor/ruby-2.0.0/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- redis (LoadError)
Any suggestions on what could be wrong? It seems like it should work!
EDIT
I should note that the bundler phase is fine. The problem seems to be in the require step.
Bundler gives me this output:
Using redis (3.0.4) from git://github.com/lmirosevic/redis-rb (at master)
I should also say that my directory structure is something like this. Not sure if this makes a difference.
/
.env
Gemfile
Gemfile.lock
Procfile
/lib
my_sinatra_app.rb
/config
...
You must have
require 'bundler/setup'
in your app or else you're not really using bundler: this is what ensures that the gem versions loaded are the ones in your gemfile and sets up load paths for anything not installed globally.
Calling Bunder.setup allows you to control what groups are used, but if just using the default group is fine then you don't need to do this.
If you aren't setting up bundler then your gemfile is used to install the required versions of the gems but then bundler is no longer used - your app will used whatever gems are installed, whether the versions match or not and you won't be able to use gems that aren't installed in the default gem load paths.

gem server won't serve gems

I'm trying to set up my own private gem server which should serve my gems and display the rdoc. As I've read the default gem server should be able to do that. And since I do not want all gems except my own to be displyed on the gem server I'm doing the following:
gem install -i /some/dir --ignore-dependencies my-special.gem
gem server -d /some/dir # -d should let me set my gem dir
But first of all, the gem server still displays all installed system gems and does not display what's inside some/dir. And second, when trying to do a:
gem install --source http://localhost:8808 my-special.gem
I only get the following messsage:
ERROR: Could not find a valid gem 'my-special' (>= 0) in any repository
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
bad response Gateway Time-out 504 (http://localhost:8808/latest_specs.4.8.gz)
And I get that even for the gems that get displayed on the created gem server page at
http://localhost:8808
What am I doing wrong? Some blogs mention to update the index with gem generate_index but this makes no sense since this tool expects the *.gem files to be in a /gems subdir but by default they land in /cache.
I solved this pretty easily.
I don't even use a dedicated gem server.
I did the following:
Create a directory on your apache web server that is servable and create a gems subdir in it. For example:
mkdir -p /var/www/rubygems/gems
Put all gems you want to serve to the created gems subdirectory: cp /my/gems/dir/*.gem /var/www/rubygems/gems
Generate the gem index:
gem generate_index -d /var/www/rubygems
Do not forget to adapt the access rights so that your web server can read the contents
INFO: The index has to be generated in the directory that contains the gems subdir, not the gems dir itself! In this case it's /var/www/rubygems.
Now you can add http://<my-gem-server>.domain/rubygems to your gem sources

Using bundler with "--path vendor", why are gems specified with ":git" not locally vendored?

I'm using bundler and have a Gemfile that looks like this:
source 'http://rubygems.org'
gem 'sinatra', '1.3.1'
gem 'httparty'
# ...etc...
gem 'my_custom_gem', :git => 'git#github.com:me/my_custom_gem.git'
When I run bundle install it fetches the necessary gems, including my custom gem, and installs them in the system gem directory. So far, so good. However, an issue arises when I try to vendor them into a project-local directory. When I run
bundle install --path vendor
It creates the "vendor" directory in my project root and installs all the regular gems there. So I see directories like
vendor/ruby/1.8/gems/sinatra-1.3.1
vendor/ruby/1.8/gems/httparty-0.8.1
...etc...
But it does not vendor the gem specified with a 'git' parameter. I expect to see but do not see anything like
vendor/ruby/1.8/gems/my_custom_gem-1.0.0
It continues to use the system-installed version of this gem. Any explanation for this? Any clean way to get this custom gem vendored as well?
Not supported right now, hopefully coming in Bundler 1.1:
https://github.com/carlhuda/bundler/issues/67
For now you'll have to do:
cd vendor/ruby/1.8/gems/
git clone git://github.com/foo/foo.git
or similar

Resources