Skip to content

Latest commit

 

History

History
59 lines (42 loc) · 4.21 KB

AGENTS.md

File metadata and controls

59 lines (42 loc) · 4.21 KB

Nautical Backup — Agent Guide

Overview

Nautical Backup is a Docker-based container backup tool that automatically backs up Docker container data using rsync. It is configured via Docker labels on individual containers or via environment variables on the Nautical container itself.

Active User Base — Backward Compatibility is Critical

~10,000 users run this app, many with auto-updating Docker containers. A push to the main branch can trigger automatic updates for a significant portion of the user base within hours.

  • Every code change must be reviewed for backward compatibility before merging.
  • If a change breaks existing behavior, it must be called out explicitly in the PR and the version bumped using semantic versioning (semver):
    • PATCH (x.x.1) — bug fixes, no behavior change for existing users
    • MINOR (x.1.x) — new features, fully backward-compatible
    • MAJOR (1.x.x) — breaking changes (avoid unless absolutely necessary)

Docs Folder = Source of Truth

The docs/ folder contains the MkDocs user-facing documentation. Read the relevant docs pages before implementing any feature or fix. If the docs describe a behavior, that behavior is the contract with users. If your change affects documented behavior, update the docs too.

Key docs pages:

  • docs/labels.md — all Docker label options (per-container config)
  • docs/arguments.md — all environment variable options (global config)
  • docs/introduction.md — high-level overview
  • app/defaults.env — default environment variable values

Tests — Do Not Change Without Explicit Justification

Tests in pytest/ exist to enforce backward compatibility. Treat them as a contract.

  • Do not modify existing tests unless there is a clear, meaningful reason (e.g., the test was wrong, or the code behavior intentionally changed).
  • If you must change an existing test, call it out explicitly when proposing or describing the change.
  • Adding new tests is always fine and encouraged.
  • When mocking subprocess.run, always set mock_subprocess_run.return_value.returncode = 0 in new tests so the mock behaves like a successful rsync call.

Run tests with: nb pytest (inside the dev environment) or python -m pytest pytest/ locally (excluding pytest/test_api.py if the dev DB is not initialized).

Dev Environment Gotchas

  • Bash init scripts duplicate Python logic. app/entry.sh, env.sh, logger.sh, and utils.sh run during s6-overlay container init, before the Python app starts, and some of them re-implement logic that also exists in Python (e.g. logger.sh's report-file naming mirrors logger.py). If you change one side, update the other and keep them in sync. There is no bash test framework in this repo (no bats/shellcheck), so pytest/ never exercises the bash side — verify bash changes manually (bash -n script.sh at minimum; ideally build the image and run it for real).
  • nb pytest touches real shared dev state, not isolated temp dirs — test_backup.py's retention-policy tests read/write the actual dev/config/nautical-db.json, dev/destination, and dev/source. Don't run nb pytest in two terminals/processes at once; it races on these files and produces spurious JSONDecodeError/Directory not empty failures that look like a real regression but aren't.
  • nb integration needs a manual pre-step. It runs docker compose against a minituff/nautical-test image it never builds itself (that step is commented out in .devcontainer/scripts/nb.sh). Build it first with docker build --build-arg TEST_MODE=0 -t minituff/nautical-test ., matching the separate build step in .github/workflows/test_docker_image.yml.

Codebase Layout

app/
  backup.py          # Core backup orchestration (NauticalBackup class)
  nautical_env.py    # Environment variable parsing (NauticalEnv class)
  api/               # FastAPI REST API
  db.py              # Simple JSON key-value database
  logger.py          # Logging utilities
pytest/              # Test suite
docs/                # MkDocs user documentation