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.
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!
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 🙂
Thanks guys for these nice alternatives!
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 🙂
Bastian, that”s a good idea! Even simpler for passenger users
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?
Josh, agreed. restart.txt is a bit less reliable than a custom dummy file for the reason you mention.