Skip to content

Commit bd33a1b

Browse files
authored
Feat/multi thread download artifacts (#827)
* feat: support to download job artifacts in multiple threads * support to set the thread num * use release of http-downloader --------- Co-authored-by: rick <[email protected]>
1 parent a2d078b commit bd33a1b

File tree

3 files changed

+119
-65
lines changed

3 files changed

+119
-65
lines changed

app/cmd/job_artifact_download.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import (
44
"fmt"
55
appCfg "github.com/jenkins-zh/jenkins-cli/app/config"
66
"github.com/jenkins-zh/jenkins-cli/app/i18n"
7+
httpdownloader "github.com/linuxsuren/http-downloader/pkg/net"
78
"net/http"
89
"net/url"
910
"path/filepath"
11+
"runtime"
1012
"strconv"
1113
"strings"
1214

1315
"github.com/jenkins-zh/jenkins-cli/app/helper"
1416

1517
"github.com/jenkins-zh/jenkins-cli/client"
16-
httpdownloader "github.com/linuxsuren/http-downloader/pkg"
1718
"github.com/spf13/cobra"
1819
)
1920

@@ -23,6 +24,7 @@ type JobArtifactDownloadOption struct {
2324
ShowProgress bool
2425
DownloadDir string
2526

27+
Thread int
2628
Jenkins *appCfg.JenkinsServer
2729
RoundTripper http.RoundTripper
2830
}
@@ -37,6 +39,8 @@ func init() {
3739
i18n.T("Whether show the progress"))
3840
jobArtifactDownloadCmd.Flags().StringVarP(&jobArtifactDownloadOption.DownloadDir, "download-dir", "", "",
3941
i18n.T("The directory which artifact will be downloaded"))
42+
jobArtifactDownloadCmd.Flags().IntVarP(&jobArtifactDownloadOption.Thread, "thread", "t", runtime.NumCPU(),
43+
i18n.T("The number of threads"))
4044
}
4145

