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

+35 -4
View File
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"syscall"
"time"
"github.com/dokku/dokku/plugins/common"
@@ -19,11 +20,9 @@ func appNameTaken(appName string) bool {
return common.DirectoryExists(common.AppRoot(appName))
}
// checks if an app is locked
// checks if an app is locked via apps:lock or by an in-progress deploy
func appIsLocked(appName string) bool {
lockPath := getLockPath(appName)
_, err := os.Stat(lockPath)
return !os.IsNotExist(err)
return appIsManuallyLocked(appName) || deployLockHeld(appName)
}
// verifies app name and creates an app
@@ -131,6 +130,38 @@ func getLockPath(appName string) string {
return fmt.Sprintf("%v/.deploy.lock", common.GetAppDataDirectory("apps", appName))
}
// returns the path of the lock created by apps:lock
func getManualLockPath(appName string) string {
return fmt.Sprintf("%v/.manual-deploy.lock", common.GetAppDataDirectory("apps", appName))
}
// checks if an app has been locked via apps:lock
func appIsManuallyLocked(appName string) bool {
_, err := os.Stat(getManualLockPath(appName))
return err == nil
}
// checks if a deploy currently holds the flock on the deploy lock file
//
// a shared lock is attempted and immediately released. Deploys taking the
// lock exclusively wait briefly before failing, so this check does not make
// a concurrent deploy fail.
func deployLockHeld(appName string) bool {
lockFile, err := os.Open(getLockPath(appName))
if err != nil {
return false
}
defer lockFile.Close()
fd := int(lockFile.Fd())
if err := syscall.Flock(fd, syscall.LOCK_SH|syscall.LOCK_NB); err != nil {
return errors.Is(err, syscall.EWOULDBLOCK)
}
_ = syscall.Flock(fd, syscall.LOCK_UN)
return false
}
// creates an app if allowed
func maybeCreateApp(appName string) error {
if err := appExists(appName); err == nil {