'deploying' a ruby script with gems - ruby

i've written several Ruby scripts that work together to from a console application.
These scripts are written on an Ubuntu platform, but I want to be able to run them from a Windows platform as well.
The problem I'm currently facing is porting over all the gems. I've downloaded sources of most gems and made some bug fixes on them, but is it possible to package them for example with my scripts so they're available?
I'm thinking a bit DLL like here as Windows does.
I can probably add a readme file, stating which gems are required and where/how to obtain them, but it would be easier if I could package them.

Maybe you could look at http://www.erikveen.dds.nl/rubyscript2exe/index.html which does some packaging for ruby application (including the ruby interpreter, too)
You could also build a gem with your script in it along with all needed gems directly inside the gem. Provided their licences allow you to do that, it could be a reasonable solution ( Gem supports platform flavoured gems http://docs.rubygems.org/read/chapter/20#platform )

Related

Rubymine use local gem configuration

I'm running Ruby mine 7.1.2 on Windows and I'm having difficulty with it because it seems to want to use its own gems and version of fun where. My application works fine from the command line if I do bundle install or bundle exec rails script but when I try to run from the IDE it complains about missing gems.
I could just try to reinstall all the gems via ruby mine but some of the gems require special customization in Windows and doing that from the command line is much easier. Is there anyway I can have ruby mine just use the gems which are already installed?
Rubymine will usually bundle your ruby SDK (i.e. ruby itself) and all it's associated gems so that you don't end up with weird configuration dependencies.
If you want to circumvent that then follow an official guide. In addition to that guide, be aware that there are also per-run SDK settings. These kick in when running or debugging a RubyMine project and need to be configured in the run -> configuration settings dialog.
My (unsolicited) additional advice is that I'd recommend figuring out what aspects of your global ruby installation are causing issues with RubyMine's bundle installer. The reason RubyMine sandboxes several SDKs is to reduce major headaches when you go to deploy your applications. Without it, you might encounter dependency hell when you deploy your application. From my personal (and extremely annoying) experience, rushing these initial set-up steps tend to come back with vengeance when you want to run ruby apps elsewhere.

Approach for installing system service implemented as Ruby gem

After years of being away from Ruby, I'm back full-force and have just cut my first gem, which includes an executable. Everything works like a charm.
The problem I am facing, however, is that I ALSO have a startup script (not part of the gem istelf) that daemonizes the executable. Additionally, I'd also like for the startup script to point the executable at configuration in a place like /var/
To the best of my knowledge, there's no way with rubygems, gemspec, etc., to specify files getting blown out to other parts of your system during install (e.g. startup script to /etc/init.d, and config to /var/). It certainly wouldn't make sense if you COULD do that.
So... my question is... what IS the proper procedure for automating the installation of something like this. I'm using RHEL, and am wondering if it's, perhaps, time for me to get my feet wet with making my first RPM.
Any thoughts?
You can do it. However it is probably not quite the recommended approach. But yes it is possible to run arbitary code during gem installation using the extensions option.
From the RubyGems Manual:
Usage
spec.extensions << 'ext/rmagic/extconf.rb'
Notes
These files will be run when the gem is installed, causing the
C (or whatever) code to be compiled on the user’s machine.
Just place whatever ruby code you need into the extconf.rb (or equivalent) file.
Examples for building C-extensions from the RubyGems Guides:
http://guides.rubygems.org/c-extensions/

Ruby standalone app deployment/distribution

What's the best way to distribute a simple command-line Ruby app to clients in a way that would not require them to manually install Ruby and required Gems?
In my understanding this task boils down just to a couple of lines of SH/BAT code that does Ruby/Gems checks and if not found goes on with Ruby installation with RVM.
So do these lines of code exist already somewhere or will I need to write something on my own?
I've used this project for small scripts in the past, without any issues
http://www.erikveen.dds.nl/rubyscript2exe/
It creates an EXE file out of your ruby script.
If you need something cross-platform, the BAT/sh option is probably best. You could grab RVM, have RVM install ruby, use bundler for your gems, and then launch the script.
The closest I've found is (I believe) releasy: https://github.com/Spooner/releasy
I failed to find any way of producing a Ruby cross platform installation.
I've created a RubyAnywhere script that tries to solve this task.

How to package a Ruby application?

I've got an application in Ruby that uses the Qt 4 bindings. I want to be able to package and release it.
I've looked at other applications such as rake and puppet to see how they're packaged. Both rake and puppet are packaged as gems. I started going down this route when I realized that both rake and puppet are more system level tools rather than user-level applications.
I also looked at orca, but it's windows only.
Are there other options available for packaging a Ruby GUI app other than gem or orca? I'd like something that's cross platform.
Take a look at the platform specification for gems. You can package up a gem for each platform that your code supports.
Some gems consist of pre-compiled code (“binary gems”). It’s especially important that they set the platform attribute appropriately.

Packaging precompiled binaries inside of a gem

I've got a ruby web app that uses lilypond to generate sheet music based on user input. I'd like to move the hosting to heroku (I've recently used heroku on a few projects and really liked it, plus my traffic is low enough that it'd be free host it on heroku, for a while at least). However, heroku's dyno architecture doesn't allow you to ssh in and install whatever packages you want...instead, you give it a gems manifest, and it will install the gems for you.
So, if I'm going to deploy to heroku, I'm going to need to package lilypond as a gem. I've released a few pure-ruby gems, but haven't dealt with native extensions or precompiled binaries, or anything like that.
Is it possible to take some precompiled binaries and package it inside a gem? Ideally, this would include binaries for OS X (which I develop on) and debian linux (which is what's running on heroku), and would install the proper binary when the gem was installed.
it is possible, since precompiled binary gems for windows are the norm. Take a look at rake compiler, perhaps.
also https://github.com/rdp/ruby_tutorials_core/wiki/gem (https://en.wikibooks.org/wiki/Ruby_Programming/RubyGems) might help
-r
I think you've got a few options here:
You could get the Lilypond source and package it into a gem with a native C extension. There are some useful guides on how to do that at http://guides.rubygems.org/c-extensions/ and http://patshaughnessy.net/2011/10/31/dont-be-terrified-of-building-native-extensions
There's also a gem called gitara but I haven't been able to find any information about using it on Heroku. It might be worth emailing the author and asking if he knows anything about that.
You could create a Heroku buildpack that installs Lilypond as part of your deployment. I wasn't able to find any for Lilypond, but there are plenty of examples that do similar things - for example, this one installs Imagemagick (which is included by default on Heroku, so probably not necessary anymore - but hopefully the code is helpful). More documentation at https://devcenter.heroku.com/articles/buildpack-api and https://devcenter.heroku.com/articles/buildpack-binaries
Based on my reading, I think the buildpack option is the best way to go.
Hopefully this helps!
Instead of precompiling, you should be able to just list the gem in your .gems file, see the Heroku documentation. Of course, this requires your gem builds the native code correctly - this is still a task, but hopefully an easier one.

Resources