Using Codebase to track your deployments
In Codebase, you can track deployments by sending a request to the application whenever your deploy your code. This is stored within the repository object, and displayed in your activity feed along with a link to view changes which occurred (in some SCMs).
We have a Codebase4 gem, which provides a simple to use method allowing you to send the deployment to the application with the minimum of fuss and overhead within your deployment scripts.
Installing and Configuring the Gem
Firstly we need to install the gem onto our local system. You can use bundler and add gem 'codebase4' to your Gemfile, but in this example we will install it via the terminal:
$ [sudo] gem install codebase4
Next, we need to configure it by adding our user access token from our account, found under the Deployments page within our Repository:
$ cb token mydomain.codebasehq.com d8uh3sdufh7gh3
Replacing the mydomain and token with what is display in the Deployments page.
We can now check that the token was successfully added with the following command:
$ cb test mydomain.codebasehq.com
Logging a Deployment
We just need to enter the following command into our terminal:
$ cb deploy [old revision ref] [new revision ref]
Where old revision ref is the previous revision we deployed, and new revision ref is the one we are now deploying.
In addition to this, you also need to pass various other switches to this method, listed below.
Additional Switches
Firstly, a comma separated list of servers which this deployment is being sent to:
-s app1.mysite.com,app2.mysite.com
The environment which is being deployed (optional):
-e production
The branch which is being deployed (optional):
-b master
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
:
-r project:repo
The domain for the account which contains the repository:
-h mydomain.codebasehq.com
By default requests will be sent using HTTP, if you wish to send them using HTTPS, you can send this (optional):
--protocol https
The Final Command
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
Summary
In this post we've covered logging deployments in Codebase from any 3rd party service as well as Capistrano specifically. We hope you've found it useful, let us know as always if you have any questions.