Tutorial

An insight into the configuration of Capistrano #1

Published on July 18, 2012
An insight into the configuration of Capistrano #1

Prior to starting this article, you should have already configured most of Ruby on Rails with Capistrano. At this point, we need to check the configuration file for Capistrano and add up the required things.

Quick details

In this article, we will be explaining what each configuration setting is and what it is meant for. Although the article is long, every step is explained in details, so that you can carry out all the configurations successfully.

Deploy.rb

First of all, we will move to the Ruby on Rails app folder located on the local workstation.

 cd ~/dev/MyTestProject1

Open the deploy.rb file

 nano config/deploy.rb

The file should look like this:

set :application, "set your application name here"
set :repository,  "set your repository location here"
# If you aren't deploying to /u/apps/#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
# set :deploy_to, "/var/www/#{application}"
# If you aren't using Subversion to manage your source code, specify
# your SCM below:
# set :scm, :subversion
role :app, "your app-server here"
role :web, "your web-server here"
role :db,  "your db-server here", :primary => true

Setting up the variables for ‘application’, ‘username’ and ‘repository’

Working systematically, we will start at the top and work our way down to the end of the file. The first variable in the file is ‘application’. You can use any app name but it’s better to use the name of your domain. This will keep it in accordance with the protocols we used for vhost etc.

Write in the following line for the app name

set :application, "domain.com"

Now we are going to setup the username. This will forestall any permissions issues that could occur from using the local workstation username instead of droplet username.

Add this line

set :user, "username"

For repository, we enter the details we used to checkout our project ‘MyTestProject1’

set :repository,  "svn+MyTestProject1ssh://12.34.56.789/home/username/repository/MyTestProject1"

Setting up SSH port

The SSH port is not setup by default. Capistrano uses the default ssh port, 22, for connecting to the droplet via SSH. Therefore, we need to let Capistrano know that we defined our SSH port as ‘22’ while setting up the droplet.

The following line defines the SSH port.

 set :port, 22

Setting up the deployment path

Next, we will set up the deployment path. While setting up droplet and vhosts, we used ‘public_html’ folder.

The deployment path should be written as follows:

set :deploy_to, "/home/username/public_html/#{application}"

Note that the variable ‘application’ is used at the end. If we change ‘set :application’ from domain.com to something else then this setting will also reflect that change.

Setting the variables for ‘app’, ‘web’ and ‘db’

App, web and db are the last three settings that need to be set up at this stage. Many users point these three variables to the same place; which may make things a bit confusing. However, it is also possible to have your app, web and db pointing to different locations. In such a case, this setting will let Capistrano know the location of each variable.

We can define a new variable ‘location’. The three settings will point to the URL assigned to this variable.

set :location, "domain2.com"
role :app, location
role :web, location
role :db,  location, :primary => true

On the other hand, if everything is taking place on the single droplet, we can just use the application variable.

The settings would then look like this:

role :app, application
role :web, application
role :db, application , :primary => true

Final deploy.rb file

So our final file should include the information below:

set :application, "domain.com"
set : user, "username"
set :repository,  "svn+MyTestProject1ssh://12.34.56.789/home/username/repository/MyTestProject1"
# If you aren't deploying to /u/apps/#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
# set :deploy_to, "/var/www/#{application}"

set :port, 30000

set :deploy_to, "/home/username/public_html/#{application}"

# If you aren't using Subversion to manage your source code, specify
# your SCM below:
# set :scm, :subversion

role :app, application
role :web, application
role :db, application , :primary => true

Although the file’s contents seem simple, they will be helpful when it comes time to enter our very first Capistrano command...

Public_html

Now, we will log in to the droplet and move to the public_html folder.

ssh -p 22 username@123.45.67.890

cd /home/username/public_html

If you don’t have a working droplet, then the droplet will be empty. Since the directory is empty, there will not be any output.

ls

Now we will enter our first Capistrano command.

Running the command deploy:setup

Enter this command on the local workstation

 cap deploy:setup

It may seem like a simple phrase but a lot will happen. To see what has happened, we will look into the public_html folder on our droplet.

ls
...
domain.com

Directory Structure

Capistrano has worked wonders. See the power and ease of using Capistrano. It logged in to the droplet, fetched the settings from deploy.rb and created the directory structure that we will be using for our future development. Within the parent folder, you can see two more folders named ‘releases’ and ‘shared’. The ‘shared’ folder contains subfolders for system info, logs and pids etc.

By Etel Sverdlov

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
Leave a comment


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel