How to handle branches mirroring environments

A workflow our team has really enjoyed has been to have our branches mirror what is deployed to our environments.

  • master -> production/sandbox
  • staging -> staging

Are there any other teams using this kind of approach and how are you handling container tagging and CI/CD?

So far we’ve solved this by tagging our images like staging.nginx.[COMMIT_HASH] and using a DockerHub webhook to hit a service to trigger a deploy. We really don’t like how this rebuilds containers for each environment when the commit hash could’ve just changed and are considering building a service that CI communicates with after the containers have been pushed to DockerHub. We don’t want to re-invent the wheel.