Something went wrong. Try again.
Pull-based GitOps-style Docker Compose deployer: polls a (private) Git repo, detects changed stacks and reconciles only the affected
Something went wrong. Try again.
602 B · 30 lines
Go
at main
12345678910111213141516171819202122232425262728293031package core
import ( "errors" "os" "syscall")
func AcquireLock(lockPath string) (func() error, error) { f, err := os.OpenFile(lockPath, os.O_CREATE|os.O_RDWR, 0644) if err != nil { return nil, err }
if err := syscall.Flock(int(f.Fd()), syscall.LOCK_EX|syscall.LOCK_NB); err != nil { _ = f.Close() return nil, errors.New("another compose-sync is already running") }
return func() error { if err := syscall.Flock(int(f.Fd()), syscall.LOCK_UN); err != nil { f.Close() return err } if err := f.Close(); err != nil { return err } return os.Remove(lockPath) }, nil}