- Source of Truth: In GitOps, Git repositories serve as the single source of truth for your infrastructure and application configurations. Everything needed to run your app is stored as code in these repositories.
- Version Control: Since everything is in Git, you have a complete history of changes. This makes it easy to track who made changes, revert to previous versions if needed, and collaborate with others.
- Automation: GitOps uses automation tools to continuously monitor your Git repositories. When changes are detected, these tools automatically update your applications and infrastructure to match the new configuration. This ensures that what you have in your Git repository is exactly what is running in your environment.
- Consistency and Reliability: By using Git as the source of truth and automating deployments, GitOps ensures that your environments are consistent and reduces the chance of human error, making deployments more reliable.
- Collaboration: Teams can collaborate more effectively since they can propose changes through pull requests, review code, and discuss potential impacts before deploying.
Folder structure for placing your YAML configuration
The folder structure is as follows:
Github actions for validating and applying the configuration
The github actions files are present in .github/workflows: https://github.com/truefoundry/truefoundry-gitops-sample-repository/tree/main/.github/workflows. The template primarily implements two things:-
dry_run_on_pr.yaml - This file runs on creation or updating of any pull request. It validates the spec for all the yaml files changed in the PR. For validation, it performs the following checks:
- Check if the changed file is a valid yaml file
- Check if the changed file name is same as the name field in the yaml file
- Check the spec if valid using
tfy apply --dry-run
-
apply_on_merge.yaml - This file runs
tfy apply
on all the files that have changed in the PR. It also runs delete on the files that have been deleted.