Files
uberbringer/docs/development.md
T
57_WolveandClaude Opus 5.5 6e47cb713e Add a SQLite job store that opens, checks and locks its file
Jobs are to survive a restart in a SQLite database, jobs.db in the
state directory, through modernc.org/sqlite v1.64.0 (SQLite 3.54.1),
the latest release, which is pure Go and builds with CGO_ENABLED=0.
It requires modernc.org/libc at exactly v1.80.1, older than libc's
latest; the owner accepted that pin as the one exception to taking
dependencies at their latest stable release, and CLAUDE.md and
design.md record it here. The other modules it brings are mathutil,
memory, go-humanize, go-strftime and bigfft, at the versions it asks
for; bigfft has no tagged release.

The new package internal/pkg/jobstore opens the database in this order:

- It creates the file 0600 if it is missing, since SQLite gives its
  log the database's mode. An existing file is never opened outside
  SQLite, since closing any descriptor of it would drop the locks the
  process holds.
- The connection runs its pragmas, in this order: exclusive locking
  before the first read, so the log's index stays in memory and no
  -shm file is made; auto_vacuum NONE; WAL; synchronous NORMAL;
  temporary tables in memory; a 4 MiB journal_size_limit;
  secure_delete FAST. A connector runs them, since the driver's own
  _pragma list sorts them by name and would set the locking mode only
  after the first read, leaving a mapped -shm file on every open but
  the first.
- PRAGMA quick_check reads every page, so a damaged file fails at
  start rather than when a statement meets the page mid-run.
- A user_version newer than the binary's is refused, naming both.
- Each schema step runs in one synced transaction that also sets
  user_version. Version 1 creates jobs, deliveries, content and refs.
- It writes once, so a store that cannot be written fails at start and
  the file stays locked; a second Open of the directory, from any
  process, fails at once with SQLITE_BUSY.

Every error from Open names the file. The URI escapes the path, so a
directory with a space, "#", "?" or "%" in its name works. The store
syncs with fdatasync where the platform has it, as on Linux.

The lock test runs the second Open in a child process, the test binary
run again, so the lock tested is the file system's. A test reopens the
store three times and finds no -shm file and exclusive locking each
time. Nothing uses the store yet.

Part of stage 1d of docs/plans/job-store.md (decisions 1, 3 and 13).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 16:34:51 -06:00

132 lines
6.1 KiB
Markdown

