Skip to content

Devops-by-pritam/golang-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

41 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


πŸš€ Golang CI/CD with Jenkins, Docker, Helm, and OpenShift

This repository demonstrates a full CI/CD pipeline for a Golang application, showing how code changes are built, containerized, and deployed to an OpenShift cluster using modern DevOps tools.


πŸ“ Project Structure

.
β”œβ”€β”€ app/                     # Go application code & Dockerfile
β”‚   β”œβ”€β”€ main.go
β”‚   β”œβ”€β”€ go.mod
β”‚   β”œβ”€β”€ go.sum
β”‚   └── Dockerfile
β”‚
β”œβ”€β”€ k8s/helm-chart/          # Helm chart for OpenShift deployment
β”‚   β”œβ”€β”€ Chart.yaml
β”‚   β”œβ”€β”€ values.yaml
β”‚   └── templates/
β”‚       β”œβ”€β”€ deployment.yaml
β”‚       β”œβ”€β”€ service.yaml
β”‚       └── route.yaml
β”‚
└── Jenkinsfile              # Jenkins CI/CD pipeline definition

πŸ” CI/CD Pipeline Overview

The pipeline is orchestrated using Jenkins, triggered via GitHub Webhooks on commits to the main branch.

βœ… Continuous Integration (CI)

  1. Trigger: GitHub push event (via webhook).
  2. Build: Compiles the Go application as a static binary.
  3. Dockerize: Creates a lightweight image using a multi-stage Dockerfile.
  4. Push: Publishes the image to Docker Hub (tusk03/golang-app).

πŸš€ Continuous Delivery (CD)

  1. Login: Jenkins authenticates with OpenShift via CLI (oc login) using a secret token.
  2. Deploy: Runs helm upgrade --install using the chart in k8s/helm-chart/.
  3. Expose: OpenShift Route exposes the service (similar to Ingress in Kubernetes).

πŸ› οΈ Technologies Used

Tool/Platform Purpose
Go (Golang) Application logic
GitHub Source control
Jenkins CI/CD pipeline automation
Docker Containerization of app
Docker Hub Container registry
Helm Kubernetes/OpenShift deployment
OpenShift Container orchestration platform

🧩 Troubleshooting & Key Learnings

Building this pipeline involved solving several real-world DevOps issues:

πŸ”Ή 1. Docker Build Context Error

  • Error: go.mod not found, or unable to prepare context.
  • Fix: Reorganized project so the Dockerfile and Go files live inside /app. Updated docker build path to ./app in Jenkinsfile.

πŸ”Ή 2. DockerHub Credential Issue

  • Error: Jenkins failed to push image to Docker Hub.
  • Fix: Corrected withCredentials block in Jenkinsfile using usernamePassword for DockerHub credentials.

πŸ”Ή 3. OpenShift Token Expired

  • Error: oc login: token invalid or expired.
  • Fix: Generated a fresh token from OpenShift Console and updated Jenkins credentials.

πŸ”Ή 4. Helm Chart Not Found

  • Error: Chart.yaml file is missing.
  • Fix: Corrected the path to ./k8s/helm-chart and ensured file is named Chart.yaml (case-sensitive).

βœ… Outcome

By the end of this CI/CD pipeline:

  • A new Go binary is compiled and containerized automatically.
  • Docker image is pushed to your registry.
  • Helm deploys the updated image to your OpenShift cluster using rolling upgrades.
  • The app is available via a public OpenShift Route.

About

Devopsifying the golang app

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published