gem server won't serve gems - ruby

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

Related

Bundler config to either look for gems in custom path or download from custom source

How do I configure bundler so that when I run bundle install it looks for gems under /my/custom/path first and if it doesn't find there then try to fetch them from a ruby gem remote repository hosted under https://a.nice.host and downloads those into ./local/relative/path (relative to cwd for example). I would like to avoid the bundler looking at default gem installation system path or rubygems.org
The syntax for sourcing a gem from a local folder is:
gem 'some-gem-name', path: '/my/custom/path'
And the syntax for specifying a custom source is:
gem 'another-gem-name', source: 'https://a.nice.host'
And to install gems into a specific local folder, you can run:
bundle install --path ./local/relative/path
Now, that's probably all the tools you need, in truth... (And in fact, especially for that last requirement, you may instead wish to look into rvm gemsets, or using bundle install --deployment.)
But you did also ask about "looking in a local folder first, and only falling back to a remote source if it doesn't exist". That's quite an odd requirement (usually you'd only want to explicitly opt-in to fetching gems from a local path?!), but to answer this question as you've asked it...
A Gemfile is literally just ruby code! So you can define this logic using... You guessed it, ruby! For example:
if File.exists?('/my/custom/path')
gem 'some-gem-name', path: '/my/custom/path'
else
gem 'some-gem-name', source: 'https://a.nice.host'
end
If this (unusual) pattern needs to be repeated in multiple places, you could wrap it into some helper method.
For more information on the configuration options of bundler, please see the documentation.

Ruby Gem conflicts between local gem and system installed gem

I have a Gemfile that looks something like this:
source 'http://rubygems.org'
gemspec
gem "parent_gem", "0.1.3", :path => "#{File.expand_path(__FILE__)}/../vendor/gems/parent_gem-0.1.3"
parent_gem depends on child_gem-1.4.1, which we have packaged in the /vender/gems folder in the package. If a user installs child_gem-1.6.0 on their host on Ubuntu, they will get a Gem::ConflictError because it will try to use 1.6 and log child_gem-1.6.0 conflicts with child_gem (~> 1.4.1). However, if a user runs it on Amazon Linux, it works fine and uses the packaged child gem.
If I run gem list child_gem, I get the following output on both systems:
*** LOCAL GEMS ***
child_gem (1.6.1)
gem list parent_gem returns nothing because it's not installed separated and only exists in the package's vendor directory.
In the files that initiates the script, there is this line:
Gem.use_paths(nil, Gem.path << "/opt/my-app/vendor")
And the /opt/my-app/vendor directory includes child_gem-1.4.1.
Ultimately, I know that setting up the package properly with Bundler should resolve the issue, but I'm trying to understand why this is an issue.
How does Ruby decide where to look for a gem on a system? And where do I look to understand why it works on Amazon Linux but not Ubuntu?

Ruby Gem server not serving gems?

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

How to bundle local gem dependancies in IronWorker

I have a Ruby IronWorker which depends on a private gem that isn't published to RubyGems.
Is there a way to merge this local mygemname-0.0.1.gem into my IronWorker in the .worker file?
I'm hoping to be able to specify something the following in myruby.worker:
gem 'mygemname', '>=0.0.1', :path=> 'vendor/bundle'
Currently this give the following error
.rvm/gems/ruby-1.9.3-p0/gems/iron_worker_ng-0.12.2/lib/iron_worker_ng/code/base.rb:79 :in `eval':
wrong number of arguments (3 for 2) (ArgumentError)
Hoping for defaults gives:
gem 'mygemname', '>=0.0.1'
Gives the following error
Could not find gem 'mygemname (>= 0.0.1) ruby' in the gems available on this machine.
Am I on the right track trying to get this to work via the .worker file? Or should I be looking into specifying a custom build step?
If your unpublished gem itself has dependancies, you need to do a little massaging to get things going. Here is a technique that works for me:
mygem.worker
runtime "ruby"
#Merge in an unpublished local gem
dir '../opensource-cli-tools/facebook_exporter', '__gems__/gems'
file '../opensource-cli-tools/facebook_exporter/mygem.gemspec', '__gems__/specifications'
#Merge in a custom build script to fetch the unpublished gem's dependancies
file "Gemfile"
file "install_dependancies.sh"
remote_build_command 'chmod +x install_dependancies.sh && ./install_dependancies.sh'
#Run the puppy!
exec "run.rb"
install_dependancies.sh
echo "Installing dependancies to __gems__/"
gem install bundler --install-dir ./__gems__ --no-ri --no-rdoc
bundle install --standalone --path ./__gems__
cp -R ./__gems__/ruby/*/* ./__gems__
rm -rf ./__gems__/ruby
echo "Fixing install location of mygem"
mv ./__gems__/gems/mygem ./__gems__/gems/mygem-0.0.1
As far as i know, git and local paths unsupported right now.
Here is way to manually include local gem:
Add these lines to .worker file:
dir '../vendor/bundle/mygemname', '__gems__/gems'
file '../vendor/bundle/mygemname/mygemname.gemspec', '__gems__/specifications'

gem install XYZ locally (without connection to the internet)

I need to install win32-api and antlr3 on a computer without internet connection. Had it such a connection, I'd use gem like so:
gem install win32-api -r
gem install antlr3 -r
This won't obviously work. So, I thought there should be a way to download the gem and install it later, but I am not sure how I would proceed.
I found gem's which operator, which seemd to indicate the local location of a gem:
c:\>gem which antlr3
c:/tools/Ruby187/lib/ruby/gems/1.8/gems/antlr3-1.8.8/lib/antlr3.rb
however, it didn't work on win32-api:
c:\>gem which win32-api
ERROR: Can't find ruby library file or shared library win32-api
although I have previously installed it.
Can someone hint at the right direction to go on from here?
Try,
gem install --local path/to/file.gem
I had some problems with this on a VM. The VM intentionally did not have Internet access (sneaker-net test machine) but it still had some DNS servers configured.
For example:
$ gem install bundler-1.7.7.gem --local
ERROR: While executing gem ... (Errno::ENETUNREACH)
Network is unreachable - sendto(2) for "192.168.1.10" port 53
192.168.1.10 is the DNS server that VirtualBox configured. So what I had to do is comment out /etc/resolv.conf with ; at the beginning of all the lines. Even leaving in Google DNS would break it.
; /etc/resolv.conf
nameserver 8.8.8.8 ; nope. gem install --local doesn't like it
; You will get a Network is unreachable - sendto(2) for "8.8.8.8" port 53
If you comment out all of /etc/resolv.conf then you can install gems locally (from a file) it seems.
$ gem install bundler-1.7.7.gem --local
Successfully installed bundler-1.7.7
Parsing documentation for bundler-1.7.7
Installing ri documentation for bundler-1.7.7
Done installing documentation for bundler after 4 seconds
WARNING: Unable to pull data from 'https://rubygems.org/': no such name (https://rubygems.org/specs.4.8.gz)
1 gem installed
Ruby gems version: 2.4.4 on Ruby 2.1.5.
gem will first look in the current directory after .gem files. Try downloading the .gem files of the gems you want to install on a computer with an internet connection (and don't forget dependencies), then move the files over to the other computer and run gem install xyz in the same directory where you placed the .gem files.

Resources