oc-deploy/src/tool/helm.go

55 lines
1.1 KiB
Go
Raw Normal View History

2024-09-02 13:44:44 +02:00
package tool
import (
"fmt"
"os"
"oc-deploy/utils"
"oc-deploy/helm"
)
type HelmInstallData struct {
2024-09-03 13:46:45 +02:00
obj ToolData
tmp string
2024-09-02 13:44:44 +02:00
}
func (this HelmInstallData) Get() (ToolData) {
2024-09-03 13:46:45 +02:00
return this.obj
2024-09-02 13:44:44 +02:00
}
func (this HelmInstallData) Download() (error) {
2024-09-03 13:46:45 +02:00
bin_dir := this.obj.Bin
err2 := os.MkdirAll(bin_dir, os.ModePerm)
if err2 != nil {
return err2
}
2024-09-02 13:44:44 +02:00
tmp_file := fmt.Sprintf("%s/oc-deploy-%s", this.tmp, this.obj.Name)
2024-09-03 13:46:45 +02:00
url := fmt.Sprintf(this.obj.Url, this.obj.Version)
2024-09-02 13:44:44 +02:00
2024-09-03 13:46:45 +02:00
err := utils.DownloadFromUrl(tmp_file, url, 0777)
if err != nil {
return err
}
2024-09-02 13:44:44 +02:00
2024-09-03 13:46:45 +02:00
r, _ := os.Open(tmp_file)
err1 := utils.ExtractTarGz(bin_dir, r)
2024-09-03 15:18:20 +02:00
if err1 != nil {return err1}
2024-09-02 13:44:44 +02:00
2024-09-03 13:46:45 +02:00
os.Remove(tmp_file)
2024-09-02 13:44:44 +02:00
2024-09-03 13:46:45 +02:00
bin_file := fmt.Sprintf("%s/%s", bin_dir, this.obj.Name)
2024-09-02 13:44:44 +02:00
2024-09-03 15:18:20 +02:00
errChmod := os.Chmod(bin_file, 0755)
if errChmod != nil {return errChmod}
2024-09-02 13:44:44 +02:00
2024-09-03 15:18:20 +02:00
return nil
2024-09-02 13:44:44 +02:00
}
///////////////
func (this HelmInstallData) Version(path string) (string, error) {
2024-09-09 16:17:02 +02:00
cmd := helm.HelmCommand{Bin: path}
cmd.New()
return cmd.GetVersion()
2024-09-02 09:09:46 +02:00
}