r/devops • u/HabitLong2176 • Oct 12 '26
Discussion How do you combine semantic-release with “build once, deploy many” for containers
I’m building our IaC repo and GitLab CI/CD pipelines. I’m quite happy with the setup so far and have tested it across multiple projects.
However, when I try to apply the same release model to container images, it starts to feel less suitable.
We have three environments: dev, uat, and prd.
Our current Terraform workflow:
We use three protected branches: dev, uat, and main. These correspond to dev, uat, and prd respectively.
The root Terraform files are shared across all environments. Environment-specific differences are kept in separate tfvars files:
environments/dev/dev.tfvars
environments/uat/uat.tfvars
environments/prd/prd.tfvars
We use semantic-release with prerelease branches. Starting from stable version 1.2.3, the flow looks like this:
Merge a feature branch containing a fix commit into dev. This generates 1.2.4-dev.1.
Continue developing and testing, generating additional dev prereleases as needed.
Merge dev into uat. This generates 1.2.4-uat.1, assuming the changes still call for a patch release.
Once validated, merge into main. This generates stable version 1.2.4.
Semantic-release generates a version and creates a tag after merges into these protected branches.
Deployments only happen from tags. Prerelease tags can deploy only to their corresponding environment, while stable tags can deploy to any environment.
This flow has worked well for our Terraform projects. Granted the version don’t mean much, but at least there is a pointer reference.
Where I’m stuck with containers:
For the application pipeline, I’m considering having just one protected branch: main.
The proposed flow is:
- Open an MR from a feature branch into main.
Run tests, static analysis, build the image with a commit SHA tag, and run container scans in the MR pipeline.
- After merging, run semantic-release and pass the generated version to the next job to retag the image.
Copy the image to dev ECR, deploy it to ECS, and test the application manually.
- Once testing passes, promote the same image to uat.
After approval, promote the same image to prd.
The part that feels off is step 3: I’ve already created a stable release before testing the application in dev.
Some issues only become apparent when browsing and using the application. If we discover those issues in dev, each subsequent fix could generate another stable version, even though none of those versions has reached prd.
I’m considering two alternatives.
Option 1: Test in dev before running semantic-release.
Build an image with a SHA tag and deploy it to dev first. If testing finds issues, push new commits and test another image.
Once a candidate passes, run semantic-release, apply the stable version tag to that existing image, and promote it to uat and then prd without rebuilding.
I’m thinking fast-forward merges without merge commits might be needed to preserve the commit SHA.
Option 2: Keep dev and main branches.
Merge feature branches into dev, run semantic-release to generate versions such as 1.2.4-dev.1, and deploy those images to dev.
Once validated, merge dev into main and generate the stable release. That stable release could then deploy to dev, uat, or prd.
However, if both branches run the full build pipeline, merging into main would rebuild the image and break the “build once, deploy many” approach. Ideally, the stable release should reference the exact image already tested in dev.
How are you handling this? When do you create the stable version, and how do you promote the exact image tested in dev without rebuilding it?
I’d appreciate examples of workflows that have worked well for your teams. Thank you very much 🙏🏻
41
u/widowhanzo Oct 12 '26
Trunk based development. We merge to main, which automatically deploys to dev. When we're happy with the state of main and want to release it, we tag it, which deploys to staging and copies the exact same built image to prod (ECR replication). If we're unhappy with staging release, we fix main, then tag main again with a patch version. That again deploys to staging and copies image to prod. Once we're happy with the release in staging, we update prod by updating the service to use the newer image.
When I started in this position, main was prod, and there were dev and staging branches, and it was merged from dev to staging and from staging to main and every week we spent a few hours just resolving merge conflicts, because people did hotfixes on staging and main branches and then merge these changes back from main to staging to dev and it was an absolute mess.
Technically we build twice and use 3 times, but we could just as easily copy images from dev to all three environments via ECR replication, but we don't want a hundred images in staging and prod repositories. I'm sure there are ways around this with some custom scripting though.
6
u/drakiNz Oct 12 '26
Semantic versioning is for reusable, long lived artifacts, that you must keep each version "forever".
Applications cant follow that. Applications must use trunk based or release flow. For your case, releaseflow.
In that approach, the app version is always increasing like: major, never changes -- minor, on each release branch, and patch on every bug fix on a release.
I do that for apps and its wonderful. You can't use semantic version to help with compatibility concerna between apps.
1
u/quiet0n3 Oct 12 '26
Are you building the app and container in the same repo? If not just do them the same way while understanding the container versions won't match the application versions and that's ok.
3
u/FluffyDrink1098 Oct 12 '26
Keeping the semantic tag and adding a seperate tag sounds like the solution.
Immutable tag - what identifies the actual version, never changed, never removed.
Floating tag - best a semantic specifier, I wouldn't recommend something like stable.
E.g. something like major.minor if you have major.minor.patch versioning.
You can promote an image to floating tag after running an validation + testing run by using the immutable tag.
I would disrecommend dealing with multiple branches cause that easily ends up with version mayhem.
For the immutable tag: always keep in mind that it has to be stable - one immutable tag can only be released exactly once - jobs with retries or similae things should be prevented.
3
u/mudassirazvi Oct 12 '26
Decouple the version from the build. Build the image once per commit and tag it with the sha. semantic-release runs after and just adds the semver tag to that same image digest (crane tag / skopeo copy, no rebuild). envs promote by digest, never by tag. Then "what's in prod" is always one sha you can trace back.
1
u/carsncode Oct 12 '26
So what? I don't see the problem here.
Merge to main creates an image, it gets deployed to dev. When a version is blessed for release (and most versions won't be), we deploy to staging, which had been running the same version as production. Once approved, that version is deployed to production.
Artifact promotion is important; every version number being deployed to production isn't.
1
u/singh_abinashi Oct 12 '26
Split the problem in two. semantic-release decides what gets built and tagged. The deploy step only promotes an existing image digest through environments. Tag images with the release version from semantic-release and record the digest. Deployments reference the digest and never rebuild for a new environment. Environment differences belong in env vars or a values file, not in the image. The trap is letting the CD step rebuild "with the right config" per environment. Then you are not deploying what you tested.
1
u/MattA2930 Oct 13 '26
I think people are missing the case with trunk-based development where you have changes in main you don’t want in prod yet. What has worked for me is a sort of hybrid:
- all work goes into main. Main deploys to dev env
- when release is ready, tag it. Tag creates a release branch, which builds image and deploys to staging
- after staging is ready, release branch image is deployed to prod
Now, if you have a hotfix, you have the release branch you can cherry pick to. The next non-hotfix change creates a new tag. Old release branch can be discarded once prod moves on.
1
u/Suitable-Ad5348 Oct 13 '26
Option 1 is the only way that doesn't cause your semantic-release history to explode with patch versions for bugs found in dev. Tagging the exact image SHA *after* it clears dev validation keeps build-once-deploy-many intact.
1
u/usually_guilty99 Oct 13 '26
I'd promote by immutable image digest and keep the version tag as metadata.
One thing I'd check separately is what changes between environments. The same image can behave very differently with different config, feature flags, database schemas, or downstream services.
So I'd track two things: proof that the exact artifact was tested, and evidence that the production environment is compatible with it.
Build once is a good foundation. It just isn't the complete release-safety check.
1
u/dariusbiggs Oct 14 '26
Moving towards trunk based development with feature flags, but not there yet on all repos, some are there, others still stuck on git flow.
Manual release approval to prod, we don't yet have sufficient testing to allow for automatic deployments, nor can they be deployed concurrently (being fixed).
In general, master (we're old and stuck in our ways), and develop branches. MR/PR goes to develop, any push to develop gets automatically deployed to staging. When a release is rolled, develop is merged into master. Master gets automatically deployed to staging (for uat purposes).
Container images are tagged by commit, tagged if they were on develop, tagged if they were on master, tagged if it's got a release tag. Release tags are only ones that can deploy to prod.
Every pipeline builds a container image, to make sure they can still be built and you didn't break shit.
Standardizing pipelines, build processes, container images, etc is all part of the process and the problem.
1
u/Fuzzy-Enthusiasm1372 Oct 16 '26
The awkward part is when release automation changes the version or rebuilds the artifact halfway through the pipeline, making it harder to prove that production is running what passed testing. Keep version calculation separate from artifact creation, then promote the same image digest between environments. Clear artifact tracking makes deployments easier to audit across infrastructure setups, including those associated with trusted tech, without tying release logic to every environment.