Read more

How to make sure that manual deploy tasks (scheduled in Pivotal Tracker) are executed on deploy (with Capistrano)

Dominik Schöler
October 12, 2023Software engineer at makandra GmbH

We regularly have tasks that need to be performed around a deploy. Be it to notify operations about changed application behavior, be it to run a little oneline script after the deploy. Most database-related stuff can be handled by migrations, but every once in a while, we have tasks that are much easier to be performed manually.

Writing deploy tasks

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

Here is how we manage the deploy tasks themselves:

  • Deploy tasks are written inside the Pivotal Tracker story description, clearly marked (e.g. with a headline "Deploy task")
  • We distinguish "before" and "after" as well as "staging" and "production deploy tasks
  • Stories with pending deploy tasks get a label, describing when the deploy task has to be performed, e.g. "before staging deploy" or "after production deploy"

Now, before and after each deploy, the developer can filter by the respective label and see if there are any tasks to be performed. But what if this could be automated?

Automatically checking deploy tasks

  1. Make sure Geordi Show archive.org snapshot is installed (locally, don't put it into your Gemfile).
  2. Run geordi commit in order to set up API access for Pivotal Tracker.
  3. Put the tracker_api Gem into your Gemfile.
  4. Store the attached pivotal_tracker_client.rb in app/util/. Note that it filters stories by their state. You may want to modify this.
  5. Store the attached deploy.rake in lib/capistrano/tasks/, or merge the tasks with an existing deploy.rake file in that location.
  6. Hook up the Rake tasks in Capfile:
    before 'deploy:starting', 'deploy:before_deploy_tasks' # Before Slackistrano, if you're using it
    after 'deploy:finished', 'deploy:after_deploy_tasks' # Keep this last
    
  7. Deploy with bundle exec.

Now, when deploying, Capistrano will first check if there are any pending before deploy tasks. If so, it will print them and wait until you're ready to continue. After the deploy, it will check for after deploy tasks, and tell you if there are any.

Posted by Dominik Schöler to makandra dev (2023-10-12 12:17)