Skip to content

feat(docker): user-defined label presets via tsdproxy.template - #552

Open
almeidapaulopt wants to merge 3 commits into
mainfrom
feat/label-presets
Open

almeidapaulopt wants to merge 3 commits into
mainfrom
feat/label-presets

Conversation

@almeidapaulopt

Copy link
Copy Markdown
Owner

Summary

  • Adds user-defined label presets (presets: in tsdproxy.yaml) that containers reference with tsdproxy.template: <name>, expanding the preset's ports and dashboard fields into the container's effective labels (Option B+C from the issue — no built-in registry).
  • Explicit container labels always override preset values, and presets compose with extra per-container ports.

Motivation

Exposing common services (gitea, nginx, authentik, …) means repeating the same tsdproxy.port.* / tsdproxy.dash.* label patterns on every container. Presets let operators define the pattern once and apply it with a single label.

Closes #432

Changes

  • internal/config/config.go: new presets map (PresetConfig → PresetPort options + PresetDashboard). Port keys use the exact syntax of tsdproxy.port.* label values; per-port options mirror the port label options (noTLSValidate, funnel, noAutoDetect). Only non-zero dashboard fields expand, so an unset icon still falls back to the image-based guess.
  • internal/targetproviders/docker/preset.go (new): applyPresetLabels expands a preset into synthetic tsdproxy.port.* / tsdproxy.dash.* label entries. The input label map is never mutated; unknown preset names log an error and leave labels unchanged.
  • internal/targetproviders/docker/container.go: expandPreset() runs in newContainer before any label parsing, so all existing parsing, validation and operator gates apply unchanged — a preset cannot bypass allowContainerFunnel / allowTlsValidateDisable (options flow through model.ApplyPortOptions).
  • Precedence (Option C):
    • Dashboard: preset values only fill label keys the container didn't set.
    • Ports: an explicit tsdproxy.port.* label on the same proxy port/protocol replaces the preset port (protocol defaults normalized, so 443:3001 overrides a preset 443/https:…); explicit ports on other proxy ports are added on top of the preset ports.
  • Wiring: docker.New takes the presets map; proxymanager passes cfg.Presets.
  • Docs: "presets" section with a gitea example in the server config guides (current + v3), tsdproxy.template row in both Docker label references, sample configs updated.

Test Plan

  • internal/targetproviders/docker/preset_test.go — 13 tests: expansion (ports/dashboard/options), scalar precedence, port precedence (same proxy port, default-protocol normalization), composition on other ports, unknown/nil presets no-op, input map not mutated, and end-to-end through newContainer → newProxyConfig (real target resolution)
  • internal/config/config_test.go — YAML round-trip via the real config loader (key normalization included) + defaults do not invent preset values
  • Sabotage run: disabling expandPreset() makes the integration tests fail; re-enabling makes them pass
  • go build ./..., go vet ./internal/..., golangci-lint run clean on the touched packages; full unit suite green (24 packages)
  • Real binary check: server starts with a presets-bearing config; a typo inside presets is rejected with unknown field "portz" — did you mean "ports"?

Notes for review

  • The Lint CI step is red-by-proxy on every PR from main (pre-existing errcheck findings with golangci-lint v2.15 — see fix: sort dashboard names by display label across sources #549); this PR adds no new lint findings on the touched packages.
  • Scope kept to the Docker target provider per the issue; Incus/Proxmox could adopt the same mechanism later.

almeidapaulopt and others added 2 commits October 20, 2026 09:19
golangci-lint v2.15.0 flags unchecked receives from chan error. Bind and
handle (or explicitly discard with rationale) at all sites, unblocking
the build workflow for every open PR (incl. #548).
…emplate

Presets are defined by the operator under presets in tsdproxy.yaml and
expanded into container labels when a container carries
tsdproxy.template: <name> (issue #432, Option B+C).

- config: Presets map with ports (same syntax as tsdproxy.port.* label
  values, plus noTLSValidate/funnel/noAutoDetect options) and dashboard
  fields; only set fields expand so defaults (e.g. icon guess) stay intact
- docker: preset expansion happens in newContainer before label parsing,
  reusing the existing port parsing and operator gates — a preset cannot
  bypass allowContainerFunnel/allowTlsValidateDisable
- precedence: explicit container labels override preset values; a port
  label on the same proxy port/protocol replaces the preset port, ports
  on other proxy ports compose with the preset
- docs: presets section in the server config guides (current + v3),
  tsdproxy.template in the Docker label references, gitea example

Closes #432
@almeidapaulopt

Copy link
Copy Markdown
Owner Author

CI note: the merge commit brings in fix/errcheck-v2.15-base (#551) so the Lint step can pass — the 3 errcheck findings were pre-existing main debt in test files this feature never touched. Verified locally with the exact CI linter (golangci-lint v2.15.0: 0 issues) before pushing. If #551 merges first, those hunks drop out of this diff automatically; merging this PR first would also close #551 (its commit is an ancestor). Either order is safe. One flake seen and cleared: TestTCPPortClose (timing race, pre-existing) failed once on a slow runner and passed on rerun + 50x locally.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Docker label presets / templates for common services

1 participant