Servage Magazine

Information about YOUR hosting company – where we give you a clear picture of what we think and do!

Application deployment with Capistrano

Thursday, October 27th, 2016 by Servage

capistranoHave you ever found yourself doing the same tasks to deploy an application again and again? Perhaps some of those repetitive tasks could be automated? Fortunately, there are free and open-source solutions available! One of the most recognized automated deployment tools is called Capistrano.

What is Capistrano?

Capistrano is a tool written in Ruby that allows you to automate application deployment to a Linux server using by executing commands over SSH. It is possible to automate the whole deployment process from start to end using Capistrano.

What is required?

Since Capistrano and also its configuration files are written in Ruby, some Ruby knowledge is required to create a deployment configuration. However, Capistrano aims to make writing deployments as simple as possible, making it easy even for those who have never used Ruby before. On a technical level, Capistrano requires the above-mentioned Linux server and Ruby installed on it.

How does it work?

Before you can deploy anything, you must tell Capistrano how to deploy. This is often done using at least two files: deploy.rb and production.rb. deploy.rb is the main configuration file for deployment behavior. This is the file where specify what to do, such as install dependencies using Composer, download the latest source code from GitHub and clear application cache after a successful deployment.

The second file, production.rb is used to tell Capistrano where to deploy to. It contains the hostname, login credentials, SSH keys and other information required to access your server. If you have more than one environment, for example a staging server, you may have another file called staging.rb that looks almost identical to this file. Usually the only difference is the hostname.

When you have configured Capistrano, you are ready to deploy your application. All you have to do is run the following command: “cap production deploy”. This will deploy a new version of your application to the server you specified in production.rb.

Common Capistrano tasks

You may be wondering what to write in the configuration files. Here are a few common tasks you may want to do, but for more complete instructions, refer to the official Capistrano documentation.

Install dependencies: “composer install” is run automatically by Capistrano. This means you don’t have to manually run this step or configure it in any files.

Deployment method: This tells Capistrano how to get the latest source code, for example by using Git or local file storage. Example: set :scm, :git

Git repository URL: This is the URL from which Capistrano will download the latest source code. Example: set :repo_url, ‘https://github.com/your/repository.git’

Git branch: This is the branch to use from the repository. Example: set :branch, ‘master’

Console commands: To run custom console commands before or after deployment, use the execute function. Example: execute :php, ‘app/console cache:clear

This should get you started with Capistrano. For advanced instructions, head to the Capistrano documentation.

Application deployment with Capistrano, 5.0 out of 5 based on 4 ratings
Categories: Software & Webapps

Keywords:

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

No comments yet (leave a comment)

You are welcome to initiate a conversation about this blog entry.

Leave a comment

You must be logged in to post a comment.