Skip to content
This repository was archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #17 from KusionStack/add-cdn-source
Browse files Browse the repository at this point in the history
feat: add cdn source
  • Loading branch information
elliotxx authored May 18, 2022
2 parents 765b008 + af6710b commit a3c6716
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path/filepath"

"github.com/KusionStack/kusionup/pkg/sources"
"github.com/KusionStack/kusionup/pkg/sources/cdn"
"github.com/KusionStack/kusionup/pkg/sources/github"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -26,6 +27,7 @@ func init() {
// Init release sources
registedReleaseSources = map[string]sources.ReleaseSource{
github.GithubReleaseSource.GetName(): github.GithubReleaseSource,
cdn.GithubReleaseSource.GetName(): cdn.GithubReleaseSource,
}

var err error
Expand Down
56 changes: 56 additions & 0 deletions pkg/sources/cdn/source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cdn

import (
"github.com/KusionStack/kusionup/pkg/sources"
"github.com/KusionStack/kusionup/pkg/util/gitutil"
)

var GithubReleaseSource sources.ReleaseSource = &releaseSource{}

type releaseSource struct {
name string // release source name
}

func (s *releaseSource) GetName() string {
s.name = "cdn"

return s.name
}

func (s *releaseSource) GetVersions() []string {
versions := []string{}

// Get tags from github repo of kusion
remoteURL := "git@github.com:KusionStack/kusion"

tags, err := gitutil.GetTagListFromRemote(remoteURL, true)
if err != nil {
// klog.Warningf("Get tag list from remote failed, err: %v", err)
return versions
}

// Hidden timeout tags
isHiddenTag := getIsHiddenTag()
for _, tag := range tags {
if _, hidden := isHiddenTag[tag]; !hidden {
versions = append(versions, tag)
}
}

return versions
}

func (s *releaseSource) GetDownloadURL(ver string) (string, error) {
return getArchiveDownloadURL(ver)
}

func getIsHiddenTag() map[string]struct{} {
hiddenTags := []string{"v0.4.0"}
isHiddenTag := make(map[string]struct{})

for _, tag := range hiddenTags {
isHiddenTag[tag] = struct{}{}
}

return isHiddenTag
}
27 changes: 27 additions & 0 deletions pkg/sources/cdn/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cdn

import (
"fmt"
"runtime"
)

var ErrUnsupportedOsArch = fmt.Errorf("unsupported os/arch: %s/%s", runtime.GOOS, runtime.GOARCH)

func getArchiveDownloadURL(ver string) (string, error) {
archiveDownloadURLMap := map[string]string{
"linux-amd64": "https://gh.api.99988866.xyz/https://github.com/KusionStack/kusion/releases/download/%s/kusion-linux.tgz",
"darwin-amd64": "https://gh.api.99988866.xyz/https://github.com/KusionStack/kusion/releases/download/%s/kusion-darwin.tgz",
// "darwin-arm64": "TODO",
// "windows-amd64": "TODO",
}

if urlPattern, ok := archiveDownloadURLMap[getOsArchKey(runtime.GOOS, runtime.GOARCH)]; ok {
return fmt.Sprintf(urlPattern, ver), nil
}

return "", ErrUnsupportedOsArch
}

func getOsArchKey(goos, goarch string) string {
return goos + "-" + goarch
}

0 comments on commit a3c6716

Please sign in to comment.