Tracking Deployments

Last updated by Adam West on June 07, 2016 10:28

Codebase allows you to track deployments by sending a request to the application whenever you deploy your application. This will be stored within the repository object and displayed in the activity feed along with a link to view the changes which were performed (in some SCMs).

The easiest way to track deployments is to use the Codebase4 gem which provides a simple to use method allowing you to the send the deployment to the application with the minimum of fuss and overhead within your deployment scripts.

Installing & Configuring the Gem

To begin, you need to install the gem on your local system. You can also use bundler if you prefer and add gem 'codebase4' to your Gemfile.

[sudo] gem install codebase4

Once you have installed the gem you should configure it by adding your user's access token for your account. The token can be found on the 'Deploys' page for any repository. This token is unique to your user for the account you are currently logged in to.

cb token mydomain.codebasehq.com d8uh3sdufh7gh3

Obviously, replace mydomain.codebasehq.com with your Codebase domain and d8uh3sdufh7gh3 with the token you get from the interface.

You can check that your token has been added correctly by running the command:

 cb test mydomain.codebasehq.com

Logging a deployment

To log a deployment you will need to build a simple cb deploy command following the instructions below:

cb deploy [old revision ref] [new revision ref]

For example, you should enter the revision your deployment started from (i.e. the last revision which was deployed) and the revision you are currently deploying from.

In addition to this, you also need to pass various other switches to this method.

  • -s app1.mysite.com,app2.mysite.com - this contains a comma separated list of servers which this deployment is being sent to.
  • -e production - this is the environment which is being deployed (optional)
  • -b master - this is the branch which is being deployed (optional)
  • -r project:repo - this is the name of the repository which is written as project permalink followed by the repository permalink separated by a colon. You can find this from the address bar when browsing a repository for example the path /projects/awesomeproject/repositories/myrepo** has the project permalink 'awesomeproject' and the repository permalink 'myrepo' which is written as awesomeproject:myrepo.
  • -h mydomain.codebasehq.com - this is the domain for the account which contains the repository.
  • --protocol https - by default requests will be sent using HTTP, if you wish to send them using HTTPS, you can send this (optional).

Once you have put all this together you should get a command which looks like this:

cb deploy 531eca5 9de177c -s app1.mydomain.com,app2.mydomain.com 
-e production -b master 
-h mydomain.codebasehq.com 
-r awesomeproject:myrepo 
--protocol https

Automatically logging deployments with Capistrano

The Codebase 4 gem comes with a recipe that you can include in your Capistrano deployment script to automatically log your deployments to Codebase. To include the recipe in your Capfile simply add the line:

require 'codebase/recipes'

The next time you run cap deploy you should see output similar to the following during the deployment:

running: cb deploy fc10b3aa5a9e39ac326489805bba5c577f04db85 840daf31f4f87cb5cafd295ef75de989095f415b 
-s localhost -b master -r test-repositories:git1 -h test.codebasehq.com --protocol https 
Sending deployment information to test.codebasehq.com (project: 'test-repositories' repo: 'git1')   
Commits......: fc10b3aa5a9e39ac326489805bba5c577f04db85 ... 840daf31f4f87cb5cafd295ef75de989095f415b
Environment..: -   Branch.......: master   Server(s)....: localhost   Token........: lJ7KvCW****** 
Deployment added successfully