Skip to content

Commit

Permalink
perf(dl): imp dl
Browse files Browse the repository at this point in the history
imp dl

Signed-off-by: ysicing <i@ysicing.me>
  • Loading branch information
ysicing committed Nov 10, 2021
1 parent 0e8d4e9 commit 16f26b5
Show file tree
Hide file tree
Showing 13 changed files with 364 additions and 141 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## Ergo CHANGELOG
# Ergo CHANGELOG

- v2.6.4
- 优化下载, 参考[lima-vm/lima](https://github.com/lima-vm/lima/blob/19e79df9673c5122fbe3e3418b6297c6296ec8eb/pkg/downloader/downloader.go)

- v2.6.3
- 优化下载
Expand Down
6 changes: 3 additions & 3 deletions cmd/k3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"github.com/ysicing/ergo/common"
"github.com/ysicing/ergo/internal/kube"
es "github.com/ysicing/ergo/pkg/daemon/service"
"github.com/ysicing/ergo/pkg/downloader"
"github.com/ysicing/ergo/pkg/util/factory"
"github.com/ysicing/ergo/pkg/util/util"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -66,7 +66,7 @@ func initAction(cmd *cobra.Command, args []string) error {
filebin, err := exec.LookPath(common.K3sBinName)
if err != nil {
klog.Infof("not found k3s bin, will down k3s %v", common.K3sBinVersion)
if err := util.HTTPGet(common.K3sBinURL, common.K3sBinPath); err != nil {
if _, err := downloader.Download(common.K3sBinURL, common.K3sBinPath); err != nil {
return err
}
os.Chmod(common.K3sBinPath, common.FileMode0755)
Expand Down Expand Up @@ -178,7 +178,7 @@ func joinAction(cmd *cobra.Command, args []string) error {
filebin, err := exec.LookPath(common.K3sBinName)
if err != nil {
klog.Infof("not found k3s bin, will down k3s %v", common.K3sBinVersion)
if err := util.HTTPGet(common.K3sBinURL, common.K3sBinPath); err != nil {
if _, err := downloader.Download(common.K3sBinURL, common.K3sBinPath); err != nil {
return err
}
os.Chmod(common.K3sBinPath, common.FileMode0755)
Expand Down
7 changes: 3 additions & 4 deletions cmd/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
"github.com/spf13/cobra"
"github.com/ysicing/ergo/cmd/flags"
"github.com/ysicing/ergo/common"
"github.com/ysicing/ergo/pkg/downloader"
"github.com/ysicing/ergo/pkg/ergo/ops/exec"
"github.com/ysicing/ergo/pkg/ergo/ops/nc"
"github.com/ysicing/ergo/pkg/ergo/ops/ping"
"github.com/ysicing/ergo/pkg/ergo/ops/ps"
"github.com/ysicing/ergo/pkg/util/factory"
sshutil "github.com/ysicing/ergo/pkg/util/ssh"
"github.com/ysicing/ergo/pkg/util/util"
"helm.sh/helm/v3/cmd/helm/require"
)

Expand Down Expand Up @@ -122,12 +122,11 @@ func (cmd *OPSCmd) wget(target string) error {
cmd.log.Warnf("已存在 %v", dst)
return nil
}
cmd.log.StartWait(fmt.Sprintf("开始下载: %v", s[len(s)-1]))
err := util.HTTPGet(target, dst)
cmd.log.Infof("开始下载: %v", s[len(s)-1])
_, err := downloader.Download(target, dst)
if err != nil {
return err
}
cmd.log.StopWait()
cmd.log.Donef("下载完成, 保存在: %v", dst)
return nil
}
Expand Down
23 changes: 14 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ go 1.16
require (
github.com/Microsoft/go-winio v0.5.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20210920160938-87db9fbc61c7 // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1317
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1323
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394
github.com/blang/semver v3.5.1+incompatible
github.com/cheggaaa/pb/v3 v3.0.8
github.com/containerd/continuity v0.2.1
github.com/ergoapi/log v0.0.0-20211027064103-103783bd0168
github.com/ergoapi/util v0.1.0
github.com/ergoapi/util v0.1.2
github.com/fatih/color v1.13.0 // indirect
github.com/go-git/go-git/v5 v5.4.2
github.com/go-ping/ping v0.0.0-20211014180314-6e2b003bffdd
Expand All @@ -24,6 +27,7 @@ require (
github.com/kardianos/service v1.2.1-0.20211104163826-b9d1d5b7279b
github.com/kevinburke/ssh_config v1.1.0 // indirect
github.com/manifoldco/promptui v0.8.0
github.com/mattn/go-isatty v0.0.14
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
Expand All @@ -35,19 +39,20 @@ require (
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.9.0
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.283
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.283
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.283
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.283
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.283
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.283
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.288
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.288
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.288
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.288
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.288
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.288
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/wangle201210/githubapi v0.0.0-20200804144924-cde7bbdc36ab
github.com/xanzy/ssh-agent v0.3.1 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
golang.org/x/net v0.0.0-20211020060615-d418f374d309 // indirect
golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1
golang.org/x/sys v0.0.0-20211107104306-e0b2ad06fe42 // indirect
golang.org/x/sys v0.0.0-20211109184856-51b60fd695b3 // indirect
gotest.tools v2.2.0+incompatible
helm.sh/helm/v3 v3.7.1
k8s.io/apimachinery v0.22.3
k8s.io/client-go v0.22.3
Expand Down
Loading

0 comments on commit 16f26b5

Please sign in to comment.