DevOpsifying a Go Web App

Suraj GuravSuraj Gurav
2 min read

DevOpsifying a Go Web App: From Code to Cloud 鈽侊笍馃殌

Hey DevOps enthusiasts! 馃憢
In this post, we鈥檒l take a simple Go web application and walk through how to wrap it in a modern DevOps workflow鈥攆rom containerization to CI/CD and Kubernetes deployment. Whether you're a developer looking to level up your ops game or a DevOps engineer exploring Go-based projects, this guide is for you.

馃攳 Project Overview

The go-web-app is a basic web application built using Go鈥檚 net/http package. It includes:

  • Basic routing (login, dashboard, logout)

  • MySQL database integration

  • HTML templates and static assets

Let鈥檚 now shift gears and look at how to productionize this app using DevOps best practices.

馃惓 Step 1: Containerize with Docker

Create a Dockerfile in the root directory:

FROM golang:1.22.5 as builder WORKDIR /app COPY . . RUN go mod download RUN go build -o main .

FROM gcr.io/distroless/base WORKDIR /app COPY --from=builder /app/main . COPY --from=builder /app/static ./static EXPOSE 8080 CMD ["./main"]

Then build and push the image:

docker build -t your-dockerhub-username/go-web-app . docker push your-dockerhub-username/go-web-app

鈿欙笍 Step 2: Set Up CI/CD with GitHub Actions

Create a .github/workflows/deploy.yml file:

name: CI/CD Pipeline on: push: branches: [ main ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Set up Go uses: actions/setup-go@v4 with: go-version: 1.22 - name: Build run: go build -o main . - name: Docker Build & Push uses: docker/build-push-action@v5 with: context: . push: true tags: your-dockerhub-username/go-web-app:latest

罘涱窚

鈽革笍 Step 3: Deploy to Kubernetes with Helm

Create a Helm chart (helm/go-web-app-chart) and define your values.yaml:

image: repository: your-dockerhub-username/go-web-app tag: latest service: type: LoadBalancer port: 80

Then deploy using:

helm install go-web-app ./helm/go-web-app-chart

馃攣 Step 4: GitOps with ArgoCD

  1. Install ArgoCD on your cluster.

  2. Create an Application manifest pointing to your Helm chart repo.

  3. ArgoCD will automatically sync changes from Git to your cluster.

馃 Final Thoughts

This project is a great example of how to take a simple Go app and wrap it in a full DevOps pipeline. From Docker to GitHub Actions to Kubernetes and GitOps, you鈥檝e got a solid foundation to build on.

0
Subscribe to my newsletter

Read articles from Suraj Gurav directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Suraj Gurav
Suraj Gurav

Experienced in supporting and managing cloud infrastructure using tools like AWS, Docker, Kubernetes, Terraform, and Ansible. I help teams by: Automating workflows Improving system performance Building scalable and secure cloud environments Passionate about sharing knowledge and contributing to the DevOps community. Always open to collaborate, mentor, or discuss new trends in DevOps and cloud.