Deploy with Capistrano

What is Capistrano?

Capistrano is a tool that uses SSH to connect to servers to perform a series of defined Rake tasks. The tool can be used for code deployment, restarting services or database migrations. It is mostly used in the deployment process to minimize the risk of errors and save time.

In this article, we will show you how to prepare a pipeline that will let you deploy to Capistrano.

Image loading...Example pipeline with Capistrano deploymentExample pipeline with Capistrano deployment

Tip
If you are using Buddy for the first time, check out our workflow guides that will tell you how to build and test your application before the deployment.

How does Capistrano work?

Capistrano works with any web server that supports SSH and has the required tools installed. It works by running Rake tasks that are executed on a remote server using SSH. Rake tasks are scripts written in Ruby used for task automation. Rake Tasks are added here:

default
└── lib └── capistrano └── tasks

Does Capistrano only work with Ruby on Rails?

Capistrano doesn't only work with Ruby on Rails, although it is often used in Rails projects. You can adjust it to work with various technologies like: Node.js, PHP, Java or Python. In our example, we're going to deploy a Ruby app.

What are Capistrano requirements?

To use Capistrano, you need:

  • a server that handles SSH connections
  • Ruby, with a proper Ruby version installed on the server
  • rbenv - a tool for managing Ruby versions
  • bundler - a tool for managing Ruby dependencies

Project structure

default
├── Capfile ├── config │ ├── deploy │ │ ├── production.rb │ │ └── staging.rb │ └── deploy.rb └── lib └── capistrano └── tasks

Each of these files serves a specific role:

  • Capfile - Capistrano configuration file
  • deploy.rb - global deployment configuration
  • production.rb or staging.rb - deployment environments configuration
  • tasks - folder for additional tasks

Configure pipeline in Buddy

  1. Create a new project in Buddy and select GitHub as the provider:

Image loading...Creating new projectCreating new project

  1. Add a new pipeline and configure the details: name, trigger mode, and a branch from which you want to deploy.

Image loading...Adding new pipelineAdding new pipeline

Configure Capistrano deployment script

  1. Since Capistrano is Ruby-based, look up and click Ruby on the action list to add it to the pipeline:

Image loading...Build actions in BuddyBuild actions in Buddy

  1. Install Bundler to your Gemfile and enter the script execution command for the server defined in your config file (e.g. production or staging):
bash
gem install bundler bundle install bundle exec cap staging deploy$$$

Image loading...Default build commands in BuddyDefault build commands in Buddy

Tip
You can add other commands to the build container before the deployment, for example rake test that will test your application before the upload.
  1. When ready, click Add this action to finish configuration.
Success
Congratulations! You have just automated your deployment with Capistrano. 🥳

Integrating Buddy with Capistrano lets you smoothly deploy your applications to servers, using the power of the Ruby tool and the SSH communication protocol. With Buddy's simple and intuitive interface, you can quickly prepare a deployment pipeline, saving time and minimizing the risk of errors. Such a pipeline enables fast execution of deployment scripts, automatic application testing, and effective management of your CI/CD process.

Last update:
Sep 24, 2024