Manage hotfixes in Heroku pipeline

844 Views Asked by At

I have a simple Heroku deployment pipeline (review apps -> development -> staging -> production). If I push something to master then it will trigger the CI (codeship) and if the tests ran successfully the Codeship will deploy the changes to development Heroku app. It's pretty simple.

But how can we manage the hotfixes? What happen if we cannot deploy the current master to production for any reason.

I've just read an article which says that we should handle hotfixes with git tags. Is it the only way to manage hotfixes? Can we handle these without using git tags?

3

There are 3 best solutions below

2
On BEST ANSWER

master is your deployment branch. So hotfixes are done in master branch as well.

I assume you also have a development branch. So if you have ongoing work, you continue to do it on the development branch and not merge it to master.

If master is broken - you must fix it (hence the hotfix). You fix the issue, push it to master, and continue with the deployment cycle.

Then you should also cherry pick the hotfix back to your development branch.

Update

If you wish to stick with a single master branch than I cannot see a workaround working with hotfix branches.

You don't necessary need to tag one each time. But the key is to know which version is the last stable version currently in production slot.

Developers continue to work on master - it goes to staging but you asses that it cannot proceed to master.

So you:

  • create a new branch, based on the current version - this is the hotfix branch.
  • Create the fix
  • Deploy it
  • Merge it to master
2
On

For anyone who was still confused about this, Heroku Pipelines lets you deploy your Production app from any branch:

Choose a branch to deploy

You can publish a hotfix by manually creating a branch from the code that's currently deployed to your Production app and cherry-picking the fixes you need.

0
On

Before all, we need preparate the remote:

git remote -v
# should contain the production remote with whatever name (better producation for sure), for example:
#
# production    https://git.heroku.com/your-repo-prod.git (fetch)
# production    https://git.heroku.com/your-repo-prod.git (push)
# staging   https://git.heroku.com/your-repo-staging.git (fetch)
# staging   https://git.heroku.com/your-repo-staging.git (push)

# if not, use this to add:
git remote add production https://git.heroku.com/your-repo.git

Then: you need up-to-date the remote branches:

git fetch production

Then: Need to create the new branch based on production Heroku-branch:

git checkout -b hotfix/TICKET -t production/master

# where 'hotfix/TICKET' is your preferred branch name

Then you need to apply the hotfix changes, for example:

1) manually:

# -> do something with codebase
git add .
git commit -m "hotfix: bla..."

2) by cherry-pick specific commit:

git cherry-pick COMMIT_HASH

# or use this, if you need to cherry-pick the 'merge-commit':
git cherry-pick -m 1 MERGE_HASH

now you need to push changes:

git push production hotfix/TICKET:master
# where 'hotfix/TICKET' is your preferred branch name

That's it. :tada: