Template for a Go HTTP service with the basics and a pipeline from forgejo/ci-components (draft)
- Go 100%
The pipeline was a call to a reusable workflow with many inputs. It is now a readable workflow that a team can copy and change. It uses only the actions checkout and ko-build of forgejo/ci-components. |
||
|---|---|---|
| .forgejo | ||
| cmd/server | ||
| .dockerignore | ||
| .editorconfig | ||
| .gitignore | ||
| .golangci.yml | ||
| go.mod | ||
| README.md | ||
| renovate.json | ||
$REPO_OWNER/$REPO_NAME
$REPO_DESCRIPTION
A Go HTTP service, made from the template
forgejo/template-go.
Start
The template has its own module path. Give the module the path of this repository once:
go mod edit -module code.digitaledienst.overheid.nl/$REPO_OWNER/$REPO_NAME
Then build, test and run:
go test ./...
go run ./cmd/server # listens on :8080; set ADDR to change it
curl localhost:8080/healthz
Pipeline
.forgejo/workflows/ci.yml is the complete pipeline. Copy it and
change it as you need. It uses two actions of
forgejo/ci-components: checkout
and ko-build.
| Event | What happens |
|---|---|
| Pull request | golangci-lint, go vet, go test -race and govulncheck in parallel, then the image is built without a push |
Push to main |
The same, and the image is pushed as <short sha>-main-<run number> |
Tag vX.Y.Z |
Also the image X.Y.Z |
The image is code.digitaledienst.overheid.nl/$REPO_OWNER/$REPO_NAME. It is built with ko, from
./cmd/server, without a Dockerfile, and has an SBOM. The push uses the organisation secrets REGISTRY_USER and REGISTRY_TOKEN. Ask a site administrator if your
organisation does not have them.
Files
| File | Purpose |
|---|---|
.editorconfig |
Tabs for Go, 2 spaces for the rest |
.gitignore, .dockerignore |
Build and test output, local configuration |
.golangci.yml |
The linters |
renovate.json |
The shared Renovate presets, and the tags of the actions of forgejo/ci-components |