# Development
## Contents
- [Running from source](#running-from-source)
- [Go version](#go-version)
- [Make targets](#make-targets)
- [Generated files](#generated-files)
- [Package layout](#package-layout)
- [CI and releases](#ci-and-releases)
## Running from source
Build from a clone of the repository.
```sh
cp configs/config.example.toml config.toml
go run ./cmd/uberbringer secret # paste into api.secret
$EDITOR config.toml # set printer.address
go run ./cmd/uberbringer token # prints a bearer token
make run
```
## Go version
The Go version is the `go 1.27.4` line in `go.mod`, the latest Go release:
- It is the minimum for building, and builds with `GOTOOLCHAIN=local` need at
least that. With the default `GOTOOLCHAIN=auto`, an older local Go
downloads go1.27.4 by itself.
- CI tests, scans and releases with exactly that release; the workflows read
it from `go.mod`. There is no separate `toolchain` line.
- To move to a new Go release, change the go line
(`go mod edit -go=1.27.5`). In the same commit, bump the tool modules
golang.org/x/tools, golang.org/x/vuln and honnef.co/go/tools.
## Make targets
```sh
make check # the CI gate, below
make build # bin/uberbringer
make build-arm # builds for linux/arm (ARMv6) and linux/arm64, then discards them
make fmt # gofmt + goimports
make vuln # govulncheck
make generate # regenerate docs/swagger.json and the license notices (go generate ./...)
make snapshot # release archives in dist/; publishes nothing
```
`make check` runs the same steps as `.gitea/workflows/test.yml`, in the same
order: gofmt and goimports, `go mod tidy -diff`, `go vet`, staticcheck, a
check that `go generate ./...` leaves the generated files unchanged,
`go test -race -timeout 5m`, builds for linux/arm (ARMv6) and linux/arm64
without cgo, as releases are built, whose binaries it discards, and
`goreleaser check`, which validates the release config without building.
It needs goreleaser installed.
govulncheck is not part of it; run `make vuln`. Run `make snapshot` after
changing `.goreleaser.yaml` or `packaging/`. `make` builds report the
version without the leading `v`, e.g. `0.1.2-3-gabc1234`, as release
binaries do.
The linters are pinned as Go tools in `go.mod`, so `go tool staticcheck`,
`go tool govulncheck` and `go tool goimports` need no separate install.
## Generated files
Never edit these by hand. Change their sources, run `go generate ./...`,
and commit the result with the change.
- `docs/swagger.json` is generated by `tools/genopenapi` from the route
table in `internal/app/uberbringer/server/routes.go`, which the server
also registers its routes from. The schemas come from the Go types the
routes name: their `json` and `jsonschema` tags and their doc comments.
- `THIRD-PARTY-LICENSES.md` and its copy
`internal/app/uberbringer/licenses_embed.md`, which the binary embeds and
`uberbringer licenses` prints, are generated by `tools/genlicenses`. They
hold the license and notice files of the Go distribution and of every
module that `./cmd/uberbringer` links on the release platforms; modules
that only the tools and tests use are left out. Regenerate them after
adding, bumping or dropping a dependency. The generator fails on a module
that ships no license file, or whose license it does not recognize; teach
`licenseMarkers` in `tools/genlicenses/notices.go` its wording once the
license is acceptable.
## Package layout
The module path is `uberbringer`, so packages import as
`uberbringer/internal/...`.
```text
cmd/uberbringer/ main: build info, signals, exit code
internal/app/uberbringer/ CLI commands and wiring
server/ Fiber HTTP API, auth, health
internal/pkg/config/ Config from TOML and UBERBRINGER_* variables (Viper): defaults, validation
internal/pkg/escpos/ ESC/POS command builder, code pages, barcodes, QR, raster, status, interpreter
internal/pkg/receipt/ Job format, validation, text folding, word wrap, blocks, rendering, preview
internal/pkg/modules/ Modules that build jobs from plain payloads: note, notify, ntfy; notification cards, markdown
internal/pkg/ntfy/ ntfy's message types; the subscriber: stream, cursor, repeats, paper budget, quiet hours
internal/pkg/raster/ Image decoding, scaling and dithering
internal/pkg/safehttp/ SSRF-guarded image fetching
internal/pkg/printer/ TCP printer client (port 9100) and status queries
internal/pkg/printqueue/ Job queue, worker and status history
internal/pkg/jobstore/ The job store on disk: one SQLite database, through modernc.org/sqlite
configs/ Example configuration
examples/ Example jobs, such as the block calibration receipt
packaging/ systemd unit
tools/genlicenses/ Generates THIRD-PARTY-LICENSES.md and its embedded copy from the linked modules
tools/genopenapi/ Generates docs/swagger.json from the route table
docs/ User docs, API reference, OpenAPI document, design notes and feature plans
```
## CI and releases
CI runs on the Gitea runner from `.gitea/workflows/`. The repository has no
`.github/` directory.
- `test.yml` runs the `make check` gate on every branch push. It keeps none
of the binaries it builds for ARM, and it does not run on pull requests
or tags.
- `security.yml` runs govulncheck on pushes to main and every Monday at
06:00 UTC. Scheduled runs use main's copy of the workflow.
- `release.yml` builds and publishes a release with goreleaser 2.20.3 when a
`v*` tag is pushed.
- It runs only for tags whose commit is on main, and refuses any other tag.
- `vX.Y.Z-rc.N` tags are published as prereleases, so they never become the
latest release that `install.sh` installs.
- Each archive holds the binary, `LICENSE.txt`, `THIRD-PARTY-LICENSES.md`,
`README.md`, `CHANGELOG.md`, `configs/config.example.toml`,
`packaging/uberbringer.service`, `docs/swagger.json` and, from `docs/`,
`install.md`, `docker.md`, `configuration.md`, `security.md`, `api.md`,
`ntfy.md` and `cli.md`.
- The release notes link to `CHANGELOG.md` at the tag.