Skip to content

Commit

Permalink
Merge pull request #1482 from openziti/install-ziti-fixes
Browse files Browse the repository at this point in the history
Properly handle installing and running 'latest' ziti binaries
  • Loading branch information
plorenz authored Oct 30, 2023
2 parents dd1cc71 + 73c71d3 commit 386db7c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 30 deletions.
27 changes: 18 additions & 9 deletions common/getziti/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 2 additions & 16 deletions common/getziti/install_ziti.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion zititest/zitilab/component_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion zititest/zitilab/component_echo_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion zititest/zitilab/component_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion zititest/zitilab/component_zcat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion zititest/zitilab/component_ziti_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 386db7c

Please sign in to comment.