Rails: Showing the latest deploy date in web app

1.1k Views Asked by At

I'd like to show in our app when the latest production deploy was made, as a means of showing an ongoing commitment to improvement, etc, etc.

Off the top of my head I'm thinking of getting a last_updated_at from one of the files, but I'd like to hear other thoughts.

What's the best way to get the date of the latest production deploy dynamically?


Thanks,

Josh

2

There are 2 best solutions below

2
On BEST ANSWER

Thanks to mpd who pointed me on the right direction.

For those interested in doing something similar, this is a quick and dirty method that probably can be refined and refactored.

In app/controllers/application_controller.rb put this method in the private section:

private 

def app_last_updated_at
  if File.exist?(RAILS_ROOT + "/REVISION")
    timezone = "Mountain Time (US & Canada)"
    @app_last_updated_at = File.atime(RAILS_ROOT + "/REVISION").in_time_zone( timezone )
  else 
    @app_last_updated_at = "Not Long Ago."
  end
end

Obviously, replace the timezone with your own (or you can do something fancy for individual user timezones).

In order to have this run all the time I use a :before_filter and put it at the top of your application_controller.rb.

before_filter :app_last_updated_at

And then to actually show this last updated at date, you just throw this or something like it in a layout or a partial or whatever:

<%= 
unless @app_last_updated_at.nil? 
  if @app_last_updated_at.is_a? Time 
@app_last_updated_at.to_s(:long)
  else
@app_last_updated_at 
  end
end
%>

Hopefully, this helps others. I'm not keen on having it run in the ApplicationController for every access, so suggestions would be appreciated.

2
On

You can do it pretty easily with Capistrano. Take a look at this link I think it does exactly what you want Deployment date