Latest Updates: capistrano RSS

  • Articles

    Switched to Python Fabric

    Stii 11:18 am on March 4, 2009 | Comments: 13 Permalink | Reply
    Tags: , capistrano, deployment, , ,

    We’ve been using Capistrano to deploy Afrigator to our various servers for a while now. I can seriously not complain or say anything bad about Capistrano. Thing is, I’m more familiar with Python than I am with Ruby, thus for me it just makes more sense for me to use Fabric.

    Here is a small example of how to write a typical deploy script with Python Fabric:

    First, define your various servers which you need to deploy to. Ideally, you’ll have a test, staging and live server. Thus you’ll set them up as follows.

    def test():
        config.fab_user = 'test_user_name'
        config.fab_hosts = ['test.yourserver.com']
    
    def staging():
        config.fab_user = 'staging_user_name'
        config.fab_hosts = ['staging.yourserver.com']
    
    def live():
        config.fab_user = 'live_user_name'
        config.fab_hosts = ['www1.yourserver.com', \
    'www2.yourserver.com', 'www3.yourserver.com']
    

    This allows you to deploy your code to the various servers. Please note, you need to setup automatic login for your different servers. See here how to do automatic logins.

    Next, write the steps you would take to deploy your site manually:

    def deploy():
        "Deploy code to servers"
        msg = "deploying"
        require('fab_hosts', provided_by = [test,staging,live])
        local('svn ci -m "$(msg)"')
        run('svn export repos /path/to/repository/export/')
        run('cp -R /path/to/repository/export/* /path/to/your/site/')
    

    To deploy to the staging server you can run the following command:

    $ fab staging let:msg="Reason for check in" deploy
    

    To deploy to the 3 live servers, all you do is:

    $ fab live let:msg="Reason for check in" deploy
    

    The command works as follows: fab is the command. live/stating/test are the environments you would like to load. If you said staging, it will do the commands in deploy for the staging server. The last part is the command you want to run. In this instance, deploy.

    The let:msg=”Reason for check in” is the coolest bit! It basically allow you to override Fabric variables. If you look closely, in my deploy script I’ve set a variable msg to just say “deploy”. Now that is a stupid SVN message for a commit. In order to commit with meaningful messages, I override the msg variable with my own message. Simple, yet very effective!

    You may want to write a number of different functions in a single fabfile. If you have 100 commands and you’re not one hundred percent sure, just do a:

    $ fab list
    

    and all the commands available to you will be printed with their description. Fabric rocks! Seriously.

    Welcome back! You should subscribe to my RSS feed here.
    You should follow me on Twitter here
    You should follow me on Gatorpeeps here.

    Save Cape Town City Ballet
     
  • Articles

    FTP is crap! So they say in Cape Town

    Stii 8:00 am on December 15, 2008 | Comments: 0 Permalink | Reply
    Tags: capistrano, , ftp, , ,

    FTP is crap. At least someone in Cape Town seems to think so! Found this little gem in a shopping centre in Cape Town.

    ftp

    In all fairness, its not that I believe it is crap, its just that there is so much better ways to update sites. My preference at the moment is:

    I do understand that if you host sites on a shared host you don’t always have these options and in lots of instances FTP is the only option available to you. I feel your pain :(

    Save Cape Town City Ballet
     
  • Articles

    Fabric, Capistrano in Python

    Stii 4:27 pm on November 24, 2008 | Comments: 1 Permalink | Reply
    Tags: capistrano, , ,

    FabricIf you still use FTP or SCP or sFTP to deploy projects, you’re missing out big time on the ease of either Ruby’s Capistrano or Python’s Fabric. Capistrano is almost synonymous with Ruby on Rails, though it is simple to setup with any project. We at Afrigator uses Capistrano to deploy changes to the staging server and to the live servers. It is specially handy if you have to deploy to a cluster of servers. In short, it allows you to execute commands on a remote server(s). For example, you can set it up so that it backs up your files before the deployment or do something and simple and trivial as a directory listing.

    Capistrano

    Today I came across Fabric, which is a Python version of Capistrano. Now, for the record, my use of Capistrano has been limited. I use it for what I need it. Nothing more. What I’m trying to say is I didn’t go into a very advanced setup of Capistrano, so I’m not really qualified to say which is better. On the Fabric page it says:

    It is a bit like a dumbed down Capistrano, except it’s in Python

    I like it. Its simple and it is easier than Capistrano IMHO. In the end, it comes down to which tool suits you best! Capistrano does support commits and rollbacks which, by the looks of it, Fabric don’t.

    Setting up Capistrano was painless. All I had to do was

    sudo gem install capistrano
    

    Fabric had a few dependency issues, which I had to meet first before I could

    sudo easy_install Fabric
    

    It was looking for pycrypto which I had to install before I could setup Fabric.

    Once installed, using it is as straight forward as Capistrano. All you need to do is to create a fabfile which is a simple python file which holds all the config options and commands to execute remotely. The syntax is plain and simple and clean. Here is a simple example executing a directory listing on a remote server:

    def listing():
        "Outputs a directory listing on the remote server."
        set(fab_user = 'stii')
        set(fab_hosts = ['stii.co.za'])
        run('ls -l /usr/bin')
    

    Simple. Apart from the run command to execute remote queries, there are also a sudo (execute remote commands as a privileged user), local (execute commands on your local machine) and put (upload files to the remote servers) which is very handy.

    I’m going to use it a bit more and would give you more feedback in a while. If you want, you can check it out!

    Update: Here is an example of how to upgrade WordPress using Python Fabric

    Save Cape Town City Ballet
     

About Me

Software developer at Afrigator.com Love Python, do PHP.
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
esc
cancel