fix(deployer): wire pre-deploy backup into the unified dispatch path
auto_backup_before_deploy silently did nothing — MaybeBackupBeforeDeploy's only caller was the legacy executeDeploy pipeline, removed in the workload-first cutover. Reconnect it as maybeBackupBeforeDeploy(), invoked from DispatchPlugin after the source resolves and before it runs, so the setting fires for every source kind. Fail-open: a nil backuper, a settings-load error, or a backup failure skips the snapshot without blocking the deploy. Adds predeploy_backup_test.go asserting the wiring.
This commit is contained in:
@@ -100,20 +100,34 @@ func (d *Deployer) SetPreDeployBackuper(b PreDeployBackuper) {
|
||||
d.backuper = b
|
||||
}
|
||||
|
||||
// MaybeBackupBeforeDeploy creates a "pre-deploy" Tinyforge DB snapshot when
|
||||
// the setting is enabled. Failures are logged but do not abort the deploy:
|
||||
// missing a backup is preferable to refusing to ship a fix. Exposed so
|
||||
// Source plugins can opt into the same behaviour.
|
||||
func (d *Deployer) MaybeBackupBeforeDeploy(deployID string, settings store.Settings) {
|
||||
if !settings.AutoBackupBeforeDeploy || d.backuper == nil {
|
||||
// maybeBackupBeforeDeploy takes a "pre-deploy" Tinyforge DB snapshot before a
|
||||
// deploy when the operator enabled auto_backup_before_deploy. It is called on
|
||||
// the unified deploy path (DispatchPlugin) so the setting actually fires — its
|
||||
// predecessor was orphaned when the legacy executeDeploy pipeline (its only
|
||||
// caller) was removed in the workload-first cutover, silently disabling the
|
||||
// setting.
|
||||
//
|
||||
// Fail-open: a nil backuper, a settings-load error, or a backup failure all
|
||||
// skip the snapshot without blocking the deploy — missing a backup is
|
||||
// preferable to refusing to ship a fix.
|
||||
func (d *Deployer) maybeBackupBeforeDeploy(workloadID string) {
|
||||
if d.backuper == nil {
|
||||
return
|
||||
}
|
||||
settings, err := d.store.GetSettings()
|
||||
if err != nil {
|
||||
slog.Warn("pre-deploy backup: load settings", "workload", workloadID, "error", err)
|
||||
return
|
||||
}
|
||||
if !settings.AutoBackupBeforeDeploy {
|
||||
return
|
||||
}
|
||||
backup, err := d.backuper.CreateBackup("pre-deploy")
|
||||
if err != nil {
|
||||
slog.Warn("pre-deploy backup failed", "deploy_id", deployID, "error", err)
|
||||
slog.Warn("pre-deploy backup failed", "workload", workloadID, "error", err)
|
||||
return
|
||||
}
|
||||
slog.Info("pre-deploy backup created", "deploy_id", deployID, "backup_id", backup.ID, "filename", backup.Filename)
|
||||
slog.Info("pre-deploy backup created", "workload", workloadID, "backup_id", backup.ID, "filename", backup.Filename)
|
||||
}
|
||||
|
||||
// SetDNSProvider sets the DNS provider for managing DNS records during deployments.
|
||||
|
||||
Reference in New Issue
Block a user