← Back to Cecep Azhar
Cecep Azhar #ci-cd#golang#docker#kubernetes#devops#pipeline

Membangun CI/CD Pipeline yang Solid untuk Go + Docker + Kubernetes

Cecep Saeful Azhar • 16 Oct 2026
Membangun CI/CD Pipeline yang Solid untuk Go + Docker + Kubernetes
Tutorial lengkap membuat CI/CD pipeline modern. Dari local development sampai production deployment dengan Go, Docker, dan Kubernetes.

Pipeline yang Buruk = Hidup yang Susah

Percayalah, saya pernah bekerja di proyek di mana deployment manual memakan waktu 2 jam. Dua jam! Setiap kali ada bug fix kecil, developer harus jalankan 15 steps secara manual. Dan tentu saja, human error terjadi. Saya pernah push wrong tag ke production. Sekarang, di setiap proyek yang saya tangani, CI/CD pipeline harus solid sebelum lines of code pertama ditulis.

Architecture Pipeline yang Saya Rekomendasikan

Ini pipeline yang sudah saya buktikan di production untuk Go projects:

# .github/workflows/ci-cd.yml
name: CI/CD Pipeline

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]

jobs:
  lint-and-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup Go
        uses: actions/setup-go@v4
        with:
          go-version: '1.22'
      - name: Run Linter
        uses: golangci/golangci-lint-action@v3
      - name: Run Tests
        run: go test -v -race -coverprofile=coverage.out ./...

  build:
    needs: lint-and-test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Build Docker Image
        run: docker build -t myapp:${{ github.sha }} .

  deploy:
    needs: build
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    steps:
      - name: Deploy to Kubernetes
        run: |
          kubectl set image deployment/myapp myapp=myapp:${{ github.sha }}
          kubectl rollout status deployment/myapp

Dockerfile Multi-Stage Build

Di pengalaman saya, multi-stage build adalah must untuk Go projects. Docker image production harus kecil dan secure:

# Build stage
FROM golang:1.22-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o server ./cmd/server

# Production stage
FROM alpine:3.19
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/server .
EXPOSE 8080
CMD ["./server"]

Tips dari Production

Beberapa hal yang saya pelajari:

1. Cache dependencies aggressively. Di Docker dan CI, manfaatkan layer caching. Letakkan go mod download sebelum COPY . . — ini bisa menghemat 2-3 menit di setiap build.

2. Parallel test execution. Go support parallel testing secara native. Gunakan t.Parallel() di tests Anda untuk mengurangi pipeline time secara signifikan.

3. Rollback strategy. Selalu siapkan rollback mechanism. Di Kubernetes, saya menggunakan rolling updates dengan maxSurge dan maxUnavailable yang tepat.

4. Environment promotion. Pipeline harus support staged deployment: dev ke staging ke production. Setiap environment punya gates yang harus dipenuhi.

Yang Sering Dilupakan

Security scanning. Di pipeline saya, selalu ada steps untuk: container vulnerability scanning (Trivy), dependency vulnerability check (govulncheck), dan secret detection (gitleaks). Jangan deploy image yang belum di-scan ke production.

Security dalam CI/CD Pipeline

Satu hal yang sering diabaikan developer adalah security scanning di pipeline. Setiap build harus menjalankan beberapa security checks secara otomatis:

Dengan security scanning di pipeline, kamu bisa menangkap vulnerability sebelum code sampai ke production. Ini jauh lebih murah daripada harus patch production system yang sudah terkena serangan.

← More articles from Cecep Azhar Central Content Hub Home →