Rails

Ruby on Rails

Getting Started with Ruby on Rails

App42 PaaS offers fully managed Ruby on Rails hosting for Shared hosting environment.

It is easy to deploy highly scalable and fault tolerant Ruby on Rails applications, within minutes. Our highly design App42 PaaS architecture protectively monitoring your servers 24*7, you can rest assured that you are in good hands. Below are the steps you have to follow:

Glossary

Kontena – Kontena is a lightweight container that will run your apps and services in an isolated and secured manner. You can specify the power of the Kontena while setting up infra or creating services. One Kontena power specifies to 256 MB Memory and 128 MHz CPU.

Service – Services in the App42 PaaS are add-on components which are needed in an App. App42 PaaS supports multiple services like SQL databases, NoSQL databases and more.

Prerequisites

To get going with App42 PaaS, below are few prerequisites that will allow you to use AppHQ – App42 PaaS Management Console as well as Command Line Client.


Setup infrastructure for Ruby on Rails environment

To deploy your Ruby on Rails application on App42 PaaS, You first need to setup an environment by providing certain inputs which will run your app. Below is the screenshot of setting up the required environment for your app using Command Line Client. You can also perform the same using AppHQ – App42 PaaS Management Console.

$ app42 setupInfra
Enter App Name: railsdemo
Checking App Name Availability... OK

1: Shared
Select Instance Type [Shared]: 

1: Amazon (Oregon)
Select IaaS Provider [Amazon (Oregon)]: 

1: Ruby 2.0.0
2: Java 6
3: Java 7
4: PHP 5.3
5: PHP 5.5
Select Runtime [Ruby 2.0.0]: 

1: Ruby on Rack 
2: Rails 4.0
3: Sinatra 1.4
Select Framework [Ruby on Rack ]: 2 

1: Nginx 1.4.1
Select Web Server [Nginx 1.4.1]: 

Specify Kontena Power: 1

Setting up the infrastructure... OK
  
Operation is in progress, Please wait.../
  
Setup Infra completed successfully.

Default application has been deployed. You can visit 'https://railsdemo.iab.app42paas.com' to see the default application.
Create Your Application

You may be starting from an existing app. if not you can also use our Sample Apps and extend it to suit your needs. Here is the link to Ruby on Rails Sample App .


Prerequisite production environment configuration

Same code of rails application used to run on different environment(development, testing, staging and production). To run application smooth on production environment we have to ensure that we are doing all expected production configuration.

Gemfile

In App42 PaaS, you are supposed to configure the database yourself, we do not make any assumptions on applications that are running which gives maximal flexibility on what can be deployed. To enable your database, add the required gem to Gemfile (located in the root of your application). For MySQL, add mysql2 gem dependency.

group :production do
    gem 'mysql2'
end

Configuration

1. By default, Rails 3 does not serve static files. To enable that, change this line to the config/environments/production.rb file:

config.serve_static_assets = false => config.serve_static_assets = true

2. Enable assets compilation on request: Assets will be compiled on first request and then, they will be cached on front-ends until assets will not change.

config.assets.compile = false => config.assets.compile = true

3. Sendfile allows you to keep all your protected assets in a publicly inaccessible folder in your application folder.

config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

You are ready now. If you do not have any special dependencies in your code, there should be no problem with getting your application running.

Deploy a Ruby on Rails application

You can deploy the application on App42 PaaS platform using two ways. One, you can create a binary (including all dependencies) on your local development environment. Other, you can deploy your application by providing the Git repository URL of your app.

NOTE: In case of deploying from source, Either the provided Git repository must be public or if you want to deploy from private repository, you need to provide the pull permission to App42PaaS Github user.

Deploy Binary

$ app42 deploy
Enter App Name: railsdemo
1: Binary
2: Source
Choose Upload Type [Binary]: 1

Would you like to deploy from the current directory? [Yn]: n
Binary Deployment Path: /home/ubuntu/workspace/App42PasS/sample_app/App42PaaS-Rails-Sample
Please be patient... This process may take a while to complete.
Deploying Application... OK

Operation is in progress, Please wait...|
App deployed successfully.

Deploy Source

$ app42 deploy
Enter App Name: railsdemo
1: Binary
2: Source
Choose Upload Type [Binary]: 2

Enter Git URL?: https://github.com/shephertz/App42PaaS-Rails-Sample.git
Deploying Application... OK

Operation is in progress, Please wait...|
App deployed successfully.
Get application details

You can see the details of your setup environment either from AppHQ – App42 PaaS Management Console or Command Line Client using app42 appInfo.

$ app42 appInfo
Enter App Name: railsdemo
+-------------------------------------+------------+------------------+-------------+------------+----------------+--------+
|                                              === railsdemo Info ===                                              |
+-------------------------------------+------------+------------------+-------------+------------+----------------+--------+
| App Url                             | App Status | Iaas Provider    | Name        | Runtime    | Instance Count | Memory |
+-------------------------------------+------------+------------------+-------------+------------+----------------+--------+
| https://railsdemo.iab.app42paas.com | RUNNING    | Amazon (Oregon)  | railsdemo   | Ruby 2.0.0 | 1              | 512 MB |
+-------------------------------------+------------+------------------+-------------+------------+----------------+--------+
Visit Your Application

You’ve deployed your application to App42 PaaS. Now you can open your application in your favorite browser.