Post-deployment configuration in Ruby / Rails applications with Jelastic
This article was originally posted by Kemel Zaidan who is an active member of the Brazilian free software community and a supporter of causes related to digital inclusion and free knowledge. In the professional field, he has coordinated education and inclusion projects in third sector entities and was editor in chief of Linux Magazine and iMasters magazine, having lectured in various technology field events. In recent years, he has been dedicated to researching the world of digital culture and its developments. He is also an evangelist for our hosting partner in Brazil, Locaweb.
Below is the translated version of Kemel’s article.
Recently I helped Comrade Fabio Akita to put a Rails application in Jelastic. In the review, although positive, a detail caught my eye that had gone unnoticed: deployment pipeline.
Despite the difficult name, it is nothing more than the tasks that must be performed in a Ruby / Rails application after it is deployed to a server. In an IaaS (Infrastructure as a Service), you would have to do this manually, or through some deploy software / automation, like Capistrano.
Although Jelastic allows making use of this tool as it allows SSH access to your cloud environment and entering it by hand, it is not what we want; otherwise, we would not be using cloud. In addition, Jelastic is a PaaS, and the advantage of using such a service is just to reduce the need for system administration, since it automates many of the tasks essential to maintain a complex infrastructure in the cloud without having to type commands manually as bundle install and rake db: migrate every time you make a new deployment.
For the dependency management, everything is very simple, and Jelastic follows the pattern of language (not just in Ruby, but in other languages available): If the project has a Gemfile file in the root folder, it will automatically resolve dependencies with Bundler after deployment to the server without you having to perform any manual intervention. Rest assured that even if you perform some changes to the file later, Jelastic recognizes the changes and install the missing dependencies in the project.
It is very common that Rails projects need to perform some action after the application is deployed, how to create databases on the database of production and other similar tasks.
In order not to waste time performing these repetitive actions every time we need to put a system into production, it is easier to automate this type of task. For this, the platform allows you to run the rake command through a file rake_deploy to the root folder of the project.
The file should contain a list of commands that will be passed to rake for running consecutively. Each command should be on a separate line. Jelastic will run these commands in the file rake_deploy after each restart of the Apache / Nginx / Raptor and delete the file after a successful execution.
So if you need to perform different commands after each deployment, you have to create different files at a time and place commands to correct it. The output of commands can be viewed via the “Logs” of Jelastic.
The syntax of the file rake_deploy is as follows:
And Jelastic executes the following script:
A valid example would be:
Note: To vendorize gems, you need to add this parameter to the file rake_deploy : gems: unpack
Thanks Kemel for clarifying this! If you would like to test Ruby on Jelastic cloud, simply signup for a 2-week-free-trial and share your experience in the comments below.