PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, September 28, 2022

[FIXED] How can I display a 'last-deployed' timestamp from within my Heroku Rails app?

 September 28, 2022     continuous-deployment, git, heroku, ruby-on-rails     No comments   

Issue

I'd like to update an environment variable or something to track the time of the deploy that is currently active. Is there any way to do this automatically from within my app on Heroku, or do I have to do it as part of a deploy script? Ideally, I'd like something that would work with me using TDDium for CI, and letting them do the push to Heroku for me when the build passes.


Solution

1. There is no automatic method when deploying to Heroku unless you make a deploy script/task. (I searched for this too in June 2012). I have a rake task that does a deploy, part of it sets GIT_TAG and my web page (application layout in rails) prints that to the page.

Heres how I write to the Heroku GIT_TAG config var (using a Rails-based Rake task):

    tag = `git describe master --always`.strip
    `heroku config:add GIT_TAG=#{tag} --app XXXX` 

2. With tddium: tddium now supports a "post build hook" and I augment their standard version to set the GIT_TAG during that process. read and follow http://blog.tddium.com/2012/05/09/heroku-continuous-deployment/ first and to the "post_build_hook" task add something to read the tag and set the heroku config var as demonstrated:

    namespace :tddium do
      def cmd(c)
        system c
      end

      desc "post_build_hook to deploy to dfc-site-qa"
      task :post_build_hook do
        ...use code verbatim from above URL (https://www.tddium.com/support/reference#customization)
        ...
        current_tag = `git describe master --always`.strip
        cmd "heroku config:add GIT_TAG=#{current_tag} --app XXXX" or puts "could not set GIT_TAG to #{current_tag}"
        ...
      end

Notes:

  1. Substitute for 'master' in the above as needed. In my deploy rake tasks (happy to share) I allow deploying based on a branch or a tag (handy to bypass heroku's desire to only deploy from master).

  2. To have tddium run your "post_build_hook" you must de-activate the post-deploy URL by running this: tddium suite --edit

    and use your current value for the "pull url" but set the "push url" to blank (or default). This step was not mentioned on the blog link.

  3. In your tddium web page for the current build you will now see a link to the post_deploy_hook logfile (at very bottom of page) that you can open and see how it went (aka debug your rake task).



Answered By - Mike P.
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing