From 73c71d3ff2f5344d6ead6f5cfea9eb7491a1c42e Mon Sep 17 00:00:00 2001 From: Paul Lorenz Date: Mon, 30 Oct 2023 12:08:27 -0400 Subject: [PATCH] Properly handle installing and running 'latest' ziti binaries --- common/getziti/github.go | 27 +++++++++++++++-------- common/getziti/install_ziti.go | 18 ++------------- zititest/zitilab/component_controller.go | 2 +- zititest/zitilab/component_echo_server.go | 2 +- zititest/zitilab/component_router.go | 2 +- zititest/zitilab/component_zcat.go | 2 +- zititest/zitilab/component_ziti_tunnel.go | 2 +- 7 files changed, 25 insertions(+), 30 deletions(-) diff --git a/common/getziti/github.go b/common/getziti/github.go index e9dcee8ea..ae7c6a787 100644 --- a/common/getziti/github.go +++ b/common/getziti/github.go @@ -178,15 +178,21 @@ func DownloadGitHubReleaseAsset(fullUrl string, filepath string) (err error) { } func FindVersionAndInstallGitHubRelease(zitiApp string, zitiAppGitHub string, targetOS, targetArch string, binDir string, version string, verbose bool) error { - if version != "" { + releaseVersion := version + if version != "" && version != "latest" { if _, err := semver.Make(strings.TrimPrefix(version, "v")); err != nil { return err } } else { version = "latest" + v, err := GetLatestGitHubReleaseVersion(zitiApp, verbose) + if err != nil { + return err + } + releaseVersion = v.String() } - release, err := GetLatestGitHubReleaseAsset(zitiApp, zitiAppGitHub, version, verbose) + release, err := GetLatestGitHubReleaseAsset(zitiApp, zitiAppGitHub, releaseVersion, verbose) if err != nil { return err } @@ -248,14 +254,17 @@ func InstallGitHubRelease(zitiApp string, release *GitHubReleasesData, binDir st if zitiApp == c.ZITI { count := 0 zitiFileName := "ziti-" + version - semVer, err := versions.ParseSemVer(version) - if err != nil { - return err - } expectedPath := "ziti" - pathChangedVersion := versions.MustParseSemVer("0.29.0") - if semVer.CompareTo(pathChangedVersion) < 0 { - expectedPath = "ziti/ziti" + if version != "latest" { + semVer, err := versions.ParseSemVer(version) + if err != nil { + return err + } + + pathChangedVersion := versions.MustParseSemVer("0.29.0") + if semVer.CompareTo(pathChangedVersion) < 0 { + expectedPath = "ziti/ziti" + } } err = UnTarGz(fullPath, binDir, func(path string) (string, bool) { if path == expectedPath { diff --git a/common/getziti/install_ziti.go b/common/getziti/install_ziti.go index ecb285c2b..9ab194979 100644 --- a/common/getziti/install_ziti.go +++ b/common/getziti/install_ziti.go @@ -2,25 +2,11 @@ package getziti import ( "fmt" - "github.com/blang/semver" c "github.com/openziti/ziti/ziti/constants" - "strings" ) func InstallZiti(targetVersion, targetOS, targetArch, binDir string, verbose bool) error { - var newVersion semver.Version - - if targetVersion != "" { - newVersion = semver.MustParse(strings.TrimPrefix(targetVersion, "v")) - } else { - v, err := GetLatestGitHubReleaseVersion(c.ZITI, verbose) - if err != nil { - return err - } - newVersion = v - } - - fmt.Println("Attempting to install '" + c.ZITI + "' version: v" + newVersion.String()) + fmt.Println("Attempting to install '" + c.ZITI + "' version: " + targetVersion) return FindVersionAndInstallGitHubRelease( - c.ZITI, c.ZITI, targetOS, targetArch, binDir, "v"+newVersion.String(), verbose) + c.ZITI, c.ZITI, targetOS, targetArch, binDir, targetVersion, verbose) } diff --git a/zititest/zitilab/component_controller.go b/zititest/zitilab/component_controller.go index acf52db12..65e6382c7 100644 --- a/zititest/zitilab/component_controller.go +++ b/zititest/zitilab/component_controller.go @@ -47,7 +47,7 @@ type ControllerType struct { } func (self *ControllerType) InitType(*model.Component) { - if self.Version != "" && !strings.HasPrefix(self.Version, "v") { + if self.Version != "" && self.Version != "latest" && !strings.HasPrefix(self.Version, "v") { self.Version = "v" + self.Version } } diff --git a/zititest/zitilab/component_echo_server.go b/zititest/zitilab/component_echo_server.go index 9d6422f98..b0425c42d 100644 --- a/zititest/zitilab/component_echo_server.go +++ b/zititest/zitilab/component_echo_server.go @@ -18,7 +18,7 @@ type EchoServerType struct { } func (self *EchoServerType) InitType(*model.Component) { - if self.Version != "" && !strings.HasPrefix(self.Version, "v") { + if self.Version != "" && self.Version != "latest" && !strings.HasPrefix(self.Version, "v") { self.Version = "v" + self.Version } } diff --git a/zititest/zitilab/component_router.go b/zititest/zitilab/component_router.go index 6eaf219ba..73d1f1f3f 100644 --- a/zititest/zitilab/component_router.go +++ b/zititest/zitilab/component_router.go @@ -45,7 +45,7 @@ type RouterType struct { } func (self *RouterType) InitType(*model.Component) { - if self.Version != "" && !strings.HasPrefix(self.Version, "v") { + if self.Version != "" && self.Version != "latest" && !strings.HasPrefix(self.Version, "v") { self.Version = "v" + self.Version } } diff --git a/zititest/zitilab/component_zcat.go b/zititest/zitilab/component_zcat.go index fabb46a29..d7e5f3645 100644 --- a/zititest/zitilab/component_zcat.go +++ b/zititest/zitilab/component_zcat.go @@ -16,7 +16,7 @@ type ZCatType struct { } func (self *ZCatType) InitType(*model.Component) { - if self.Version != "" && !strings.HasPrefix(self.Version, "v") { + if self.Version != "" && self.Version != "latest" && !strings.HasPrefix(self.Version, "v") { self.Version = "v" + self.Version } } diff --git a/zititest/zitilab/component_ziti_tunnel.go b/zititest/zitilab/component_ziti_tunnel.go index c8ff622c1..b76151db0 100644 --- a/zititest/zitilab/component_ziti_tunnel.go +++ b/zititest/zitilab/component_ziti_tunnel.go @@ -62,7 +62,7 @@ func (self *ZitiTunnelType) GetActions() map[string]model.ComponentAction { } func (self *ZitiTunnelType) InitType(*model.Component) { - if self.Version != "" && !strings.HasPrefix(self.Version, "v") { + if self.Version != "" && self.Version != "latest" && !strings.HasPrefix(self.Version, "v") { self.Version = "v" + self.Version } }