Adopt norn's CI, release, API and docs practices; bare module path
Test / Lint, test and build (push) Successful in 3m17s

Module
- The module path is now the bare "uberbringer"; imports read
  uberbringer/internal/... The banner keeps the Gitea URL.

CI and releases
- Workflows move to .gitea/workflows: test.yml (every branch push:
  gofmt, goimports, tidy, vet, staticcheck, race tests, goreleaser
  snapshot), security.yml (govulncheck weekly and on main) and a hardened
  release.yml (v* tags on main only, tags fetched, goreleaser pinned to
  2.20.3). The broken labeler workflow is removed.
- go.mod pins toolchain go1.27.4, which fixes GO-2026-6859; workflows
  check that the running Go matches it.
- .goreleaser.yaml: tidy check that never writes, reproducible file times,
  prerelease: auto, a release header linking CHANGELOG.md, and archives
  that ship CHANGELOG.md, the example config and the systemd unit.
- Makefile mirrors the CI gate; .dockerignore is an allowlist.

API and tests
- Every error answers {"error", "code", "details"} with a stable code from
  server/errors.go; the framework's own error text is never sent.
- Panics and unexpected errors are logged and reported to Sentry once;
  refusals are not logged as failures. /healthz sends no-store.
- TestRoutesConform requires auth, rate limiting and the body limit on
  every /api/v1 route.
- Race-prone tests no longer rely on freed ports or sleeps; serve takes
  an injected listener.
- The test config uses a placeholder secret instead of a real one.

Install and packaging
- install.sh resolves the latest release through the Gitea API, verifies
  checksums, requests a certificate only when none exists, installs the
  hardened packaging/uberbringer.service and writes the first token to a
  0600 file instead of printing it. It is now executable in git.

Docs
- CLAUDE.md, CHANGELOG.md (0.2.0 with breaking changes and upgrade
  steps), docs/design.md, and docs/plans/formatters.md for the planned
  CP437 blocks, modules and ntfy printing. README updated throughout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-11-29 23:27:48 -06:00
1 parent afcf96431f
commit 9b91109550
39 files changed
+3197 -433

No files matched your search

