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.
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.
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
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"
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
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.
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
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...
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.
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
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.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
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!