How to Properly Implement CI/CD with Merging Strategies?

0
22
Asked By DevDynamo42 On

I'm a developer currently diving into the world of DevOps, and I've been tasked with setting up our CI/CD workflow at work. Since we don't want to invest in cloud solutions and are limited to using internal servers, I've focused on finding open-source solutions. I've set up some infrastructure as code using bash scripts to manage our self-hosted runners and configured Docker registries to handle our images.

Here's how the current flow works: When someone opens a pull request (PR), Docker builds the project and pushes the image to the registry. After the PR is merged, the corresponding deployment happens using that built image. However, I've noticed an issue: if two PRs are based on the same branch, merging them results in deployments that only reflect the last merged PR, requiring new PRs for the changes to appear together.

Originally, I set this up based on the "Build once, deploy everywhere" concept, but now I'm wondering if "Build on Merge" would be better. Does this go against the idea of building once? What workflow do you all use, and do you have any tips?

4 Answers

Answered By DeployMasterX On

It looks like there's a misunderstanding here. The point of "build once" is about promoting a single finalized image through different environments, like from staging to production. This ensures no discrepancies arise between builds. Building directly from a PR might not be the best practice since the code there could still change. It's usually better to build on merges to the master branch and tag those images distinctly for future references.

Answered By CI_Solutions42 On

Using a trunk-based strategy with tagging will definitely help you here. Just ensure you maintain a linear history to streamline the process.

Answered By CodeCrafter99 On

You might be a bit off on the "Build once" concept. When you're using trunk-based development, you should build from the main branch after merging pulls to create one final image. Think of it this way: every time there’s a change to main, that’s when you build and deploy the new artifact. So, essentially, merging PR B should trigger a build with both A and B changes. Maybe consider elaborating on your branching strategy a bit more too.

Answered By VersioningWizard23 On

There are different approaches to handling this. What I typically do is adopt semantic versioning. Instead of tagging every merge, just tag the main branch whenever you're ready to deploy, like 1.10.0. You can also build the Docker image on merges and tag it as "main" or "latest." This helps in thinking of your project like it's ready for public release. And if you're building from feature branches, you might just want to do it for validation purposes. If that’s the case, tagging them by the commit SHA or PR ID could be a good idea.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.