From 539b90cf4eaa8ac4487309c70b770770dd053118 Mon Sep 17 00:00:00 2001 From: Noel Sabia Date: Sat, 14 Nov 2026 05:11:31 +0100 Subject: [PATCH] ci: add make check, Gitea workflow, numeric runtime user --- .gitea/workflows/ci.yml | 23 +++++++++++++++++++++++ Dockerfile | 4 +++- Makefile | 15 +++++++++++++++ README.md | 30 +++++++++++++++++++++++++++++- 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 .gitea/workflows/ci.yml create mode 100644 Makefile diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..12e99cf --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,23 @@ +name: ci + +on: + push: + pull_request: + +permissions: + contents: read + +jobs: + check: + runs-on: ubuntu-latest + steps: + - name: Check out + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Check + run: make check diff --git a/Dockerfile b/Dockerfile index b915a4e..f79e54a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,8 @@ ENV DATA_DIR=/app/data \ PORT=8080 EXPOSE 8080 -USER nonroot:nonroot +# Numeric UID/GID: the kubelet cannot verify named users for runAsNonRoot. +# 65532 is the distroless "nonroot" user. +USER 65532:65532 ENTRYPOINT ["/app/api"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f52692b --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +GO ?= go + +.PHONY: check vet test build + +# Local equivalent of the Gitea Actions CI job. +check: vet test build + +vet: + $(GO) vet ./... + +test: + $(GO) test -count=1 ./... + +build: + $(GO) build ./... diff --git a/README.md b/README.md index 904b200..751a44d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,31 @@ # api-go -Golang API that is the backbone for daily usage, while python works in batches and is heavy in compute while Golang handles concurrent usage cheap \ No newline at end of file +Golang API that is the backbone for daily usage, while python works in batches and is heavy in compute while Golang handles concurrent usage cheap + +## Checks + +```sh +make check +``` + +Runs `go vet ./...`, `go test -count=1 ./...`, and `go build ./...`. The same +target runs in Gitea Actions on every push and pull request +(`.gitea/workflows/ci.yml`). + +## Container + +The image is a multi-stage build. The runtime is +`gcr.io/distroless/static-debian12:nonroot` and runs as numeric +**UID/GID `65532:65532`** (`USER 65532:65532` in the `Dockerfile`). + +Use the same numbers in Kubernetes: + +```yaml +securityContext: + runAsUser: 65532 + runAsGroup: 65532 + runAsNonRoot: true +``` + +Do not use named users such as `nonroot` in a `securityContext`: the kubelet +cannot verify a non-numeric image user.