From 47e53dffb7c60c900406de2d2d6f6503ac9eb0c2 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sat, 22 Jun 2024 17:49:56 +0200 Subject: [PATCH] Switch to using latest mediocre-go-lib --- default.nix | 2 +- go/bootstrap/garage_global_bucket.go | 4 +-- go/cmd/entrypoint/admin.go | 2 +- go/cmd/entrypoint/daemon.go | 4 +-- go/cmd/entrypoint/garage_util.go | 2 +- go/cmd/entrypoint/hosts.go | 2 +- go/cmd/entrypoint/jigs.go | 47 ++++++++++++++++++++++++++++ go/cmd/entrypoint/logger.go | 4 +-- go/cmd/entrypoint/main.go | 30 +++++++++++++----- go/cmd/entrypoint/proc_lock.go | 4 +-- go/cmd/entrypoint/sub_cmd.go | 2 +- go/daemon/child_garage.go | 4 +-- go/daemon/daemon.go | 2 +- go/daemon/global_bucket.go | 2 +- go/daemon/jsonrpc2/handler.go | 4 +-- go/daemon/jsonrpc2/jsonrpc2_test.go | 2 +- go/garage/admin_client.go | 4 +-- go/go.mod | 6 ++-- go/go.sum | 4 +-- 19 files changed, 96 insertions(+), 35 deletions(-) create mode 100644 go/cmd/entrypoint/jigs.go diff --git a/default.nix b/default.nix index a7f3cbc..242f9ef 100644 --- a/default.nix +++ b/default.nix @@ -69,7 +69,7 @@ in rec { ''; }; - vendorHash = "sha256-33gwBj+6x9I/yz0Qf4G8YXRgC/HfwHCedqzrCE4FHHk="; + vendorHash = "sha256-heXFvEea3u3zvdUvVxlI+FTxqEeImoXd1sqdJJTASoc="; subPackages = [ "./cmd/entrypoint" diff --git a/go/bootstrap/garage_global_bucket.go b/go/bootstrap/garage_global_bucket.go index 9207757..ec1b344 100644 --- a/go/bootstrap/garage_global_bucket.go +++ b/go/bootstrap/garage_global_bucket.go @@ -7,8 +7,8 @@ import ( "isle/garage" "path/filepath" - "github.com/mediocregopher/mediocre-go-lib/v2/mctx" - "github.com/mediocregopher/mediocre-go-lib/v2/mlog" + "dev.mediocregopher.com/mediocre-go-lib.git/mctx" + "dev.mediocregopher.com/mediocre-go-lib.git/mlog" "github.com/minio/minio-go/v7" ) diff --git a/go/cmd/entrypoint/admin.go b/go/cmd/entrypoint/admin.go index b0c9e09..fbb1448 100644 --- a/go/cmd/entrypoint/admin.go +++ b/go/cmd/entrypoint/admin.go @@ -14,7 +14,7 @@ import ( "os" "strings" - "github.com/mediocregopher/mediocre-go-lib/v2/mlog" + "dev.mediocregopher.com/mediocre-go-lib.git/mlog" ) func randStr(l int) string { diff --git a/go/cmd/entrypoint/daemon.go b/go/cmd/entrypoint/daemon.go index 68bd62d..3a3f956 100644 --- a/go/cmd/entrypoint/daemon.go +++ b/go/cmd/entrypoint/daemon.go @@ -12,8 +12,8 @@ import ( "isle/bootstrap" "isle/daemon" - "github.com/mediocregopher/mediocre-go-lib/v2/mctx" - "github.com/mediocregopher/mediocre-go-lib/v2/mlog" + "dev.mediocregopher.com/mediocre-go-lib.git/mctx" + "dev.mediocregopher.com/mediocre-go-lib.git/mlog" ) // The daemon sub-command deals with starting an actual isle daemon diff --git a/go/cmd/entrypoint/garage_util.go b/go/cmd/entrypoint/garage_util.go index 6c63865..826960d 100644 --- a/go/cmd/entrypoint/garage_util.go +++ b/go/cmd/entrypoint/garage_util.go @@ -7,7 +7,7 @@ import ( "isle/daemon" "isle/garage" - "github.com/mediocregopher/mediocre-go-lib/v2/mlog" + "dev.mediocregopher.com/mediocre-go-lib.git/mlog" ) func garageInitializeGlobalBucket( diff --git a/go/cmd/entrypoint/hosts.go b/go/cmd/entrypoint/hosts.go index 16207d6..856128a 100644 --- a/go/cmd/entrypoint/hosts.go +++ b/go/cmd/entrypoint/hosts.go @@ -9,7 +9,7 @@ import ( "regexp" "sort" - "github.com/mediocregopher/mediocre-go-lib/v2/mlog" + "dev.mediocregopher.com/mediocre-go-lib.git/mlog" ) var hostNameRegexp = regexp.MustCompile(`^[a-z][a-z0-9\-]*$`) diff --git a/go/cmd/entrypoint/jigs.go b/go/cmd/entrypoint/jigs.go new file mode 100644 index 0000000..b8ba318 --- /dev/null +++ b/go/cmd/entrypoint/jigs.go @@ -0,0 +1,47 @@ +package main + +import ( + "errors" + "fmt" + "io/fs" + "os" + "slices" + "strings" +) + +func envOr(name string, fallback func() string) string { + if v := os.Getenv(name); v != "" { + return v + } + return fallback() +} + +func firstExistingDir(paths ...string) (string, error) { + var errs []error + for _, path := range paths { + stat, err := os.Stat(path) + switch { + case errors.Is(err, fs.ErrExist): + continue + case err != nil: + errs = append( + errs, fmt.Errorf("checking if path %q exists: %w", path, err), + ) + case !stat.IsDir(): + errs = append( + errs, fmt.Errorf("path %q exists but is not a directory", path), + ) + default: + return path, nil + } + } + + err := fmt.Errorf( + "no directory found at any of the following paths: %s", + strings.Join(paths, ", "), + ) + if len(errs) > 0 { + err = errors.Join(slices.Insert(errs, 0, err)...) + } + return "", err +} diff --git a/go/cmd/entrypoint/logger.go b/go/cmd/entrypoint/logger.go index ced9e77..a9a9510 100644 --- a/go/cmd/entrypoint/logger.go +++ b/go/cmd/entrypoint/logger.go @@ -6,8 +6,8 @@ import ( "path" "sync" - "github.com/mediocregopher/mediocre-go-lib/v2/mctx" - "github.com/mediocregopher/mediocre-go-lib/v2/mlog" + "dev.mediocregopher.com/mediocre-go-lib.git/mctx" + "dev.mediocregopher.com/mediocre-go-lib.git/mlog" ) type logMsgHandler struct { diff --git a/go/cmd/entrypoint/main.go b/go/cmd/entrypoint/main.go index 111d037..7be5129 100644 --- a/go/cmd/entrypoint/main.go +++ b/go/cmd/entrypoint/main.go @@ -2,14 +2,15 @@ package main import ( "context" + "fmt" "os" "os/signal" "path/filepath" "syscall" "github.com/adrg/xdg" - "github.com/mediocregopher/mediocre-go-lib/v2/mctx" - "github.com/mediocregopher/mediocre-go-lib/v2/mlog" + "dev.mediocregopher.com/mediocre-go-lib.git/mctx" + "dev.mediocregopher.com/mediocre-go-lib.git/mlog" ) // The purpose of this binary is to act as the entrypoint of the isle @@ -25,11 +26,18 @@ func getAppDirPath() string { return appDirPath } -func envOr(name, fallback string) string { - if v := os.Getenv(name); v != "" { - return v +func getRPCSocketDirPath() string { + path, err := firstExistingDir( + "/run", + "/var/run", + "/tmp", + "/dev/shm", + ) + if err != nil { + panic(fmt.Sprintf("Failed to find directory for RPC socket: %v", err)) } - return fallback + + return path } // RUNTIME_DIRECTORY/STATE_DIRECTORY are used by the systemd service in @@ -38,13 +46,19 @@ var ( envAppDirPath = getAppDirPath() envRuntimeDirPath = envOr( "RUNTIME_DIRECTORY", - filepath.Join(xdg.RuntimeDir, "isle"), + func() string { return filepath.Join(xdg.RuntimeDir, "isle") }, ) envStateDirPath = envOr( "STATE_DIRECTORY", - filepath.Join(xdg.StateHome, "isle"), + func() string { return filepath.Join(xdg.StateHome, "isle") }, ) envBinDirPath = filepath.Join(envAppDirPath, "bin") + envSocketPath = envOr( + "ISLE_SOCKET_PATH", + func() string { + return filepath.Join(getRPCSocketDirPath(), "isle-daemon.sock") + }, + ) ) func binPath(name string) string { diff --git a/go/cmd/entrypoint/proc_lock.go b/go/cmd/entrypoint/proc_lock.go index 5c4e7b7..862bc76 100644 --- a/go/cmd/entrypoint/proc_lock.go +++ b/go/cmd/entrypoint/proc_lock.go @@ -8,8 +8,8 @@ import ( "os" "path/filepath" - "github.com/mediocregopher/mediocre-go-lib/v2/mctx" - "github.com/mediocregopher/mediocre-go-lib/v2/mlog" + "dev.mediocregopher.com/mediocre-go-lib.git/mctx" + "dev.mediocregopher.com/mediocre-go-lib.git/mlog" "github.com/shirou/gopsutil/process" ) diff --git a/go/cmd/entrypoint/sub_cmd.go b/go/cmd/entrypoint/sub_cmd.go index d3df776..de3e09f 100644 --- a/go/cmd/entrypoint/sub_cmd.go +++ b/go/cmd/entrypoint/sub_cmd.go @@ -6,7 +6,7 @@ import ( "os" "strings" - "github.com/mediocregopher/mediocre-go-lib/v2/mlog" + "dev.mediocregopher.com/mediocre-go-lib.git/mlog" "github.com/spf13/pflag" ) diff --git a/go/daemon/child_garage.go b/go/daemon/child_garage.go index 538b026..298980e 100644 --- a/go/daemon/child_garage.go +++ b/go/daemon/child_garage.go @@ -11,8 +11,8 @@ import ( "strconv" "code.betamike.com/micropelago/pmux/pmuxlib" - "github.com/mediocregopher/mediocre-go-lib/v2/mctx" - "github.com/mediocregopher/mediocre-go-lib/v2/mlog" + "dev.mediocregopher.com/mediocre-go-lib.git/mctx" + "dev.mediocregopher.com/mediocre-go-lib.git/mlog" ) func garageAdminClientLogger(logger *mlog.Logger) *mlog.Logger { diff --git a/go/daemon/daemon.go b/go/daemon/daemon.go index 867a75c..5dbd018 100644 --- a/go/daemon/daemon.go +++ b/go/daemon/daemon.go @@ -11,7 +11,7 @@ import ( "time" "code.betamike.com/micropelago/pmux/pmuxlib" - "github.com/mediocregopher/mediocre-go-lib/v2/mlog" + "dev.mediocregopher.com/mediocre-go-lib.git/mlog" ) type daemon struct { diff --git a/go/daemon/global_bucket.go b/go/daemon/global_bucket.go index e1764f0..7fda231 100644 --- a/go/daemon/global_bucket.go +++ b/go/daemon/global_bucket.go @@ -10,7 +10,7 @@ import ( "isle/nebula" "path/filepath" - "github.com/mediocregopher/mediocre-go-lib/v2/mctx" + "dev.mediocregopher.com/mediocre-go-lib.git/mctx" "github.com/minio/minio-go/v7" ) diff --git a/go/daemon/jsonrpc2/handler.go b/go/daemon/jsonrpc2/handler.go index aabaffe..32f705d 100644 --- a/go/daemon/jsonrpc2/handler.go +++ b/go/daemon/jsonrpc2/handler.go @@ -4,8 +4,8 @@ import ( "context" "errors" - "github.com/mediocregopher/mediocre-go-lib/v2/mctx" - "github.com/mediocregopher/mediocre-go-lib/v2/mlog" + "dev.mediocregopher.com/mediocre-go-lib.git/mctx" + "dev.mediocregopher.com/mediocre-go-lib.git/mlog" ) // Handler is any type which is capable of handling arbitrary RPC calls. The diff --git a/go/daemon/jsonrpc2/jsonrpc2_test.go b/go/daemon/jsonrpc2/jsonrpc2_test.go index 75601ff..02a9427 100644 --- a/go/daemon/jsonrpc2/jsonrpc2_test.go +++ b/go/daemon/jsonrpc2/jsonrpc2_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - "github.com/mediocregopher/mediocre-go-lib/v2/mlog" + "dev.mediocregopher.com/mediocre-go-lib.git/mlog" ) type DivideParams struct { diff --git a/go/garage/admin_client.go b/go/garage/admin_client.go index f5b5f21..0505b00 100644 --- a/go/garage/admin_client.go +++ b/go/garage/admin_client.go @@ -10,8 +10,8 @@ import ( "net/http/httputil" "time" - "github.com/mediocregopher/mediocre-go-lib/v2/mctx" - "github.com/mediocregopher/mediocre-go-lib/v2/mlog" + "dev.mediocregopher.com/mediocre-go-lib.git/mctx" + "dev.mediocregopher.com/mediocre-go-lib.git/mlog" ) // BucketID is a unique identifier for a bucket in garage. It is different than diff --git a/go/go.mod b/go/go.mod index 66af9b3..8c1aa46 100644 --- a/go/go.mod +++ b/go/go.mod @@ -4,14 +4,14 @@ go 1.22 require ( code.betamike.com/micropelago/pmux v0.0.0-20230706154656-fde8c2be7540 + dev.mediocregopher.com/mediocre-go-lib.git v0.0.0-20240511135822-4ab1176672d7 github.com/adrg/xdg v0.4.0 github.com/imdario/mergo v0.3.12 - github.com/mediocregopher/mediocre-go-lib/v2 v2.0.0-beta.1.0.20221113151154-07f3889a705b + github.com/jxskiss/base62 v1.1.0 github.com/minio/minio-go/v7 v7.0.28 github.com/shirou/gopsutil v3.21.11+incompatible github.com/slackhq/nebula v1.6.1 github.com/spf13/pflag v1.0.5 - golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 gopkg.in/yaml.v3 v3.0.1 ) @@ -23,7 +23,6 @@ require ( github.com/gopherjs/gopherjs v1.17.2 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/jtolds/gls v4.20.0+incompatible // indirect - github.com/jxskiss/base62 v1.1.0 // indirect github.com/klauspost/compress v1.13.5 // indirect github.com/klauspost/cpuid v1.3.1 // indirect github.com/minio/md5-simd v1.1.0 // indirect @@ -37,6 +36,7 @@ require ( github.com/tklauser/go-sysconf v0.3.10 // indirect github.com/tklauser/numcpus v0.4.0 // indirect github.com/yusufpapurcu/wmi v1.2.2 // indirect + golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 // indirect golang.org/x/net v0.0.0-20220403103023-749bd193bc2b // indirect golang.org/x/sys v0.0.0-20220406155245-289d7a0edf71 // indirect golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 // indirect diff --git a/go/go.sum b/go/go.sum index e08bef0..1fc8a4b 100644 --- a/go/go.sum +++ b/go/go.sum @@ -1,5 +1,7 @@ code.betamike.com/micropelago/pmux v0.0.0-20230706154656-fde8c2be7540 h1:ycD1mEkCbrx3Apr71Q2PKgyycRu8wvwX9J4ZSvjyTtQ= code.betamike.com/micropelago/pmux v0.0.0-20230706154656-fde8c2be7540/go.mod h1:WlEWacLREVfIQl1IlBjKzuDgL56DFRvyl7YiL5gGP4w= +dev.mediocregopher.com/mediocre-go-lib.git v0.0.0-20240511135822-4ab1176672d7 h1:wKQ3bXzG+KQDtRAN/xaRZ4aQtJe1pccleG6V43MvFxw= +dev.mediocregopher.com/mediocre-go-lib.git v0.0.0-20240511135822-4ab1176672d7/go.mod h1:nP+AtQWrc3k5qq5y3ABiBLkOfUPlk/FO9fpTFpF+jgs= github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls= github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -36,8 +38,6 @@ github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/mediocregopher/mediocre-go-lib/v2 v2.0.0-beta.1.0.20221113151154-07f3889a705b h1:A+IqPY72GXChyCje7YqnZrb8Q4ajUqft/etsmIOobu4= -github.com/mediocregopher/mediocre-go-lib/v2 v2.0.0-beta.1.0.20221113151154-07f3889a705b/go.mod h1:wOZVlnKYvIbkzyCJ3dxy1k40XkirvCd1pisX2O91qoQ= github.com/minio/md5-simd v1.1.0 h1:QPfiOqlZH+Cj9teu0t9b1nTBfPbyTl16Of5MeuShdK4= github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw= github.com/minio/minio-go/v7 v7.0.28 h1:VMr3K5qGIEt+/KW3poopRh8mzi5RwuCjmrmstK196Fg=