Mar 19, 2010 @ 10:49 am

When you are developing an app or a website for your client, it is pretty common to setup a sandbox environment where your client can test and see the application while it is still in development. One thing I find useful is to display the last deployment date on the home page.

Here is a quick and easy way to automate the process :

Step #1 (we can have lots of fun)
I will consider that you use capistrano for deploying your app. The only thing you have to do in your capistrano recipe is to “touch” a dummy file to update its modification date.

namespace :deploy do
  desc 'Restart My App'
  task :restart, :roles => :app do
    run "touch #{current_path}/last_deploy"
  end
end

Step #2 (there’s so much we can do)
Now in application_controller, add a before_filter like this

before_filter :last_deploy

def last_deploy
  @last_deploy = File.new("last_deploy").atime rescue Time.now
end

Step #3 (it’s just you and me)
Display the date in the layout or in the view of your choice

<%= "Last deployment : #{@last_deploy}"%>

Edit : Oh, dear readers, I just want to let you know that RubyFleebie is now on Twitter.

Bookmark this post : These icons link to social bookmarking sites where readers can share and discover new web pages.
  • DZone
  • Reddit
  • del.icio.us
  • Digg
  • Furl
  • Technorati
  • StumbleUpon
Posted under : short & sweet
8 Comments

I think you could also use the REVISION file that capistrano places by default during a deploy. You could also get the SVN/git revision from this file by reading it.

Thanks for the tip!

Comment by : Ian NeubertNo Gravatar
— March 19, 2010 @ 11:49 am

You could also pull the timestamp from the most recent folder within the releases directory, as Capistrano uses timestamped folder names as a way of separating revisions of code over different deploys. Nice idea :)

Comment by : Josh NesbittNo Gravatar
— March 19, 2010 @ 12:29 pm

Thanks guys for these nice alternatives!

Comment by : FrankNo Gravatar
— March 19, 2010 @ 1:26 pm

[...] while it is still in development. One thing I find useful is to display the last deployment… [full post] Frank Ruby Fleebie short & sweet 0 0 0 0 0 [...]

— December 10, 2010 @ 1:46 am

When using passenger, why not check for the last change on tmp/restart.tmp?

File.atime(“#{Rails.root}/tmp/restart.txt”).strftime(“%Y-%m-%d at %H:%M”)

will work with just this single line :)

Comment by : Bastian KruckNo Gravatar
— March 27, 2011 @ 9:37 pm

Bastian, that’’s a good idea! Even simpler for passenger users

Comment by : FrankNo Gravatar
— March 28, 2011 @ 8:03 am

I’m not sure the last access time would suffice. What if you you needed to restart the application but haven’t deployed new code in-between restarts?

Comment by : Josh NesbittNo Gravatar
— March 28, 2011 @ 8:12 am

Josh, agreed. restart.txt is a bit less reliable than a custom dummy file for the reason you mention.

Comment by : FrankNo Gravatar
— March 28, 2011 @ 8:16 am




Leave a comment
Name (required)
Email (will not be publish) (required)
Website