Deploying Rails application on AWS, using Nginx, Puma and Mina

Bookmark and Share

In this tutorial we are going to setup an AWS EC2 instance for deployment of rails application.

Server Setup

Following is the setup instruction for ubuntu 16.04 using ruby 2.4, Postgres 9.6 and rails 5.

Installing Ruby

Setting up dependencies for ruby.

Next step is to install ruby using RVM.

Last step is to install bundler.

Installing Rails

Installing NodeJS, this lets you use Coffee script and the Asset Pipeline in Rails which combines and minifies your javascript to provide a faster production environment.

Next is to install rails.

You can verify the installation of rails version.

Installing PostgreSQL

The postgres installation doesn’t setup a user for you, so you’ll need to follow these steps to create a user with permission to create databases.

Install Nginx

Following are some basic commands to manage Nginx:

Nginx Configuration

First disable default site by removing the symlink.

Now create a new virtual host config file.

edit the my_app.conf file:

Puma Configuration

Change config/puma.config file according to following example:

Create puma upstart script

Let’s create an Upstart init script so we can easily start and stop Puma.

Now open the provided puma.conf file, so we can configure the Puma deployment user.

Look for the two lines that specify setuid and setgid, and replace “apps” with the name of your deployment user and …

Read More

[Tip] Mina: Find last git commit released

Bookmark and Share

A project that we were handling hadn’t had a deployment in some time. So we were confused on what all commits were going to go to production ( bad karma for us for not keeping a release or change log). We use mina for all our deployment as we found it to be faster that Capistrano. So we were sure that there would be something on our server to help us settle this dilemma. We finally solved this by going through the various folders and files.

Edit the file inside the file with your branch name located at /path/to/project/scm/refs/heads. Like for example if you have your project in /var/www folder and you are deploying master then you should edit the file called master found at the following location./var/www/project/scm/refs/heads/master that file would have only one line and that’s the last git commit released.


Read More

Taking screenshots of webpages using Ruby

Bookmark and Share

Recently we have been working on taking screenshots for web page while generating reports based on that website. During this endeavor, we came across some tools to achieve that. We are sharing the information we gathered here.

The tools that we will discuss for screencapture, in  Ruby,  are:

  • PhantomJS
  • Screencap gem
  • Webshot gem

Screencap and webshot are gems in Ruby that depends on a tool called PhantomJS. It is basically a web browser without a user interface, primarily used for testing websites. Such type of browsers are generally referred to as headless browsers,

Screenshots with PhantomJS

PhantomJS is quite easy to install and is multiplatform, available on major operating systems.

To start, our script must require a reference to the webpage module then use it to create an instance:

Use the method and pass it the arguments, the url of the webpage that we want to capture screenshot.

instance.render() method captures the screenshot and saves it to the file specified in the argument.
Run the script as,

Screenshot is saved in the  directory where we run the script.

Now what we have above is all JavaScript, but to use the phantom JS in our rails application we have gems that provide us with an easy interface to acheive the …

Read More