4246
var jobArtifactDownloadCmd = &cobra.Command{
@@ -86,16 +90,12 @@ func (j *JobArtifactDownloadOption) download(artifactURL, fileName string) (err
8690
jenkinsURL, _ := url.Parse(j.Jenkins.URL)
8791
targetURL := fmt.Sprintf("%s%s", j.Jenkins.URL, strings.TrimPrefix(artifactURL, jenkinsURL.Path))
8892
fmt.Println("start to download from", targetURL)
89-
downloader := httpdownloader.HTTPDownloader{
90-
RoundTripper: j.RoundTripper,
91-
TargetFilePath: fileName,
92-
URL: targetURL,
93-
UserName: j.Jenkins.UserName,
94-
Password: j.Jenkins.Token,
95-
Proxy: j.Jenkins.Proxy,
96-
ProxyAuth: j.Jenkins.ProxyAuth,
97-
ShowProgress: j.ShowProgress,
98-
}
99-
err = downloader.DownloadFile()
93+
94+
download := &httpdownloader.MultiThreadDownloader{}
95+
download.WithBasicAuth(j.Jenkins.UserName, j.Jenkins.Token)
96+
download.WithShowProgress(j.ShowProgress)
97+
download.WithKeepParts(true)
98+
download.WithRoundTripper(j.RoundTripper)
99+
err = download.Download(targetURL, fileName, j.Thread)
100100
return
101101
}

go.mod

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,47 @@ require (
2020
github.com/linuxsuren/cobra-extension v0.0.16
2121
github.com/linuxsuren/go-cli-alias v0.0.10
2222
github.com/linuxsuren/go-cli-plugin v0.0.5
23-
github.com/linuxsuren/http-downloader v0.0.85
23+
github.com/linuxsuren/http-downloader v0.0.98
2424
github.com/magiconair/properties v1.8.5
2525
github.com/mitchellh/go-homedir v1.1.0
2626
github.com/moby/moby v20.10.8+incompatible
2727
github.com/onsi/ginkgo v1.16.5
28-
github.com/onsi/gomega v1.18.1
28+
github.com/onsi/gomega v1.27.10
2929
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
3030
github.com/spf13/cobra v1.6.1
3131
github.com/stretchr/testify v1.8.4
3232
github.com/zalando/go-keyring v0.0.0-20200121091418-667557018717
3333
go.uber.org/zap v1.19.0
34-
golang.org/x/net v0.0.0-20220722155237-a158d28d115b
34+
golang.org/x/net v0.25.0
3535
golang.org/x/text v0.21.0
3636
gopkg.in/yaml.v2 v2.4.0
3737
moul.io/http2curl v1.0.0
3838
)
3939

4040
require (
41-
github.com/Microsoft/go-winio v0.4.17 // indirect
41+
github.com/Microsoft/go-winio v0.6.1 // indirect
4242
github.com/containerd/containerd v1.5.5 // indirect
4343
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
4444
github.com/creack/pty v1.1.17 // indirect
4545
github.com/danieljoos/wincred v1.0.2 // indirect
4646
github.com/davecgh/go-spew v1.1.1 // indirect
4747
github.com/docker/distribution v2.7.1+incompatible // indirect
4848
github.com/docker/go-units v0.4.0 // indirect
49-
github.com/emirpasic/gods v1.12.0 // indirect
49+
github.com/emirpasic/gods v1.18.1 // indirect
5050
github.com/fsnotify/fsnotify v1.5.1 // indirect
51+
github.com/gliderlabs/ssh v0.3.5 // indirect
5152
github.com/godbus/dbus v4.1.0+incompatible // indirect
5253
github.com/gogo/protobuf v1.3.2 // indirect
53-
github.com/golang/protobuf v1.5.2 // indirect
54+
github.com/golang/protobuf v1.5.3 // indirect
55+
github.com/google/go-cmp v0.6.0 // indirect
5456
github.com/google/go-querystring v1.0.0 // indirect
5557
github.com/gorilla/mux v1.8.0 // indirect
5658
github.com/inconshreveable/mousetrap v1.0.1 // indirect
5759
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
5860
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213 // indirect
5961
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
60-
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
62+
github.com/kevinburke/ssh_config v1.2.0 // indirect
63+
github.com/kr/pretty v0.3.1 // indirect
6164
github.com/mattn/go-colorable v0.1.6 // indirect
6265
github.com/mattn/go-isatty v0.0.17 // indirect
6366
github.com/mattn/go-runewidth v0.0.15 // indirect
@@ -71,23 +74,28 @@ require (
7174
github.com/pkg/errors v0.9.1 // indirect
7275
github.com/pmezard/go-difflib v1.0.0 // indirect
7376
github.com/rivo/uniseg v0.4.3 // indirect
77+
github.com/rogpeppe/go-internal v1.11.0 // indirect
7478
github.com/russross/blackfriday/v2 v2.1.0 // indirect
7579
github.com/schollz/progressbar/v3 v3.13.0 // indirect
7680
github.com/sergi/go-diff v1.1.0 // indirect
77-
github.com/sirupsen/logrus v1.8.1 // indirect
81+
github.com/sirupsen/logrus v1.9.0 // indirect
7882
github.com/spf13/pflag v1.0.5 // indirect
7983
github.com/src-d/gcfg v1.4.0 // indirect
80-
github.com/xanzy/ssh-agent v0.3.0 // indirect
84+
github.com/xanzy/ssh-agent v0.3.3 // indirect
8185
go.uber.org/atomic v1.7.0 // indirect
8286
go.uber.org/multierr v1.6.0 // indirect
83-
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
87+
golang.org/x/crypto v0.23.0 // indirect
88+
golang.org/x/mod v0.17.0 // indirect
8489
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
85-
golang.org/x/sys v0.17.0 // indirect
86-
golang.org/x/term v0.17.0 // indirect
90+
golang.org/x/sync v0.10.0 // indirect
91+
golang.org/x/sys v0.20.0 // indirect
92+
golang.org/x/term v0.20.0 // indirect
93+
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
8794
google.golang.org/appengine v1.6.7 // indirect
88-
google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a // indirect
89-
google.golang.org/grpc v1.33.2 // indirect
90-
google.golang.org/protobuf v1.27.1 // indirect
95+
google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71 // indirect
96+
google.golang.org/grpc v1.40.0 // indirect
97+
google.golang.org/protobuf v1.28.0 // indirect
98+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
9199
gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect
92100
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
93101
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect

0 commit comments

Comments
 (0)