— my toolbox is filled with perl, javascript, css and html

thorsen.pm

Continuous deployment with #Mojolicious and @github

Tuesday, August 13, 2013

After hearing Curtis Poe giving the talk “Agile Companies Go P.O.P.‎” at the YAPC I thought I should finally get the word out about my extension to Mojolicious, which allow continuous deployment using a github post-receive hook.

So… Mojolicious has this marvelous web server called hypnotoad. What makes this server so cool, is that it can do hot deployment1.This is indeed excellent feature for continuous deployment. In my projects2 I have also pure copywriters which wants to make changes to the templates, but has no idea how to ssh-into-ec2-then-restart-the-server-with-some-sudo-command. Even though we’re a small group, I wanted to give the opportunity to my partners in crime to restart the server by themselves instead of waiting for me. So therefor I decided to write Toadfarm and Toadfarm::Plugin::Reload.

The “Reload” plugin allow this workflow:

  1. The developer / copywriter edit files locally.
  2. Then they use github Mac to push the changes back to a special branch3.
  3. Github then POST a document to Toadfarm, using a post-receive hook.
  4. Toadfarm verifies that the request is from github.
  5. Toadfarm then reloads with the new source code if it is valid.

There might be a delay between pushing the code and a complete restart, but if everything goes OK, the new code should be up and running within 30 seconds.

What kind of configuration is required to make this work? Not much really:

Below you can see a sample config, which is essentially copy/paste from my server.

{
  secret => 'some-super-secret-session-hash',   # Mojolicious config
  hypnotoad => {                                # Hypnotoad config
    pid_file => '/var/run/toadfarm/pid',        # |
    listen => [ 'http://*:8080' ],              # |
  },
  apps => [                                     # Toadfarm config
    '/home/webapps/batware/script/batware' => { # |
      Host => 'home.thorsen.pm',                # |
    },
  ],
  plugins => [
    Reload => {                                 # Toadfarm::Plugin::Reload config
      path => '/something-secret-5',            # |
      repositories => [{                        # |
        name => 'jhthorsen.github.com',         # |
        branch => 'master',                     # |
        path => '/home/webapps/batware',        # |
      }],
    },
  ],
}

CAVEAT:

Want to try it out? It’s simple to install with cpanminus:

$ cpanm -n --sudo Toadfarm

See also examples on how to set it up.

Want to discuss or ask questions about Toadfarm? Comment below or contact batman @ irc.perl.org. (I’m usually in the #mojo channel)

a running application without causing any downtime or without restarting the server.

  1. Hot Deployment refers to the ability of making changes to

  2. Grumpify and Betsy.

  3. The config need to contain the branch name which you push to.

blog comments powered by Disqus