Fix CMD Update: Pass the version from ldflags to the client app
- Refactor main to use a common struct for BuildConfig - Adjust NewClientApp and NewServerApp to include BuildConfig in initialization
- commit
- 7eee03d4873f7e18e392b82272743e4abc5501c2
- author
- bnema · · 2023-11-06 16:55 UTC
- parent
- 6ca3069
- signature
- unsigned
4 files · +23 -18
M cmd/cli/main.go +14 -14
| @@ -33,29 +33,29 @@ func Execute(client *cli.App, server *server.App) { | |||
| 33 | 33 | } | |
| 34 | 34 | ||
| 35 | 35 | func main() { | |
| 36 | - | a, err := cli.NewClientApp() | |
| 37 | - | if err != nil { | |
| 38 | - | fmt.Println("Error initializing app:", err) | |
| 39 | - | } | |
| 40 | - | s, err := server.NewServerApp() | |
| 41 | - | if err != nil { | |
| 42 | - | fmt.Println("Error initializing app:", err) | |
| 43 | - | } | |
| 44 | - | ||
| 45 | - | common.DockerInit(&s.Config.ContainerEngine) | |
| 46 | - | ||
| 47 | 36 | build = regexp.MustCompile(`\d+\.\d+\.\d+`).FindString(build) | |
| 48 | - | s.Config.Build = common.BuildConfig{ | |
| 37 | + | buildInfo := common.BuildConfig{ | |
| 49 | 38 | BuildVersion: build, | |
| 50 | 39 | BuildCommit: commit, | |
| 51 | 40 | BuildDate: date, | |
| 52 | 41 | ProxyURL: "https://gordon-proxy.bnema.dev", | |
| 53 | 42 | } | |
| 54 | 43 | ||
| 55 | - | if s.Config.Build.BuildVersion != "" { | |
| 56 | - | fmt.Printf("Gordon version %s\n", s.Config.Build.BuildVersion) | |
| 44 | + | if buildInfo.BuildVersion != "" { | |
| 45 | + | fmt.Printf("Gordon version %s\n", build) | |
| 57 | 46 | } | |
| 58 | 47 | ||
| 48 | + | a, err := cli.NewClientApp(buildInfo) | |
| 49 | + | if err != nil { | |
| 50 | + | fmt.Println("Error initializing app:", err) | |
| 51 | + | } | |
| 52 | + | s, err := server.NewServerApp(buildInfo) | |
| 53 | + | if err != nil { | |
| 54 | + | fmt.Println("Error initializing app:", err) | |
| 55 | + | } | |
| 56 | + | ||
| 57 | + | common.DockerInit(&s.Config.ContainerEngine) | |
| 58 | + | ||
| 59 | 59 | // Check for new version | |
| 60 | 60 | go func() { | |
| 61 | 61 | msg, err := common.CheckVersionPeriodically(&s.Config) | |
| @@ -33,29 +33,29 @@ func Execute(client *cli.App, server *server.App) { | |||||
| 33 | } | 33 | } | ||
| 34 | 34 | ||||
| 35 | func main() { | 35 | func main() { | ||
| 36 | - | a, err := cli.NewClientApp() | |||
| 37 | - | if err != nil { | |||
| 38 | - | fmt.Println("Error initializing app:", err) | |||
| 39 | - | } | |||
| 40 | - | s, err := server.NewServerApp() | |||
| 41 | - | if err != nil { | |||
| 42 | - | fmt.Println("Error initializing app:", err) | |||
| 43 | - | } | |||
| 44 | - | ||||
| 45 | - | common.DockerInit(&s.Config.ContainerEngine) | |||
| 46 | - | ||||
| 47 | build = regexp.MustCompile(`\d+\.\d+\.\d+`).FindString(build) | 36 | build = regexp.MustCompile(`\d+\.\d+\.\d+`).FindString(build) | ||
| 48 | - | s.Config.Build = common.BuildConfig{ | 37 | + | buildInfo := common.BuildConfig{ |
| 49 | BuildVersion: build, | 38 | BuildVersion: build, | ||
| 50 | BuildCommit: commit, | 39 | BuildCommit: commit, | ||
| 51 | BuildDate: date, | 40 | BuildDate: date, | ||
| 52 | ProxyURL: "https://gordon-proxy.bnema.dev", | 41 | ProxyURL: "https://gordon-proxy.bnema.dev", | ||
| 53 | } | 42 | } | ||
| 54 | 43 | ||||
| 55 | - | if s.Config.Build.BuildVersion != "" { | 44 | + | if buildInfo.BuildVersion != "" { |
| 56 | - | fmt.Printf("Gordon version %s\n", s.Config.Build.BuildVersion) | 45 | + | fmt.Printf("Gordon version %s\n", build) |
| 57 | } | 46 | } | ||
| 58 | 47 | ||||
| 48 | + | a, err := cli.NewClientApp(buildInfo) | |||
| 49 | + | if err != nil { | |||
| 50 | + | fmt.Println("Error initializing app:", err) | |||
| 51 | + | } | |||
| 52 | + | s, err := server.NewServerApp(buildInfo) | |||
| 53 | + | if err != nil { | |||
| 54 | + | fmt.Println("Error initializing app:", err) | |||
| 55 | + | } | |||
| 56 | + | ||||
| 57 | + | common.DockerInit(&s.Config.ContainerEngine) | |||
| 58 | + | ||||
| 59 | // Check for new version | 59 | // Check for new version | ||
| 60 | go func() { | 60 | go func() { | ||
| 61 | msg, err := common.CheckVersionPeriodically(&s.Config) | 61 | msg, err := common.CheckVersionPeriodically(&s.Config) | ||
M internal/cli/cmd/update.go +4 -1
| @@ -120,8 +120,11 @@ func (p *plugin) update(withBackup bool) error { | |||
| 120 | 120 | return err | |
| 121 | 121 | } | |
| 122 | 122 | ||
| 123 | + | fmt.Println("Latest version:", latest.Tag) | |
| 124 | + | fmt.Println("Current version:", p.currentVersion) | |
| 125 | + | ||
| 123 | 126 | if compareVersions(strings.TrimPrefix(p.currentVersion, "v"), strings.TrimPrefix(latest.Tag, "v")) <= 0 { | |
| 124 | - | color.Green("You already have the latest PocketBase %s.", p.currentVersion) | |
| 127 | + | color.Green("You already have the latest version %s.", p.currentVersion) | |
| 125 | 128 | return nil | |
| 126 | 129 | } | |
| 127 | 130 | ||
| @@ -120,8 +120,11 @@ func (p *plugin) update(withBackup bool) error { | |||||
| 120 | return err | 120 | return err | ||
| 121 | } | 121 | } | ||
| 122 | 122 | ||||
| 123 | + | fmt.Println("Latest version:", latest.Tag) | |||
| 124 | + | fmt.Println("Current version:", p.currentVersion) | |||
| 125 | + | ||||
| 123 | if compareVersions(strings.TrimPrefix(p.currentVersion, "v"), strings.TrimPrefix(latest.Tag, "v")) <= 0 { | 126 | if compareVersions(strings.TrimPrefix(p.currentVersion, "v"), strings.TrimPrefix(latest.Tag, "v")) <= 0 { | ||
| 124 | - | color.Green("You already have the latest PocketBase %s.", p.currentVersion) | 127 | + | color.Green("You already have the latest version %s.", p.currentVersion) |
| 125 | return nil | 128 | return nil | ||
| 126 | } | 129 | } | ||
| 127 | 130 | ||||
M internal/cli/newclient.go +4 -2
| @@ -11,9 +11,11 @@ type App struct { | |||
| 11 | 11 | } | |
| 12 | 12 | ||
| 13 | 13 | // NewClientApp initializes a new App with configuration. | |
| 14 | - | func NewClientApp() (*App, error) { | |
| 14 | + | func NewClientApp(buildConfig common.BuildConfig) (*App, error) { | |
| 15 | 15 | // Initialize AppConfig | |
| 16 | - | config := common.Config{} | |
| 16 | + | config := common.Config{ | |
| 17 | + | Build: buildConfig, | |
| 18 | + | } | |
| 17 | 19 | _, err := config.LoadConfig() | |
| 18 | 20 | if err != nil { | |
| 19 | 21 | return nil, fmt.Errorf("failed to load configuration: %w", err) | |
| @@ -11,9 +11,11 @@ type App struct { | |||||
| 11 | } | 11 | } | ||
| 12 | 12 | ||||
| 13 | // NewClientApp initializes a new App with configuration. | 13 | // NewClientApp initializes a new App with configuration. | ||
| 14 | - | func NewClientApp() (*App, error) { | 14 | + | func NewClientApp(buildConfig common.BuildConfig) (*App, error) { |
| 15 | // Initialize AppConfig | 15 | // Initialize AppConfig | ||
| 16 | - | config := common.Config{} | 16 | + | config := common.Config{ |
| 17 | + | Build: buildConfig, | |||
| 18 | + | } | |||
| 17 | _, err := config.LoadConfig() | 19 | _, err := config.LoadConfig() | ||
| 18 | if err != nil { | 20 | if err != nil { | ||
| 19 | return nil, fmt.Errorf("failed to load configuration: %w", err) | 21 | return nil, fmt.Errorf("failed to load configuration: %w", err) | ||
M internal/server/newserver.go +1 -1
| @@ -10,7 +10,7 @@ import ( | |||
| 10 | 10 | "github.com/bnema/gordon/internal/webui" | |
| 11 | 11 | ) | |
| 12 | 12 | ||
| 13 | - | func NewServerApp() (*App, error) { | |
| 13 | + | func NewServerApp(common.BuildConfig) (*App, error) { | |
| 14 | 14 | // Initialize AppConfig | |
| 15 | 15 | config := common.Config{} | |
| 16 | 16 | _, err := config.LoadConfig() | |
| @@ -10,7 +10,7 @@ import ( | |||||
| 10 | "github.com/bnema/gordon/internal/webui" | 10 | "github.com/bnema/gordon/internal/webui" | ||
| 11 | ) | 11 | ) | ||
| 12 | 12 | ||||
| 13 | - | func NewServerApp() (*App, error) { | 13 | + | func NewServerApp(common.BuildConfig) (*App, error) { |
| 14 | // Initialize AppConfig | 14 | // Initialize AppConfig | ||
| 15 | config := common.Config{} | 15 | config := common.Config{} | ||
| 16 | _, err := config.LoadConfig() | 16 | _, err := config.LoadConfig() | ||