skills/go-deploy/SKILL.md
Build and deploy Go applications — version detection, static binaries, CGO, workspaces, and Dockerfile patterns. Use when deploying a Go project, or when go.mod is detected.
npx skillsauth add nixopus/agent go-deployInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Project is Go if any of these exist:
go.mod at the build context rootgo.work at the root (Go workspaces)main.go at the rootGo version priority:
go.mod → go directive (e.g. go 1.21).go-version file, mise.toml, or .tool-versionsgo build -ldflags="-w -s" -o /app/out .CGO_ENABLED=0 go build -ldflags="-w -s" -o /app/out .cmd/, target it directly: go build -ldflags="-w -s" -o /app/<name> ./cmd/<name>go build -ldflags="-w -s" -o /app/out ./<module>.go filescmd/ (e.g. ./cmd/server)go.work): first module with a main package/app/out or /app/<name>CGO_ENABLED=0For multi-module projects with go.work:
main.go by defaultDefault: CGO disabled (CGO_ENABLED=0) for static binaries. If CGO needed:
CGO_ENABLED=1gcc, g++, libc6-devlibc6 for dynamic linkingdebian:bookworm-slim instead of alpine for runtimePORT in .env / .env.example:8080, ListenAndServe, Run( in main.go| Import / package | Category |
|---|---|
| net/http | Standard library |
| github.com/gin-gonic/gin | Gin |
| github.com/labstack/echo | Echo |
| github.com/go-chi/chi | Chi |
| github.com/valyala/fasthttp | FastHTTP |
| github.com/gofiber/fiber | Fiber |
Copy in order:
go.mod, go.sum (and go.work if workspace)go.work*.go (or full source for multi-package)Copy go.mod + go.sum first for layer caching.
Use BuildKit cache mount:
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go build -ldflags="-w -s" -o /app/out .
| Stage | Image |
|---|---|
| Build | golang:1.23-alpine or golang:1.23-bookworm |
| Runtime (static) | gcr.io/distroless/static or alpine:latest |
| Runtime (CGO) | debian:bookworm-slim |
FROM golang:1.23-alpine AS build
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o /app/out .
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /app
COPY --from=build /app/out .
EXPOSE 8080
CMD ["./out"]
FROM golang:1.23-bookworm AS build
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o /app/out .
FROM gcr.io/distroless/static
WORKDIR /app
COPY --from=build /app/out .
EXPOSE 8080
CMD ["./out"]
FROM golang:1.23-alpine AS build
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o /app/server ./cmd/server
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /app
COPY --from=build /app/server .
EXPOSE 8080
CMD ["./server"]
FROM golang:1.23-alpine AS build
WORKDIR /app
COPY go.work go.work.sum ./
COPY api/go.mod api/go.sum ./api/
COPY shared/go.mod shared/go.sum ./shared/
RUN go mod download ./api/...
COPY api/ ./api/
COPY shared/ ./shared/
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o /app/out ./api
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /app
COPY --from=build /app/out .
EXPOSE 8080
CMD ["./out"]
CGO_ENABLED=0 is required for truly static binaries — without it, the binary may dynamically link glibc and fail on Alpine/distrolessgo.sum must be committed to the repo — missing it causes go mod download to fail in Dockercmd/ layout require specifying the target: go build ./cmd/server, not just go build .ca-certificates for outbound HTTPS — distroless/static includes them by default/go/pkg/mod — use BuildKit cache mounts to avoid re-downloading on every buildtools
Compressed catalog of all Nixopus API operations for the nixopus_api() tool
development
Deploy static file sites — Caddy/nginx serving, Staticfile config, and Dockerfile patterns. Use when deploying a static HTML site with no server-side runtime, or when index.html or a Staticfile is detected at the project root.
devops
Deploy shell script applications — interpreter detection, setup scripts, and Dockerfile patterns. Use when deploying a shell script project, or when start.sh is detected.
development
Self-healing loop for failed deployments — diagnose, fix, redeploy up to 3 attempts, then escalate or rollback. Load when a deployment fails or build errors occur.