What is the best way to package a Ruby on Rails Application? - ruby-on-rails

So I have created a ruby on rails application that functions as a basic calculator. Now I want to package this application up, upload to github, download onto Jenkins, and create a Jenkins job that will run this ruby application.
Normally if this was a Java Application, you would package it as a jar file and then run the jar file. What would I package this Ruby application as?
I thought about packaging this application as a Ruby Gem, but aren't Ruby Gems mainly for when you want to use your ruby app inside of another ruby application? I want to run this app as a stand alone application.
Even if I were to package the Ruby on Rails app as a Ruby Gem, how would I run the gem as a stand alone gem? What would be the command to run it as such from the command line?

Unlike Java applications that have packaging as a first class citizen(be it a jar or a war) this concept isn't baked in most development environments.
That's why there a big push towards docker, it allows you to insulate your app(and gem dependencies) and plug it into the production environment much like dropping a war into a container.
Here's an article about dockerizing a Rails app:
https://semaphoreci.com/community/tutorials/dockerizing-a-ruby-on-rails-application

Related

Packaging rails app

I have a rails application that I'm trying to use on other machines that do not have ruby, rails, or bundler installed. Is there a way I can zip up the rails application, the ruby environment and all its gems / dependencies? I'd like to be able to just send the zipped file to a computer without ruby and be able to run the application without having to install ruby, rails, bundler and all the gems in the rails app.
I've tried traveling-ruby, but it just packages ruby and not rails or bundler.
Edit: For clarification, the app is an internal tool for work. We would rather not deploy the app to a server, but rather just share the whole package with computers that may or may not have the dependencies installed.
You should consider Docker to prepare a "package" of self sufficient environment for your application. This way you will be able to send it to another machine and run without problems. You can use those containers for development purposes only. There is no requirement to deploy them into a server.

Ruby on Rails: How to deploy an app on remote linux server

I have a working ruby on rails app in my local machine running on localhost(REST APi's). I want to deploy it on remote linux server.
I searched it over google, All I got was installing ruby, rails, nginux and others. It's really confusing. To make my app to work in rails environment in linux, is it really necessary to install the entire ruby and rails. Or, is there any binary executable available where we can use it without installing.
What is minimum required software to install or configuration needed to be set to make my app work in production environment?
(For Example, when I deploy nodejs app, All I need is to put the linux nodejs binaries in server without the need for installing the entire nodejs software)
Any help is appreciated!
The process of setting up your production server will be pretty much the same as with setting up your development machine in terms of installing Ruby and its dependencies. There are no binaries that you can just copy over. In addition to that you'll have to install and set up a web server like Apache or nginx.
I recommend this guide by Digital Ocean. It goes through everything from installing ruby, to setting up the database, to configuring the web server.
They have a couple more (here and here), which seem to be very similar, using different application and web servers, but I haven't read them.
You need to do the following:
1) Ensure that you have an installation of the Ruby language, either via your Linux package manager or with rvm or the like. I recommend it be a recent version (2.2+).
2) Copy over your Rails source tree.
3) gem install bundle
4) bundle install (in the project root directory)

Distribute Ruby on Rails app

I'm trying to figure out a way to distribute a Rails application in a fairly standalone way. Think of Sickbeard or CouchPotato, two apps you only need Python to run.
That's basically what I want to achieve, but with Rails instead. There are some failure stories out there and some that are just too complicated, but I'm hoping that there has been some advancements in the field that I just can't find.
Is there a way to distribute a Rails application including any gems it depends on in a way you only require Ruby installed to run it?
I have no intention of trying to obfuscate the source code.
Just use Bundler. Mostly every new Ruby installation have RubyGems and Bundler in standard so the only thing that End-User should do is:
$ bundle install
$ rails s
And will get running app with all dependencies installed.

RoR newbie: Regarding rails setup and rubygems

I'm beginning to learn Ruby on Rails, I installed the latest ubuntu release on a VMWare machine and started the ruby on rails setup process using the mini-guide in this online book (which was recommended in stack overflow more than once). I'm wondering:
As part of my environment setup process I installed RubyGems and used it to install Rails (which is, if I understand correctly - a gem itself) the first time.
Now, when creating a new project using rails new project_name I later on edit the Gemfile and specify "rails '{version}'", which, from what I understand, installs the Rails gem in the context of the project (after using bundle install)...
Why would I need both of them? I'm kind of confused and would be more than happy if someone could shed some light over this...
Yes, this is a bit confusing.
When you run rails new project_name, you are using whatever rails executable is available in your shell to start a new rails project. To see what version this is, run rails —version. This does not "install the rails gem" — it just generates the tree of files to get you started on a new rails project.
You'll then specify in your Gemfile which version of rails your project will use.
So, be sure to have the latest version of rails available to your shell when you generate your new project, so that you get the newest version of the files it generates.

Does the hoster has to support "Ruby on Rails" or "just Ruby" to run Rails?

Does the hoster have to support "Ruby on Rails" or "just Ruby" to run Rails?
I know mainly PHP and ask myself if "Ruby on Rails" behaves to Ruby ... like "Zend Framework" to PHP: just a bunch of PHP files I can copy in my project folder and my hoster only needs to support PHP.
I ask as my host only supports Ruby (but not Rails). If I couild just copy rails over sftp within the project, I would like to give it a try.
The primary thing is, you cannot chain your Rails application directly with Web-server, so the hoster should support one of these servers: Passenger, Thin, Mongrel, and so on.
Another thing to know is, your Rails application can also depend on some specific gems, thus they should be already installed by the hoster to successfully run your application (for example, the hoster has some super-duper control panel that can deal with Rails bundles to setup every gem, check environment, do migrations, and then run the server itself; or the hoster gives you plain SSH and you do everything you need to do, if you know what to do and how to do).
The host has to support Ruby (or JRuby). Rails is a framework that's implemented as a set of Ruby files that are distributed as RubyGems.
If a web host says they support Ruby, it's assumed Rails will work. Rails is just a Ruby application though, and all the Rails code needed to run the application can (and often does) live right in your app's directory tree.
Rails is a Ruby framework. So a basic rails app needs only ruby and rubygems. RubyGems is similar to PHP Pear but a bit more flexible and powerfull. In order to serve the HTML produces by your rail app you need a webserver. Ruby provides natively a "basic" Webserver called Webrick.
But in a production environment you'll need a real webserver (Nginx, Apache) and Passenger.

Resources