henriqueatila/golang-gin-best-practices / skills/golang-gin-deploy
golang-gin-deploy
VerifiedDeploy Go Gin APIs with Docker, docker-compose, Kubernetes. Use when Dockerizing a Go app, setting up docker-compose, deploying to K8s, or configuring CI/CD and health probes.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 7.4 KB |
| metadata.json | config | 481 B |
| references/configuration-docker-quickref.md | markdown | 2.9 KB |
| references/configuration-health-and-config-loader.md | markdown | 3.1 KB |
| references/docker-compose-dev-setup.md | markdown | 3.4 KB |
| references/docker-compose-test-and-prod.md | markdown | 5.0 KB |
| references/dockerfile-build-args-security-and-healthcheck.md | markdown | 3.2 KB |
| references/dockerfile-multistage-and-base-images.md | markdown | 3.1 KB |
| references/dockerfile-size-optimization-and-complete-example.md | markdown | 3.1 KB |
| references/kubernetes-complete-helm-cicd.md | markdown | 3.5 KB |
| references/kubernetes-deployment-service-config.md | markdown | 3.5 KB |
| references/kubernetes-probes-hpa-ingress-pvc.md | markdown | 3.8 KB |
| references/observability-docker-stack-and-shutdown.md | markdown | 4.0 KB |
| references/observability-metrics-logs-sampling.md | markdown | 4.4 KB |
| references/observability-otel-sdk-and-middleware.md | markdown | 4.2 KB |
references/dockerfile-build-args-security-and-healthcheck.md
View on GitHub# Dockerfile — Build Arguments, Secrets, Non-Root User, and HEALTHCHECK
## Build Arguments and Secrets
**Build arguments** (non-sensitive, embedded in image — visible in `docker history`):
```dockerfile
ARG VERSION=dev
ARG BUILD_TIME
RUN CGO_ENABLED=0 go build \
-ldflags="-s -w -X main.Version=${VERSION} -X main.BuildTime=${BUILD_TIME}" \
-o /app/server ./cmd/api
```
```bash
docker build \
--build-arg VERSION=$(git describe --tags --always) \
--build-arg BUILD_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
-t myapp:latest .
```
Expose in the health endpoint:
```go
var Version = "dev"; var BuildTime = "unknown" // set via -ldflags
func (h *HealthHandler) Check(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "ok", "version": Version, "build_time": BuildTime})
}
```
**Secrets** — use BuildKit secret mount; never `ARG` for sensitive values:
```dockerfile
# syntax=docker/dockerfile:1
RUN --mount=type=secret,id=github_token \
GITHUB_TOKEN=$(cat /run/secrets/github_token) \
GONOSUMCHECK=github.com/myorg/* go mod download
```
```bash
docker build --secret id=github_token,src=~/.github_token -t myapp .
```
**Warning:** `ARG` values are visible in `docker history` and image metadata — never use for secrets.
---
## Non-Root User
Running as root in a container risks host root access on container escape.
**Distroless:nonroot** — nothing extra needed; already runs as UID 65532:
```dockerfile
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=builder /app/server /server
ENTRYPOINT ["/server"]
```
**Alpine** — create a dedicated user:
```dockerfile
FROM alpine:3.21
RUN apk add --no-cache ca-certificates tzdata && \
addgroup -S appgroup && adduser -S -G appgroup -u 10001 appuser
COPY --from=builder /app/server /app/server
RUN chown appuser:appgroup /app/server
USER appuser
ENTRYPOINT ["/app/server"]
```
If the app writes files (e.g., temp uploads), ensure target directories are owned by the app user or use a volume with appropriate permissions.
---
## HEALTHCHECK Instruction
`HEALTHCHECK` tells Docker Engine and docker-compose how to test container health. Kubernetes ignores it — K8s uses `livenessProbe`/`readinessProbe` instead.
**Problem:** distroless has no shell and no `curl`/`wget`. Embed the health check in the main binary:
```go
// cmd/api/main.go
func main() {
healthCheck := flag.Bool("health-check", false, "run health check and exit")
flag.Parse()
if *healthCheck {
url := fmt.Sprintf("http://localhost:%s/health", os.Getenv("PORT"))
resp, err := http.Get(url)
if err != nil { os.Exit(1) }
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { os.Exit(1) }
os.Exit(0)
}
// ... normal server startup
}
```
```dockerfile
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
CMD ["/server", "-health-check"]
```
> For multi-stage build and base images: see [dockerfile-multistage-and-base-images.md](dockerfile-multistage-and-base-images.md).
> For size optimization, .dockerignore, and complete Dockerfile: see [dockerfile-size-optimization-and-complete-example.md](dockerfile-size-optimization-and-complete-example.md).
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |