Skip to content

v2.0.0: Rewrite in Go#1

Merged
Will-Luck merged 3 commits intomainfrom
v2-go-rewrite
Feb 8, 2026
Merged

v2.0.0: Rewrite in Go#1
Will-Luck merged 3 commits intomainfrom
v2-go-rewrite

Conversation

@Will-Luck
Copy link
Copy Markdown
Owner

Summary

  • Complete rewrite of Docker-Guardian from shell script to Go, producing a single static binary
  • Drop-in replacement: all 6 acceptance test suites pass (19/19 tests), identical env vars and Docker labels
  • Multi-stage Dockerfile: 23MB image (alpine + static binary), no runtime dependencies (curl/jq/bash removed)

Changes

New Go packages

  • cmd/guardian — entrypoint with signal handling, backward-compat CMD ["autoheal"] arg
  • internal/config — env var loading with same defaults as shell version
  • internal/docker — Docker API client (moby SDK), container listing, events, restart/start
  • internal/guardian — main monitoring loop: unhealthy restart, dependency orphan recovery, orchestration/backup/grace-period guards with per-cycle caching
  • internal/notify — 10-service notification dispatcher (gotify, discord, slack, telegram, pushover, pushbullet, lunasea, webhook, apprise, email)
  • internal/logging — slog-based structured logger
  • internal/metrics — prometheus stub (placeholder)

Key fixes during implementation

  • Nil Filters panic: client.Filters zero value is nil map — all Docker API calls use make(client.Filters).Add(...)
  • Log format: operational logs use fmt.Printf to stdout (not slog) for acceptance test grep compatibility
  • Per-cycle caching: orchestration events and backup container status queried once per cycle, matching shell behavior
  • URL encoding: sendForm() uses url.Values.Encode() instead of raw string concatenation

CI

  • New go job: build, golangci-lint, unit tests (go test -race)
  • Acceptance tests run after Go checks pass
  • GHCR multi-arch build (amd64/arm64) unchanged

Test plan

  • go build ./cmd/guardian compiles clean
  • golangci-lint run ./... passes
  • go test -count=1 ./... — unit tests pass (config + notify)
  • docker build -t docker-guardian . — image builds (23MB)
  • All 6 acceptance test suites pass:
    • Healthcheck Restart (3/3)
    • Dependency Recovery (3/3)
    • Backup Awareness (2/2)
    • Grace Period (2/2)
    • Watchtower Awareness (3/3)
    • Notifications (6/6)

🤖 Generated with Claude Code

Will-Luck and others added 3 commits February 8, 2026 18:20
Full Go project scaffold with all packages that compile clean and pass
golangci-lint. Architecture mirrors the shell script feature set:

- cmd/guardian: entry point, signal handling, main loop
- internal/config: env var → typed Config (all AUTOHEAL_*/NOTIFY_* vars)
- internal/docker: Docker API wrapper (containers, events, inspect)
- internal/guardian: core loop, unhealthy restart, dependency recovery, guards
- internal/notify: multi-service dispatcher (gotify, discord, slack, etc.)
- internal/logging: structured JSON logging via log/slog
- internal/metrics: Prometheus endpoint placeholder

Uses github.com/moby/moby client library. Requires Go 1.24+.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix nil Filters panic (make(client.Filters) instead of zero-value),
switch operational logs from slog to fmt.Printf for test-compatible
output, add per-cycle caching for orchestration events and backup
status, fix URL encoding in sendForm, create multi-stage Go Dockerfile.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CI now runs: go build, golangci-lint, go test -race before acceptance
tests. Unit tests cover event resolution logic, env var parsing, service
detection, and event filtering.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Will-Luck Will-Luck merged commit 040917b into main Feb 8, 2026
3 checks passed
@Will-Luck Will-Luck deleted the v2-go-rewrite branch February 8, 2026 20:44
Will-Luck added a commit that referenced this pull request Feb 10, 2026
v2.0.0: Rewrite in Go
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.

1 participant