Skip to content

refactor: migrate to lockgate #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 0 additions & 50 deletions cmd/trx/lock.go

This file was deleted.

2 changes: 0 additions & 2 deletions cmd/trx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ By default, it uses the ./trx.yaml configuration file, but you can specify a dif
rootCmd.Flags().BoolVarP(&force, "force", "f", false, "Force execution if no new version found")
rootCmd.Flags().BoolVarP(&disableLock, "disable-lock", "", false, "Disable execution locking")

rootCmd.AddCommand(forceUnlockCmd())

if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
}
Expand Down
28 changes: 6 additions & 22 deletions cmd/trx/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,12 @@ func run(opts runOptions) error {
return fmt.Errorf("init storage error: %w", err)
}

if !disableLock {
locker := lock.NewLocker(storage, disableLock)
if err := locker.CheckLock(); err != nil {
var locked *lock.ErrLocked
if errors.As(err, &locked) {
log.Printf("Execution is locked by %s at %s\n", locked.User, locked.CreatedAt)
return nil
}
return fmt.Errorf("check lock error: %w", err)
}
err := locker.Lock()
if err != nil {
return fmt.Errorf("lock error: %w", err)
}
log.Println("Excution lock acquired")
defer func() {
err := locker.Unlock()
if err != nil {
log.Println("Unlock error: %w", err)
}
log.Println("Execution lock released")
}()
locker := lock.NewManager(lock.NewLocalLocker(disableLock))
if err := locker.Acquire(cfg.Repo.Url); err != nil {
return fmt.Errorf("lock acquire error: %w", err)
}
if disableLock {
log.Println("Processing without execution lock")
}

gitClient, err := git.NewGitClient(cfg.Repo)
Expand Down
33 changes: 18 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/go-hclog v1.6.3
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.10.0
golang.org/x/sync v0.12.0
golang.org/x/sync v0.10.0
)

require (
Expand All @@ -30,10 +30,12 @@ require (
github.com/go-git/go-billy/v5 v5.6.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gookit/color v1.5.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-kms-wrapping/entropy/v2 v2.0.0 // indirect
Expand All @@ -55,27 +57,27 @@ require (
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/onsi/ginkgo/v2 v2.23.0 // indirect
github.com/pierrec/lz4 v2.5.2+incompatible // indirect
github.com/pjbgf/sha1cd v0.3.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.3.0 // indirect
github.com/werf/logboek v0.5.5 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/werf/logboek v0.6.1 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
golang.org/x/crypto v0.33.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/term v0.29.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/term v0.28.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/grpc v1.66.3 // indirect
google.golang.org/protobuf v1.36.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)

Expand All @@ -86,7 +88,6 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0
github.com/onsi/gomega v1.36.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand All @@ -96,12 +97,14 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/werf/trdl/server v0.0.0-20250121125358-ad0ef5178f9b
github.com/werf/common-go v0.0.0-20250317135621-3a6772a9f88d
github.com/werf/lockgate v0.1.1
github.com/werf/trdl/server v0.0.0-20250314141720-5f76cb564636
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading