The overall CI/CD pipeline, according to best practices, is shown in the figure below.
There are three code repositories under the CodeCommit repository. One is flux-repo
, the configuration repository for Flux CD, which is used to define Flux-related resources. The other is microservices-repo, which saves microservice application configurations and deployment files. The third one is the source repository app-repo
for business services. In this post, a front-end project will be used as an example. We used CodePipeline for continuous integration in the CI/CD pipeline, built and stored the docker image in Amazon ECR, and deployed the CD engine Flux as a pod in the Amazon EKS environment.
The basic workflow is:
- Coding engineers write code and push the final code to app-repo.
- Code changes in the app-repo trigger AWS CodePipeline.
- AWS CodePipeline edits and packages code, generates container images, and pushes them to the container image repository/Amazon ECR.
- The CD engine Flux, running in the EKS environment, regularly scans the ECR container image repository and pulls container image metadata for applications.
- The new container image address is automatically synced to the application deployment file stored in microservices-repo via git commit/push when a new version of the container image detected.
- Flux regularly pulls application configurations and deployment files from the Flux-repo. Since the Flux-repo repository references the microservices-repo, Flux checks the consistency of the workload running state of the cluster with the expectations described in the microservices-repo files. If there is any difference, Flux will automatically enable the EKS cluster to synchronize the differences to ensure that workloads run in the expected state.
Table of Best Practices
Since we have explained the GitOps concept and the architecture of the CI/CD pipeline, we will use a case to complete this practice by going through the four modules below:
- Deploy the cloud infrastructure using Infrastructure as Code (IaC)
- Deploy Flux CD on AWS EKS cluster
- Deploy GitOps workflow using Flux CD
- Implement automatic deployment based on images using GitOps workflow