Deploy a Go service
This example tests and vets a Go HTTP service, builds a small Linux image, and uses an explicit health check before ReaperCI marks deployment successful.
Dockerfile
FROM golang:1.26.5-bookworm AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/server ./cmd/server
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /out/server /server
USER nonroot:nonroot
EXPOSE 8080
ENTRYPOINT ["/server"]
The service should expose an unauthenticated, dependency-aware endpoint at
/healthz and shut down cleanly on SIGTERM.
Pipeline
on:
push: [main]
manual: true
schedule:
- "15 5 * * 1"
steps:
- name: test
image: golang:1.26.5-bookworm
run: go test ./... && go vet ./...
timeout: 15m
caches:
- key: go-modules
path: /go/pkg/mod
- key: go-build
path: /root/.cache/go-build
artifacts:
- name: test-report
path: test-results
retainDays: 14
- name: image
dockerfile: Dockerfile
tags:
- api:{{short_sha}}
dependsOn: [test]
platform: linux/amd64
deploy:
environment: staging
image: api:{{short_sha}}
container: api
runArgs: ["-p", "8080:8080"]
approve: manual
healthCheck:
url: https://api-staging.example.com/healthz
interval: 5s
timeout: 5s
failureThreshold: 3
autoRollback: true
Remove the artifacts block if the test command does not create test-results.
Select linux/arm64 for an arm64 target or publish both architectures in separate
steps when the application must run on both.
Verify
Run the pipeline manually once, then push a small reviewed change. Confirm the scheduled trigger is recorded in UTC, the image is available from the embedded registry, the staging health gate passes, and live-state inspection reports the same image. Exercise a rollback before protecting production.