DEV Community

Cover image for πŸš€ Task #4 β€” GitHub Actions with CI + Docker + GitOps ArgoCD + GKE Cluster (CICD)
Latchu@DevOps
Latchu@DevOps

Posted on

πŸš€ Task #4 β€” GitHub Actions with CI + Docker + GitOps ArgoCD + GKE Cluster (CICD)

πŸ“Œ How CI/CD Works

Step-by-Step Flow

1️⃣ Developer pushes code to GitHub

  • Push changes inside app/main.go
  • Push new Dockerfile changes
  • Push manifest updates

2️⃣ GitHub Actions Runs

  • Builds Docker image
  • Pushes new image to GHCR
  • Updates deployment YAML
  • Commits YAML back to the repo

3️⃣ ArgoCD Observes Git State

  • ArgoCD continuously watches repo
  • Repo changed ➝ ArgoCD detects new commit

4️⃣ ArgoCD Performs Deployment

  • Applies updated YAML to Kubernetes
  • Deploys the new version
  • Ensures cluster matches Git (self-heal)

5️⃣ Result

βœ… Fully automated CI/CD
πŸ”₯ No kubectl required
⚑ Zero manual deployments
🎯 Pull-based GitOps workflow (secure + stable)


1


πŸ“ Project Structure

argocd-demo-app/
  β”œβ”€β”€ app/
  β”‚    └── main.go
  β”œβ”€β”€ k8s/
  β”‚    └── deployment.yaml
  β”œβ”€β”€ .github/
  β”‚    └── workflows/
  β”‚         └── ci-cd.yaml
  β”œβ”€β”€ Dockerfile
  β”œβ”€β”€ README.md
Enter fullscreen mode Exit fullscreen mode

r1


πŸ“Œ Part 1 β€” Application Code

app/main.go

package main

import (
    "fmt"
    "net/http"
)

func main() {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintln(w, "This is Latchu! Hello from ArgoCD + GitHub Actions + GitOps!")
    })

    fmt.Println("Server running on port 80")
    http.ListenAndServe(":80", nil)
}
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ Part 2 β€” Dockerfile

FROM golang:1.22 AS builder
WORKDIR /app
COPY app/ .
RUN go build -o server main.go

FROM debian:stable-slim
COPY --from=builder /app/server /usr/local/bin/server
CMD ["server"]
EXPOSE 80
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ Part 3 β€” Kubernetes Deployment

k8s/deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo-app
  labels:
    app: demo-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: demo-app
  template:
    metadata:
      labels:
        app: demo-app
    spec:
      containers:
      - name: demo-app
        image: latchudevops/argocd-demo-app:780e0f9bf323810e2acbbb60b8414b5e34b16af6
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: demo-app
spec:
  type: LoadBalancer
  selector:
    app: demo-app
  ports:
    - port: 80
      targetPort: 80
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ Part 4 β€” GitHub Actions CI/CD Pipeline

.github/workflows/ci-cd.yaml

name: CI-CD Pipeline

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Login to DockerHub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Build & Push Docker Image
        run: |
          IMAGE=latchudevops/argocd-demo-app:${{ github.sha }}
          docker build -t $IMAGE .
          docker push $IMAGE
          echo "IMAGE_NAME=$IMAGE" >> $GITHUB_ENV

      - name: Update Kubernetes Manifest
        run: |
          sed -i "s|image: .*|image: $IMAGE_NAME|g" k8s/deployment.yaml

      - name: Commit Updated Manifest
        run: |
          git config --global user.email "actions@github.com"
          git config --global user.name "GitHub Actions"
          git add k8s/deployment.yaml
          git commit -m "Update image to $IMAGE_NAME" || echo "No changes to commit"
          git push
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ Part 5 β€” GitHub Secrets

GitHub repo -> Settings -> Secrets and Variables -> Actions -> Add new repository secret

s


πŸ“Œ Part 6 β€” ArgoCD Setup (GKE)

To install and configure ArgoCD on Google Kubernetes Engine Cluster using below this link

ArgoCD Setup

a1

a2


πŸ“Œ Part 7 β€” To start CICD

  • Push any changes inside app/main.go
  • GitHub Action Workflow CICD pipeline start the build docker image, push the docker image to the docker hub and update the deployment yaml file inside k8s
  • ArgoCD continuously watches the k8s mainfest yaml
  • Manifests changed -> ArgoCD detects new commit
  • Applies updated YAML to Kubernetes
  • Deploys the new version into GKE cluster

If you check with GitHub Actions workflow,

g1

If you can check with ArgoCD UI

a4

If you have a look at the GKE Cluster

k1

The new version has been deployed in Kubernetes

v1


🌟 Thanks for reading! If this post added value, a like ❀️, follow, or share would encourage me to keep creating more content.


β€” Latchu | Senior DevOps & Cloud Engineer

☁️ AWS | GCP | ☸️ Kubernetes | πŸ” Security | ⚑ Automation
πŸ“Œ Sharing hands-on guides, best practices & real-world cloud solutions

Top comments (0)