fix: release deploy locks on exit and honor apps:lock

A deploy that exited before releasing its lock, such as after a failed build, left `.deploy.lock` behind, so `apps:locked` reported a lock nothing held and the build record stayed running. The lock is now released and the record finalized whenever the deploy exits. `apps:lock` never actually blocked deploys, as it only created the file deploys lock. It now creates its own lock that git pushes, `ps:rebuild`, `git:sync`, and the `git:from-*` commands refuse to deploy past, and `apps:locked` only reports a lock when the app was locked via `apps:lock` or a deploy is in progress. Locks created by `apps:lock` in older versions are migrated on install.
This commit is contained in:
Jose Diaz-Gonzalez committed 2026-10-24 13:58:47 -04:00
1 parent 57ae817dab
commit c4b164a270
17 files changed
+535 -69

No files matched your search

+44 -2
View File
@@ -83,6 +83,40 @@ func TriggerInstall() error {
}
}
for _, appName := range apps {
if err := migrateManualLock(appName); err != nil {
return err
}
}
return nil
}
// migrateManualLock converts a lock created by apps:lock before manual locks
// had their own file. Deploys write their build id into the deploy lock file,
// so an empty one that no deploy holds was created by apps:lock.
func migrateManualLock(appName string) error {
lockPath := getLockPath(appName)
fi, err := os.Stat(lockPath)
if err != nil || fi.Size() != 0 || deployLockHeld(appName) {
return nil
}
if err := os.Rename(lockPath, getManualLockPath(appName)); err != nil {
return fmt.Errorf("Unable to migrate the deploy lock for %s: %w", appName, err)
}
return nil
}
// removeLockFiles removes the given lock files, ignoring ones that do not exist
func removeLockFiles(lockPaths ...string) error {
for _, lockPath := range lockPaths {
if err := os.Remove(lockPath); err != nil && !os.IsNotExist(err) {
return err
}
}
return nil
}
@@ -93,7 +127,11 @@ func TriggerPostAppCloneSetup(oldAppName string, newAppName string) error {
return err
}
return common.CloneAppData("apps", oldAppName, newAppName)
if err := common.CloneAppData("apps", oldAppName, newAppName); err != nil {
return err
}
return removeLockFiles(getManualLockPath(newAppName), getLockPath(newAppName))
}
// TriggerPostAppRename removes the old app data
@@ -111,7 +149,11 @@ func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
return err
}
return common.CloneAppData("apps", oldAppName, newAppName)
if err := common.CloneAppData("apps", oldAppName, newAppName); err != nil {
return err
}
return removeLockFiles(getLockPath(newAppName))
}
// TriggerPostCreate ensures apps have the correct data directory structure