+187 -23
View File
@@ -36,10 +36,57 @@ REST API and prints them on an EPSON ESC/POS network receipt printer.
sudo ./install.sh printer.example.com you@example.com 192.168.1.245
```
The script installs the latest release as a systemd service running as a
dedicated `uberbringer` user. It also sets up nginx with a Let's Encrypt
certificate, writes `/etc/uberbringer/config.toml` with a fresh secret, and
prints an API token.
The arguments are the server's domain, the email address for Let's Encrypt,
and the printer's address. The domain may contain only letters, digits, dots
and hyphens. The printer address may also contain colons, for IPv6.
The script does the following:
- It downloads the latest release for the host's architecture and checks it
against the release's `checksums.txt` (sha256). If the check fails, nothing
is installed. To install a given release, name its tag:
`sudo UBERBRINGER_VERSION=v0.2.0 ./install.sh <domain> <acme-email> <printer-address>`.
- It installs the binary to `/usr/local/bin/uberbringer` and the systemd unit
to `/usr/local/lib/systemd/system/uberbringer.service`. The unit comes from
the release archive, or from this checkout's `packaging/` directory if the
archive lacks it. The service runs as a dedicated `uberbringer` user.
- It writes `/etc/uberbringer/config.toml` (0640, root:uberbringer) with a
fresh secret.
- It sets up nginx as the HTTPS reverse proxy. The certificate comes from
Let's Encrypt through acme.sh, whose cron job renews it.
- It writes the first API token to `/etc/uberbringer/initial-token` (0600,
readable by root only) instead of printing it. Copy the token to your
client, then delete the file.
The install log, apt output included, is `/var/log/uberbringer-install.log`.
Running the script again upgrades the binary and the unit, and restarts the
service only if the binary, the unit or the config changed. It also rewrites
the nginx site files `/etc/nginx/sites-available/default.conf` and
`reverse-proxy.conf`, so local edits to them are lost. It keeps:
- **The config.** The printer-address argument is ignored on a re-run, so
edit `printer.address` in `/etc/uberbringer/config.toml` instead.
- **The certificate.** One is requested only when `fullchain.pem` or
`privkey.pem` in `/etc/letsencrypt/live/<domain>/` is missing or empty.
- **Tokens.** A re-run creates none. Issue more with
`uberbringer token --config /etc/uberbringer/config.toml --subject <client>`.
The systemd unit ships as
[packaging/uberbringer.service](packaging/uberbringer.service):
- **Changing it.** Use `systemctl edit uberbringer`, never the installed unit
file. Those drop-ins survive re-runs.
- **Sandboxing.** The unit has no capabilities and a read-only file system,
and it can reach the network over IPv4 and IPv6 only. Check it on the host
with `systemd-analyze security uberbringer`.
- **The 0.1 unit.** The 0.1 install script wrote
`/etc/systemd/system/uberbringer.service`, and a re-run renames that file to
`uberbringer.service.bak`. Any other file at that path overrides the
packaged unit; the script leaves it in place and warns.
Upgrading a 0.1 install needs a few manual steps; see
[Migrating from the old format](#migrating-from-the-old-format).
### Docker
@@ -67,6 +114,9 @@ tokens with `uberbringer token`. Tokens created by the old install script keep
working as long as the secret is unchanged. Tokens in query strings are not
accepted, because they leak into proxy logs.
Responses from `/healthz` and every `/api/v1` route, error responses
included, carry `Cache-Control: no-store`.
| Method | Path | Purpose |
|--------|--------------------|------------------------------------------|
| POST | `/api/v1/print` | Queue a print job |
@@ -153,16 +203,37 @@ Details:
### Errors
Errors are JSON: `{"error": "message", "details": ["..."]}`.
Errors are JSON:
| Status | Meaning |
|--------|---------|
| 400 | Malformed JSON, an unknown field, or invalid elements. `details` lists every problem, e.g. `elements[2] (text): size, width and height must be 1-8` |
| 401 | Missing, invalid or expired token |
| 404 | Unknown route or job |
| 413 | Body larger than `webserver.body_limit` |
| 429 | Rate limit exceeded |
| 503 | Queue full (with `Retry-After`) or the server is shutting down |
```json
{"error": "invalid job", "code": "invalid_job", "details": ["elements[2] (text): size, width and height must be 1-8"]}
```
- `code` is stable and meant for clients to match on.
- `error` is for people and may change. It never repeats the HTTP
framework's own text; for example, an unknown route answers `not found`.
- `details` appears only when an `invalid_job` fails validation.
| Status | `code` | Meaning |
|--------|--------|---------|
| 400 | `invalid_job` | Malformed JSON, an unknown field, trailing data after the job, or invalid elements. When elements are invalid, `details` lists every problem. A `{"data": [...]}` body gets a message pointing to [the new format](#migrating-from-the-old-format) |
| 400 | `bad_request` | A malformed HTTP request, refused by the server itself |
| 401 | `unauthorized` | `missing bearer token`, or `invalid or expired token`. Sent with `WWW-Authenticate` |
| 404 | `not_found` | Unknown route |
| 404 | `job_not_found` | Unknown, expired or malformed job ID |
| 405 | `method_not_allowed` | Known route, wrong method, e.g. `DELETE /api/v1/print` with a valid token (without one, `/api/v1` answers `401` first). Sent with `Allow` |
| 408 | `request_timeout` | The request was not received in time |
| 413 | `body_too_large` | Body larger than `webserver.body_limit` |
| 429 | `rate_limited` | Rate limit exceeded. `Retry-After` gives the seconds to wait |
| 431 | `headers_too_large` | Request headers too large |
| 500 | `internal_error` | Unexpected failure. The cause is logged and reported to Sentry, never sent to the client |
| 501 | `not_implemented` | A request body with an unsupported transfer coding. An unknown HTTP method (e.g. `FOO /healthz`) is refused by the HTTP server itself with a plain-text `501` |
| 503 | `queue_full` | The print queue is full. Sent with `Retry-After: 10` |
| 503 | `shutting_down` | The server is shutting down |
Any other status that the HTTP layer produces itself gets the code
`http_<status>`, e.g. `http_502`. `/healthz` answers `503` with its own body,
shown under [Health](#health), not with this shape.
Validation happens before a job is queued. Images are fetched by the worker,
so a blocked or broken image URL shows up as a `failed` job. Nothing is sent
@@ -274,13 +345,44 @@ Old text items did not end the line, hence `"newline": false`. You can usually
drop it now and let each `text` element be a line. Hex-encoded CP437 box
drawing can become plain text: `B3 20 21 21 21` is `"│ !!!"`.
These changes also affect 0.1 clients and installs.
[CHANGELOG.md](CHANGELOG.md) lists every change.
- Tokens are read only from the `Authorization` header. A `?token=` query
string gets `401`.
- Errors have the [JSON shape above](#errors) instead of `{"message": "..."}`
or plain text.
- `printer.model` defaults to `tm-t88` (512 dots). On a TM-T20, set
`model = "tm-t20"` to use the full 576-dot width.
To upgrade a server set up by the 0.1 install script:
1. Add a `[printer]` section to `/etc/uberbringer/config.toml`. The 0.1
script did not write one, `printer.address` is now required, and
`install.sh` keeps an existing config as it is, so without this step the
service does not start:
```toml
[printer]
address = "192.168.1.245"
```
2. Run the new `install.sh` with the domain, the email address and the
printer address; it needs all three, although the printer address in the
kept config is the one used. It creates the `uberbringer` user, installs
the new unit and moves the 0.1 unit aside.
3. The 0.1 script left the config readable by every user. Once the
`uberbringer` group exists, fix that with
`sudo chown root:uberbringer /etc/uberbringer/config.toml && sudo chmod 0640 /etc/uberbringer/config.toml`.
## Configuration
Copy [configs/config.example.toml](configs/config.example.toml) to
`config.toml`. Only `api.secret` (at least 32 bytes) and `printer.address` are
required; every other setting has a default, which the example shows. Configs
written by the old install script still load. Unknown keys are reported as
errors, so a typo can't silently fall back to a default.
from 0.1 still load, because their keys are unchanged, but `printer.address`
is now required. Unknown keys are reported as errors, so a typo can't
silently fall back to a default.
Settings worth knowing:
@@ -307,7 +409,22 @@ Settings worth knowing:
`127.0.0.1`.
- `sentry.dsn`: error reporting. Falls back to the `SENTRY_DSN` environment
variable, then to a DSN built into release binaries (from the `SENTRY_DSN`
CI secret). Request bodies are never sent to Sentry.
CI secret). Request bodies and the `Authorization` header are never sent
to Sentry.
- `log.level` (`debug`, `info`, `warn`, `error`) and `log.format` (`text` or
`json`) control what is logged:
- Each request is logged once, as `request`: at INFO, or at WARN when the
status is 5xx. Only the path is logged, never the query string, the body
or the token.
- An unexpected failure adds one ERROR `request failed` line, with `err` and
`request_id`, and one Sentry event.
- A recovered panic adds one ERROR `panic` line, with `panic` and `stack`,
and one Sentry event.
- A print job that fails after its retries is logged as ERROR `job failed`
with its `job_id`, and is reported to Sentry.
- Refusals are never logged at ERROR and never go to Sentry. Refusals are
4xx answers, the `queue_full` and `shutting_down` 503s, and 503s from
`/healthz`.
## Command line
@@ -323,17 +440,43 @@ printing is finished, and jobs still waiting are marked failed.
## Development
Go 1.26 or newer is required. Use the latest patch release, since govulncheck
flags standard-library fixes.
The Go version is set in `go.mod`:
- The `go 1.26.0` line is the minimum, and builds with `GOTOOLCHAIN=local`
need at least that.
- The `toolchain go1.27.4` line picks the Go release that CI tests, scans and
releases with. With the default `GOTOOLCHAIN=auto`, an older local Go
downloads go1.27.4 by itself.
- To move to a new Go release, change the toolchain line. In the same commit,
bump the tool modules golang.org/x/tools, golang.org/x/vuln and
honnef.co/go/tools. The workflows read the version from `go.mod`.
```sh
make check # gofmt, go vet, staticcheck, go test -race, govulncheck
make build # bin/uberbringer
make fmt # gofmt + goimports
make check # the CI gate, below
make build # bin/uberbringer
make fmt # gofmt + goimports
make vuln # govulncheck
make snapshot # release archives in dist/; publishes nothing
```
`make check` runs the same steps as `.gitea/workflows/test.yml`, in the same
order:
1. `fmt-check`: gofmt and goimports.
2. `tidy-check`: `go mod tidy -diff`.
3. `go vet`.
4. staticcheck.
5. `go test -race -timeout 5m`.
6. `snapshot`: `goreleaser release --snapshot --clean`.
It needs goreleaser installed. govulncheck is not part of it; run
`make vuln`. `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.
`go tool govulncheck` and `go tool goimports` need no separate install. The
module path is `uberbringer`, so packages import as
`uberbringer/internal/...`. Build from a clone of the repository.
```text
cmd/uberbringer/ main: build info, signals, exit code
@@ -347,6 +490,27 @@ 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
configs/ Example configuration
packaging/ systemd unit
docs/ Design notes and feature plans
```
Releases are built by GoReleaser when a `v*` tag is pushed.
[docs/design.md](docs/design.md) explains why the daemon is shaped as it is.
[CHANGELOG.md](CHANGELOG.md) lists the changes in each release.
### 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 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`, `README.md`,
`configs/config.example.toml` and `packaging/uberbringer.service`.
- The release notes link to `CHANGELOG.md` at the tag.