feat: improve version checking and logging
- commit
- 7396d261b14801598bbd409a665b7625d4ac78ec
- author
- bnema · · 2024-04-20 15:26 UTC
- parent
- 4db9699
- signature
- unsigned
- refs
- tag: 0.1.23
4 files · +32 -17
A Makefile +19 -0
| @@ -0,0 +1,19 @@ | |||
| 1 | + | # Variables | |
| 2 | + | INSTALL_DIR = /usr/bin | |
| 3 | + | BINARY_NAME = gordon | |
| 4 | + | # Default target | |
| 5 | + | all: build | |
| 6 | + | ||
| 7 | + | # Build the Go binary | |
| 8 | + | build: | |
| 9 | + | go build -o $(BINARY_NAME) cmd/cli/main.go | |
| 10 | + | ||
| 11 | + | # Install the binary to /usr/local/bin | |
| 12 | + | install: | |
| 13 | + | mv $(BINARY_NAME) $(INSTALL_DIR) | |
| 14 | + | ||
| 15 | + | # Clean up the built binary | |
| 16 | + | clean: | |
| 17 | + | rm -f $(BINARY_NAME) | |
| 18 | + | ||
| 19 | + | .PHONY: all build install clean⏎̸ | |
| @@ -0,0 +1,19 @@ | |||||
| 1 | + | # Variables | |||
| 2 | + | INSTALL_DIR = /usr/bin | |||
| 3 | + | BINARY_NAME = gordon | |||
| 4 | + | # Default target | |||
| 5 | + | all: build | |||
| 6 | + | ||||
| 7 | + | # Build the Go binary | |||
| 8 | + | build: | |||
| 9 | + | go build -o $(BINARY_NAME) cmd/cli/main.go | |||
| 10 | + | ||||
| 11 | + | # Install the binary to /usr/local/bin | |||
| 12 | + | install: | |||
| 13 | + | mv $(BINARY_NAME) $(INSTALL_DIR) | |||
| 14 | + | ||||
| 15 | + | # Clean up the built binary | |||
| 16 | + | clean: | |||
| 17 | + | rm -f $(BINARY_NAME) | |||
| 18 | + | ||||
| 19 | + | .PHONY: all build install clean⏎̸ | |||
M cmd/cli/main.go +6 -9
| @@ -46,9 +46,6 @@ func main() { | |||
| 46 | 46 | ProxyURL: os.Getenv("PROXY_URL"), | |
| 47 | 47 | } | |
| 48 | 48 | ||
| 49 | - | // console log proxy url | |
| 50 | - | log.Printf("Proxy URL: %s", buildInfo.ProxyURL) | |
| 51 | - | ||
| 52 | 49 | a, err := cli.NewClientApp(buildInfo) | |
| 53 | 50 | if err != nil { | |
| 54 | 51 | fmt.Println("Error initializing app:", err) | |
| @@ -61,12 +58,12 @@ func main() { | |||
| 61 | 58 | common.DockerInit(&s.Config.ContainerEngine) | |
| 62 | 59 | ||
| 63 | 60 | // Check for new version | |
| 64 | - | //go func() { | |
| 65 | - | //msg, err := common.CheckVersionPeriodically(&s.Config) | |
| 66 | - | //if err != nil || msg != "" { | |
| 67 | - | //log.Printf("CheckVersionPeriodically: %v %s", err, msg) | |
| 68 | - | //} | |
| 69 | - | //}() | |
| 61 | + | go func() { | |
| 62 | + | msg, err := common.CheckVersionPeriodically(&s.Config) | |
| 63 | + | if err != nil || msg != "" { | |
| 64 | + | log.Println(msg) | |
| 65 | + | } | |
| 66 | + | }() | |
| 70 | 67 | ||
| 71 | 68 | Execute(a, s) | |
| 72 | 69 | } | |
| @@ -46,9 +46,6 @@ func main() { | |||||
| 46 | ProxyURL: os.Getenv("PROXY_URL"), | 46 | ProxyURL: os.Getenv("PROXY_URL"), | ||
| 47 | } | 47 | } | ||
| 48 | 48 | ||||
| 49 | - | // console log proxy url | |||
| 50 | - | log.Printf("Proxy URL: %s", buildInfo.ProxyURL) | |||
| 51 | - | ||||
| 52 | a, err := cli.NewClientApp(buildInfo) | 49 | a, err := cli.NewClientApp(buildInfo) | ||
| 53 | if err != nil { | 50 | if err != nil { | ||
| 54 | fmt.Println("Error initializing app:", err) | 51 | fmt.Println("Error initializing app:", err) | ||
| @@ -61,12 +58,12 @@ func main() { | |||||
| 61 | common.DockerInit(&s.Config.ContainerEngine) | 58 | common.DockerInit(&s.Config.ContainerEngine) | ||
| 62 | 59 | ||||
| 63 | // Check for new version | 60 | // Check for new version | ||
| 64 | - | //go func() { | 61 | + | go func() { |
| 65 | - | //msg, err := common.CheckVersionPeriodically(&s.Config) | 62 | + | msg, err := common.CheckVersionPeriodically(&s.Config) |
| 66 | - | //if err != nil || msg != "" { | 63 | + | if err != nil || msg != "" { |
| 67 | - | //log.Printf("CheckVersionPeriodically: %v %s", err, msg) | 64 | + | log.Println(msg) |
| 68 | - | //} | 65 | + | } |
| 69 | - | //}() | 66 | + | }() |
| 70 | 67 | ||||
| 71 | Execute(a, s) | 68 | Execute(a, s) | ||
| 72 | } | 69 | } | ||
M internal/common/version.go +6 -6
| @@ -7,6 +7,7 @@ import ( | |||
| 7 | 7 | "log" | |
| 8 | 8 | "net/http" | |
| 9 | 9 | "runtime" | |
| 10 | + | "strings" | |
| 10 | 11 | "time" | |
| 11 | 12 | ||
| 12 | 13 | "github.com/bnema/gordon/pkg/docker" | |
| @@ -67,6 +68,11 @@ func checkAndUpdateVersion(c *Config) (string, error) { | |||
| 67 | 68 | remoteVersion = remoteVersions.Name | |
| 68 | 69 | } | |
| 69 | 70 | ||
| 71 | + | // Check if remoteVersion is empty or doesn't contain the architecture suffix | |
| 72 | + | if remoteVersion == "" || !strings.Contains(remoteVersion, getArch()) { | |
| 73 | + | return "", fmt.Errorf("remote version not available for architecture %s", getArch()) | |
| 74 | + | } | |
| 75 | + | ||
| 70 | 76 | remoteVersion = remoteVersion[:len(remoteVersion)-len(getArch())-1] | |
| 71 | 77 | message := CheckForNewVersion(localVersion.Version, remoteVersion) | |
| 72 | 78 | ||
| @@ -84,7 +90,6 @@ func checkAndUpdateVersion(c *Config) (string, error) { | |||
| 84 | 90 | } | |
| 85 | 91 | ||
| 86 | 92 | return "", nil | |
| 87 | - | ||
| 88 | 93 | } | |
| 89 | 94 | ||
| 90 | 95 | func CheckVersionPeriodically(c *Config) (string, error) { | |
| @@ -120,11 +125,6 @@ func CheckVersionPeriodically(c *Config) (string, error) { | |||
| 120 | 125 | return "", nil | |
| 121 | 126 | } | |
| 122 | 127 | ||
| 123 | - | // func getLocalVersion(c *Config) CurrentVersion { | |
| 124 | - | // // Dummy implementation, replace with your actual logic | |
| 125 | - | // return CurrentVersion{Version: "0.0.970"} // Example version | |
| 126 | - | // } | |
| 127 | - | ||
| 128 | 128 | func getRemoteVersion(c *Config) (VersionsResponse, error) { | |
| 129 | 129 | proxyURL := c.Build.ProxyURL | |
| 130 | 130 | if proxyURL == "" { | |
| @@ -7,6 +7,7 @@ import ( | |||||
| 7 | "log" | 7 | "log" | ||
| 8 | "net/http" | 8 | "net/http" | ||
| 9 | "runtime" | 9 | "runtime" | ||
| 10 | + | "strings" | |||
| 10 | "time" | 11 | "time" | ||
| 11 | 12 | ||||
| 12 | "github.com/bnema/gordon/pkg/docker" | 13 | "github.com/bnema/gordon/pkg/docker" | ||
| @@ -67,6 +68,11 @@ func checkAndUpdateVersion(c *Config) (string, error) { | |||||
| 67 | remoteVersion = remoteVersions.Name | 68 | remoteVersion = remoteVersions.Name | ||
| 68 | } | 69 | } | ||
| 69 | 70 | ||||
| 71 | + | // Check if remoteVersion is empty or doesn't contain the architecture suffix | |||
| 72 | + | if remoteVersion == "" || !strings.Contains(remoteVersion, getArch()) { | |||
| 73 | + | return "", fmt.Errorf("remote version not available for architecture %s", getArch()) | |||
| 74 | + | } | |||
| 75 | + | ||||
| 70 | remoteVersion = remoteVersion[:len(remoteVersion)-len(getArch())-1] | 76 | remoteVersion = remoteVersion[:len(remoteVersion)-len(getArch())-1] | ||
| 71 | message := CheckForNewVersion(localVersion.Version, remoteVersion) | 77 | message := CheckForNewVersion(localVersion.Version, remoteVersion) | ||
| 72 | 78 | ||||
| @@ -84,7 +90,6 @@ func checkAndUpdateVersion(c *Config) (string, error) { | |||||
| 84 | } | 90 | } | ||
| 85 | 91 | ||||
| 86 | return "", nil | 92 | return "", nil | ||
| 87 | - | ||||
| 88 | } | 93 | } | ||
| 89 | 94 | ||||
| 90 | func CheckVersionPeriodically(c *Config) (string, error) { | 95 | func CheckVersionPeriodically(c *Config) (string, error) { | ||
| @@ -120,11 +125,6 @@ func CheckVersionPeriodically(c *Config) (string, error) { | |||||
| 120 | return "", nil | 125 | return "", nil | ||
| 121 | } | 126 | } | ||
| 122 | 127 | ||||
| 123 | - | // func getLocalVersion(c *Config) CurrentVersion { | |||
| 124 | - | // // Dummy implementation, replace with your actual logic | |||
| 125 | - | // return CurrentVersion{Version: "0.0.970"} // Example version | |||
| 126 | - | // } | |||
| 127 | - | ||||
| 128 | func getRemoteVersion(c *Config) (VersionsResponse, error) { | 128 | func getRemoteVersion(c *Config) (VersionsResponse, error) { | ||
| 129 | proxyURL := c.Build.ProxyURL | 129 | proxyURL := c.Build.ProxyURL | ||
| 130 | if proxyURL == "" { | 130 | if proxyURL == "" { | ||
M internal/server/sqliteinit.go +1 -2
| @@ -17,6 +17,7 @@ const ( | |||
| 17 | 17 | ||
| 18 | 18 | func (a *App) getDiskDBFilePath() string { | |
| 19 | 19 | DiskDBfilepath := filepath.Join(a.DBDir, a.DBFilename) | |
| 20 | + | // if a.DBDir is empty return log "Set a path using storageDir in the config file" | |
| 20 | 21 | return DiskDBfilepath | |
| 21 | 22 | } | |
| 22 | 23 | ||
| @@ -59,7 +60,6 @@ func InitializeDB(a *App) (*sql.DB, error) { | |||
| 59 | 60 | } | |
| 60 | 61 | } | |
| 61 | 62 | ||
| 62 | - | // Change here from "sqlite3" to "sqlite" | |
| 63 | 63 | db, err := sql.Open("sqlite", dbPath) | |
| 64 | 64 | if err != nil { | |
| 65 | 65 | return nil, fmt.Errorf("failed to open disk DB: %w", err) | |
| @@ -78,7 +78,6 @@ func InitializeDB(a *App) (*sql.DB, error) { | |||
| 78 | 78 | } | |
| 79 | 79 | ||
| 80 | 80 | func bootstrapDB(dbPath string, app *App) error { | |
| 81 | - | // Change here from "sqlite3" to "sqlite" | |
| 82 | 81 | db, err := sql.Open("sqlite", dbPath) | |
| 83 | 82 | if err != nil { | |
| 84 | 83 | return err | |
| @@ -17,6 +17,7 @@ const ( | |||||
| 17 | 17 | ||||
| 18 | func (a *App) getDiskDBFilePath() string { | 18 | func (a *App) getDiskDBFilePath() string { | ||
| 19 | DiskDBfilepath := filepath.Join(a.DBDir, a.DBFilename) | 19 | DiskDBfilepath := filepath.Join(a.DBDir, a.DBFilename) | ||
| 20 | + | // if a.DBDir is empty return log "Set a path using storageDir in the config file" | |||
| 20 | return DiskDBfilepath | 21 | return DiskDBfilepath | ||
| 21 | } | 22 | } | ||
| 22 | 23 | ||||
| @@ -59,7 +60,6 @@ func InitializeDB(a *App) (*sql.DB, error) { | |||||
| 59 | } | 60 | } | ||
| 60 | } | 61 | } | ||
| 61 | 62 | ||||
| 62 | - | // Change here from "sqlite3" to "sqlite" | |||
| 63 | db, err := sql.Open("sqlite", dbPath) | 63 | db, err := sql.Open("sqlite", dbPath) | ||
| 64 | if err != nil { | 64 | if err != nil { | ||
| 65 | return nil, fmt.Errorf("failed to open disk DB: %w", err) | 65 | return nil, fmt.Errorf("failed to open disk DB: %w", err) | ||
| @@ -78,7 +78,6 @@ func InitializeDB(a *App) (*sql.DB, error) { | |||||
| 78 | } | 78 | } | ||
| 79 | 79 | ||||
| 80 | func bootstrapDB(dbPath string, app *App) error { | 80 | func bootstrapDB(dbPath string, app *App) error { | ||
| 81 | - | // Change here from "sqlite3" to "sqlite" | |||
| 82 | db, err := sql.Open("sqlite", dbPath) | 81 | db, err := sql.Open("sqlite", dbPath) | ||
| 83 | if err != nil { | 82 | if err != nil { | ||
| 84 | return err | 83 | return err | ||