-
Notifications
You must be signed in to change notification settings - Fork 200
/
install.go
71 lines (60 loc) · 1.6 KB
/
install.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package tools
import (
"os"
"runtime"
"github.com/carolynvs/magex/mgx"
"github.com/carolynvs/magex/pkg"
"github.com/carolynvs/magex/pkg/archive"
"github.com/carolynvs/magex/pkg/downloads"
)
const (
// Version of KIND to install if not already present
DefaultKindVersion = "v0.10.0"
)
// Install mage
func EnsureMage() error {
return pkg.EnsureMage("")
}
// Install gh
func EnsureGitHubClient() {
if ok, _ := pkg.IsCommandAvailable("gh", ""); ok {
return
}
// gh cli unfortunately uses a different archive schema depending on the OS
target := "gh_{{.VERSION}}_{{.GOOS}}_{{.GOARCH}}/bin/gh{{.EXT}}"
if runtime.GOOS == "windows" {
target = "bin/gh.exe"
}
opts := archive.DownloadArchiveOptions{
DownloadOptions: downloads.DownloadOptions{
UrlTemplate: "https://github.com/cli/cli/releases/download/v{{.VERSION}}/gh_{{.VERSION}}_{{.GOOS}}_{{.GOARCH}}{{.EXT}}",
Name: "gh",
Version: "1.8.1",
OsReplacement: map[string]string{
"darwin": "macOS",
},
},
ArchiveExtensions: map[string]string{
"linux": ".tar.gz",
"darwin": ".tar.gz",
"windows": ".zip",
},
TargetFileTemplate: target,
}
err := archive.DownloadToGopathBin(opts)
mgx.Must(err)
}
// Install kind
func EnsureKind() {
if ok, _ := pkg.IsCommandAvailable("kind", ""); ok {
return
}
kindURL := "https://github.com/kubernetes-sigs/kind/releases/download/{{.VERSION}}/kind-{{.GOOS}}-{{.GOARCH}}"
mgx.Must(pkg.DownloadToGopathBin(kindURL, "kind", getKindVersion()))
}
func getKindVersion() string {
if version, ok := os.LookupEnv("KIND_VERSION"); ok {
return version
}
return DefaultKindVersion
}