The environment repository – Source Code Management with Git and GitOps

The environment repository stores the environment-specific configurations needed to run the application code. Therefore, they will typically have Infrastructure as Code (IaC) in the form of Terraform scripts, CaC in the form of Ansible playbooks, or Kubernetes manifests that typically help deploy the code we’ve built from the application repository.

The environment repository should follow an environment-specific branching strategy where a branch represents a particular environment. You can have pull request-based gating for these kinds of scenarios. Typically, you build your development environments from a development branch and then raise a pull request to merge the changes to a staging branch. From the staging branch to production, your code progresses with environments. If you have 10 environments, you might end up with 10 different branches in the environment repository. The following diagram showcases the branching strategy you might want to follow for your environment repository:

Figure 2.14 – The environment repository

The environment repository aims to act as the single source of truth for your environments. The configuration you add to the repository is applied directly to your environments.

Tip

While you can combine the environment and application repository into one, the best practice is to keep them separate. GitOps offers a clear separation between the CI and CD processes using the application and environment repositories, respectively.

Now that we’ve covered Git and GitOps in detail, let’s look at why Git and GitOps are related but different concepts.

Git versus GitOps

The following table summarizes the differences between Git and GitOps:

Remember that while Git is a version control system, GitOps extends this concept by utilizing Git as a central source of truth for infrastructure and application configurations, allowing for automated deployment and management of DevOps workflows.

Summary

This chapter covered Git, GitOps, why we need it, its principles, and various GitOps deployments. We also looked at different kinds of repositories that we can create to implement GitOps, along with the branching strategy choices for each of them.

You should now be able to do the following:

  • Understand what source code management is and how it is necessary for many activities with modern DevOps
  • Create a Git repository and play around with the clone, add, commit, push, pull, branch, and checkout commands
  • Understand what GitOps is and how it fits the modern DevOps context
  • Understand why we need GitOps and how it achieves modern DevOps
  • Understand the salient principles of GitOps
  • Understand how to use an effective branching strategy to implement GitOps based on the org structure and product type

In the next chapter, we will develop a core understanding of containers and look at Docker.

Leave a Reply

Your email address will not be published. Required fields are marked *