🔙 Backjoeygoksu.com

A Brief Guide to GitOps

software

March 20, 2022

Hello everyone,

I’ve been hearing a lot about GitOps lately. I want to share some of my experience with it.

Let’s start with a simple question.

What is GitOps?

It’s an operational framework that takes DevOps best practices and applies them to infrastructure automation. It focuses on a developer-centric experience when operating infrastructure, including Git and Continuous Deployment tools. The main idea is to make it easier for developers to work with infrastructure, and to make it easier for teams to work together.

I’ve been using Jenkins for a long time and I love to use “Jenkinsfile” to automate the CI/CD process. With the multibranch projects, I can use the same Jenkinsfile to run the builds for different branches. My main flow is:

Develop -> PR request -> Merge -> Build -> Test -> Deploy.

I define everything in the Jenkinsfile and it handles the rest. I can also use the same Jenkinsfile for other projects. It makes my life easier. It also make DevOps jobs easier to manage.

Here is an example Jenkinsfile to building your project and deploying to AWS ECS using codedeploy. (It’s not %100 accurate. It’s just a representation of workflow.)

#!/usr/bin/env groovy
pipeline {
  agent any
  tools {nodejs "latest"}
  stages {
    stage('preflight') {
      steps {
        echo sh(returnStdout: true, script: 'env')
        sh 'node -v'
        sh 'npm --version'
        sh 'git log --reverse -1'
      }
    }
    stage('build') {
      steps {
        sh 'npm install'
        sh 'npm run build'
      }
    }
    stage('deploy') {
      steps {
        sh 'docker build . ${git repo name}'
        sh 'aws codedeploy ...'
      }
    }
  }
}

Principles

  • Declaratively described: Define the workflow in the Jenkinsfile (or whatevery you have/want)
  • Single source of truth: All the code is in one place, and all the changes are in one place.
  • Approved changes for direct application to the system: The changes are approved by the team before they are applied to the system.

Difference between DevOps and GitOps

DevOps is the combination of cultural philosophies, practices and tools that are used to automate the process of building, deploying and maintaining software. GitOps is a technique to implement Continuous Delivery. If you already employing DevOps techniques, shared principles between them certainly make it easier to adopt a GitOps workflow.

I want to share definitions and my experience with GitOps. Hopefully, it will be useful for you.

References

gitopsdevopscontinuous deploymentcloud native

Crafted with ❤️ in multiple locations [🇬🇧 🇺🇸 🇹🇷 🇷🇺]. · © 2022