Per-stack auto-update policy on the stack Overview tab. When the background
image-update check finds a newer registry digest for one of a stack's images,
the stack is pulled + redeployed (or just flagged, "notify only"). Only running
stacks are auto-redeployed; a stopped stack is skipped, never silently started.
- models/auto_update.py: AutoUpdate(stack_id, agent_id, enabled, redeploy,
last_run/status/result) + schemas; registered in models/__init__.py.
- update_service: DB-free stack_images/stack_updates helpers (agent reuses
them); agent GET /agent/stacks/{id}/updates.
- services/auto_update_service.py: run_due/run_policy (local pull+up via
compose_service, remote via agent_service POST /agent/stacks/{id}/update,
notify-only with per-transition dedup); lazy-called from
update_service.background_loop. New stack_auto_updated notify event.
- routers: GET/PUT/run /api/stacks/{id}/auto-update and the
/api/agents/{id}/stacks/{sid}/auto-update variants (policy stored centrally).
- frontend: api/autoUpdate.ts + AutoUpdatePanel (enable, redeploy|notify-only,
Check now, last-run status) on StackDetail + RemoteStackDetail; EVENT_LABELS
gains stack_auto_updated + backup_failed.
Live-verified all four paths (updated / update-available / up-to-date /
skipped) against real compose.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
90 lines
2.1 KiB
Python
90 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime, timezone
|
|
from typing import Optional
|
|
|
|
from sqlmodel import Field, SQLModel
|
|
|
|
|
|
def _now() -> datetime:
|
|
return datetime.now(timezone.utc)
|
|
|
|
|
|
# Notification event names ----------------------------------------------------
|
|
EVENT_UPDATE_AVAILABLE = "update_available"
|
|
EVENT_STACK_START = "stack_start"
|
|
EVENT_STACK_STOP = "stack_stop"
|
|
EVENT_STACK_ERROR = "stack_error"
|
|
EVENT_PULL_FAILED = "pull_failed"
|
|
EVENT_BACKUP_FAILED = "backup_failed"
|
|
EVENT_STACK_AUTO_UPDATED = "stack_auto_updated"
|
|
|
|
ALL_EVENTS = [
|
|
EVENT_UPDATE_AVAILABLE,
|
|
EVENT_STACK_START,
|
|
EVENT_STACK_STOP,
|
|
EVENT_STACK_ERROR,
|
|
EVENT_PULL_FAILED,
|
|
EVENT_BACKUP_FAILED,
|
|
EVENT_STACK_AUTO_UPDATED,
|
|
]
|
|
|
|
WEBHOOK_TYPES = ["ntfy", "discord", "slack", "gotify", "generic"]
|
|
|
|
|
|
class Setting(SQLModel, table=True):
|
|
"""Simple key/value store for runtime-tunable settings (JSON-encoded value)."""
|
|
|
|
key: str = Field(primary_key=True)
|
|
value: str # JSON-encoded
|
|
|
|
|
|
class Webhook(SQLModel, table=True):
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
name: str
|
|
url: str
|
|
type: str = "generic" # one of WEBHOOK_TYPES
|
|
events: str = ",".join(ALL_EVENTS) # comma-separated subscribed events
|
|
enabled: bool = True
|
|
created_at: datetime = Field(default_factory=_now)
|
|
|
|
|
|
# --- API schemas ---
|
|
|
|
|
|
class WebhookCreate(SQLModel):
|
|
name: str
|
|
url: str
|
|
type: str = "generic"
|
|
events: list[str] = ALL_EVENTS
|
|
enabled: bool = True
|
|
|
|
|
|
class WebhookUpdate(SQLModel):
|
|
name: Optional[str] = None
|
|
url: Optional[str] = None
|
|
type: Optional[str] = None
|
|
events: Optional[list[str]] = None
|
|
enabled: Optional[bool] = None
|
|
|
|
|
|
class WebhookRead(SQLModel):
|
|
id: int
|
|
name: str
|
|
url: str
|
|
type: str
|
|
events: list[str]
|
|
enabled: bool
|
|
created_at: datetime
|
|
|
|
|
|
class SettingsRead(SQLModel):
|
|
update_check_interval_minutes: int
|
|
env_webhook_count: int
|
|
available_events: list[str]
|
|
webhook_types: list[str]
|
|
|
|
|
|
class SettingsUpdate(SQLModel):
|
|
update_check_interval_minutes: Optional[int] = None
|