Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep log of capistrano deployments

Is there a way to keep a log (either local or stored on a remote server) of every time a deployment is done via capistrano? It would be very useful to keep a record of what revision was running at any given time in the past.

I know that the deployment process leaves behind the deployed files for the last 10 deployments in the releases directory, but it would be nice to keep more history and have it accessible in the form of a flat file.

like image 736
readonly Avatar asked Aug 03 '09 21:08

readonly


2 Answers

capistrano sets a few helpful variables, one called latest_revision that you can dump out to a file.

task :mark_revision do
  log = "#{deploy_to}/revisions.log"
  run "(test -e #{log} || touch #{log} && chmod 666 #{log}) && " +
  "echo #{latest_revision} >> #{log};"
end
like image 68
Michael Sepcot Avatar answered Nov 09 '22 23:11

Michael Sepcot


There's no functionality built in, so the other answer would work perfectly; I might say that you should attach it to the default execution chain somehow, I would recommend something like

after :deploy, :mark_revision

of better still imho would be something like:

after :deploy do
    log = "#{deploy_to}/revisions.log"
    run "(test -e #{log} || touch #{log} && chmod 666 #{log}) && " +
    "echo #{latest_revision} >> #{log};"
end

I've opened it as a ticket for discussion on Capistrano's bug tracker, maybe we'll implement something in the core to keep better logs; it's certainly a great question we've harshly overlooked!

Peritor Labs'"Webistrano"does something similar, by keeping a database driven web-front end, this allows you to log whatever you like, and move the dependency for deployment off the developer machines to somewhere more central; often people use Webistrano on their CI server, or repository host if they are self-hosting. More info on their Trac: http://labs.peritor.com/webistrano

The bug resides here: https://capistrano.lighthouseapp.com/projects/8716-capistrano/tickets/98-log-deployments

like image 29
Lee Hambley Avatar answered Nov 09 '22 22:11

Lee Hambley