Skip to content

About

Go URL shortener with distroless containers and Helm

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Go URL Shortener

A stateless Go service for demonstrating secure container packaging and Helm deployment.

API

curl -X POST localhost:8080/shorten -d '{"url":"https://example.com"}' -H 'content-type: application/json'
curl -i localhost:8080/r/<id>
curl localhost:8080/health

DevOps practices

  • Go vet, race detector and unit tests in GitHub Actions;
  • minimal distroless image and non-root user;
  • image publishing to GHCR;
  • Helm chart with replicas, probes and requests/limits.
go test -race ./...
go run ./cmd/server
helm lint helm/url-shortener
helm template url-shortener helm/url-shortener

Architecture

Git -> GitHub Actions (gofmt, vet, -race tests) -> GHCR :<sha> distroless -> Helm release

Key files

  • internal/store/store.go — mutex-guarded, collision-checked link store.
  • cmd/server/main.go — HTTPS-only validation, structured JSON errors.
  • Dockerfile — multi-stage build to distroless with a non-root USER.
  • helm/url-shortener/ — chart with probes, requests/limits and an image updater-friendly values.yaml.

What I learned

Distilling an image down to just the runtime (distroless) plus a non-root user removes the largest attack surface without adding a base image. Enforcing https:// at the API and 404-ing on unknown links keeps the shortener honest, while go test -race catches the data races a plain Map would otherwise hide under concurrent redirects.

Endpoints

Path Method Purpose
POST /shorten POST shorten an https:// URL, returns id
GET /r/{id} GET 302 redirect to the original URL
GET /health GET liveness

About

Go URL shortener with distroless containers and Helm

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages