Self contained ruby "binary"? - ruby

[Ruby Noob]
I have a small (command line) utility written in Ruby, which requires a few gems. Is there a way to create a self contained bundle of my program such that I can run it on another machine that has Ruby installed (but not necessarily the gems)?
FWIW, the target machine runs Linux/Ubuntu.

You can use the gem bundle http://gembundler.com/
With bundle you create a Gemfile in your project root - a text that contains all your dependencies, very similar to Maven concept
In order to fetch all your dependencies simply tun
bundle install
The only issue is that you need to have the bundle gem itself installed, so you are back with the chicken-or-Egg problem :-)

I've used:
http://www.erikveen.dds.nl/rubyscript2exe/
before, but it was a while ago. Seemed to work okay for simple programs.
You can download it here:
http://rubyforge.org/projects/rubyscript2exe/

Related

A variation on internally distributing a rails app

I have written a ruby service that I want to package and distribute internally to a specific environment (a standardized linux host). After digging around a bit for the best ways to create a distribution, I've come across a lot of blogs and answers here that recommend bundler and gem packaging as well as a lot of binary distribution options (e.g. traveling-ruby), but these all seem like a bit too much for a relatively simple service that will get deployed to a known environment. I want to create a distribution that doesn't require dependencies to be resolved at deploy time (e.g. bundle install --deployment is not the approach I want).
So with this in mind, is there an available framework that is commonly in use by ruby apps that would create a redistributable package with all dependencies included in it? I am currently doing this in 2 steps and wondering if there's a "better" ruby-way of doing it - something along the lines of gem build ... that creates dependency-inclusive archive?
# Assuming `bundle install` was run on developer workstation and there's a `Gemfile.lock`
$ bundle install --deployment
$ tar zcf ../my-app.tar.gz ./
my-app.tar.gz can now be distributed and if I have an executable to run it with, I can do so with bundle exec bin/run from within the directory after it's extracted. This a good approach?
I've seen a gem called crate that might be able to work....

Building CompassApp (jruby app) executable from source on Windows

I would like to build the executable of CompassApp, a GUI application that lets webdesigners compile stylesheets by using SASS and Compass without using the command line.
The source can be found on GitHub here: https://github.com/handlino/CompassApp.
CompassApp is a an application developed in Jruby.
From the GitHub webpage of the project:
If you want to build your own copy, you will need JRuby and rawr
I am using Windows 7 as operating system for my webdesign projects. I never built a jruby app from source. It seems on linux it's easier to install the required things, anyway i'm using Windows now.
First i cloned the GitHub repository.
Then i installed jruby.
Now i should install rawr (https://github.com/rawr/rawr)
It seems that rawr also requires javac and rake
I saw that rawr and rake are 2 ruby gems.
So how do i install those 2 ruby gems for jruby on Windows?
And how do i build CompassApp from source after i have everything i need?
I would need a step by step guide from the install of the requirements
to the build of the application.
(i never used jruby in the past).
If someone of you develops apps in jruby i think that can help me easily.
I thank you in advance.
#Fabio Hi, we made Compass.app and Fire.app :-)
It is easy to build Compass.app on OS X or Linux. We have a (almost) step by step guide about building Fire.app on the GitHub wiki and it can be applied to Compass.app too: https://github.com/handlino/FireApp/wiki
We have never tried to build it on Windows, and do not think it can be done easily.
I'm trying to do a similar thing, but in my case only package the gems in a self-contained executable jar. the docs are not very descriptive and some are outdated.
I tried rawr but managed to get further with warbler
here's what I did: I created a folder named jrcompass and installed compass into it:
c:\test\jrcompass>%JRUBY%\jruby -S gem install compass -i .
I installed warbler and then ran the warble command in that folder:
C:\test\jrcompass>c:\apps\jruby\bin\jruby -S warble
that created a ~20MB jar file named jrcompass.jar which is farther than I got with rawr.
now I'm trying to execute the jar with:
C:\test\jrcompass>java -jar jrcompass.jar
and I get the following error below. I hope that this will help you make progress. please let me know if you figure it out.
Gem::LoadError: Could not find compass (>= 0) amongst [rake-0.9.2.2]
to_specs at jar:file:/C:/Users/Admin/AppData/Local/Temp/jruby1564362137331239458extract/jruby-stdlib-1.7.1.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/dependency.rb:247
to_spec at jar:file:/C:/Users/Admin/AppData/Local/Temp/jruby1564362137331239458extract/jruby-stdlib-1.7.1.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/dependency.rb:256
gem at jar:file:/C:/Users/Admin/AppData/Local/Temp/jruby1564362137331239458extract/jruby-stdlib-1.7.1.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems.rb:1231
(root) at file:/C:/Apps/test/jrcompass/jrcompass.jar!/jrcompass/bin/compass:22
load at org/jruby/RubyKernel.java:1046
(root) at file:/C:/Apps/test/jrcompass/jrcompass.jar!/META-INF/main.rb:1
require at org/jruby/RubyKernel.java:1027
(root) at file:/C:/Apps/test/jrcompass/jrcompass.jar!/META-INF/main.rb:1
(root) at jar:file:/C:/Users/Admin/AppData/Local/Temp/jruby1564362137331239458extract/jruby-stdlib-1.7.1.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/custom_require.rb:1

Pack gem with app

So I have a simple app/script wich depends on a single gem and what I want to do is to pack it with the app so there is no need to install it each time on every new machine it needs to run.
I tried with bundler pack command but the problem is that this way I still need to have bundler installed which I can't assure.
So what a made was grab the code I need from the gem and then used it.
My question is:
How can I pack the gem with my app without any dependency and is my current solution is polite?
Cheers
from setup.rb(or wherever the entry point of your application) add this line:
Dir.glob("#{File.dirname(__FILE__)}/lib/*.rb") { |lib| require lib }

Ruby gems in lib - spare tire principle

I'm working on a console ruby application (not rails!) I will be installing this application on several machines. I was wondering if there is a way i can build it so i dont have to install the gems i'm using for the app on each machine. I'd like to be able to just copy the directory to each machine and run it. Ideally, i'd like to put the gems in the lib folder or something and reference them from there, so i don't have to even install them on my dev machine. Is there a way to do this?
In .net, we call this the "spare tire" principle.
thanks,
Craig
How about using bundler?
Then you can include a Gemfile that specifies all the necssary gems and just run "bundle install" on each machine to pull them down.
If you really want to bundle them with the app run "bundle package" and the gems will be stored in vendor/cache.
You could take the same approach as rails allows and "vendor" your gems. This involves creating a new directory (rails uses vendor/gems) and unpack the gem into this directory, using gem unpack.
You then configure your load path to include all of the sub-folders below that.
Edit
You can configure your load path by doing something like this
Dir.glob(File.join("vendor", "gems", "*", "lib")).each do |lib|
$LOAD_PATH.unshift(File.expand_path(lib))
end

How to develop a gem in staging environment?

I am trying to hack through a forked gem (buildr). As such I cloned it from github and began to butcher the code. The official gem is installed on my system (under /usr/lib/ruby.../gems/buildr...). There is an executable which I need to use in my dev process - buildr.
Now I want the buildr executable and the library to point to my forked repo and not the default gem installation. This would be for this gem only. As such, the changes I make against the forked repo is usable directly for testing and so forth.
I would guess I need to load my library prior to the system gem loading. Can somebody recommend the best way to do so?
I did something similar for work when the Spreadsheet gem broke backward compatibility. I put the previous versions code in it's own module and just renamed the gem my-spreadsheet and installed that (I really wanted some of the features of the new gem but I also didn't want to rewrite all my previous code at that point).
If it's just a binary you want to override you could always do some PATH magic, setting the directory of your binary first and thus make sure you always override. But personally I'd prefer making my own copy with a new name and installing that.
you could bump the version in the gemspec for your fork. Then when you install your version of the gem, it will use your (newer) version by default.
change buildr.gemspec
#...
spec.version = '1.3.4.dev'
#...
Then
$ gem build buildr.gemspec
$ sudo gem install buildr-1.3.4.dev.gem
and it should work.

Resources