Skip to content

Commit

Permalink
Merge pull request #6 from cuisongliu/issue/2
Browse files Browse the repository at this point in the history
fix(1.6): fetch remote versions
  • Loading branch information
cuisongliu authored Dec 3, 2020
2 parents 63a42a2 + 5caa7ad commit 33e8274
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 33 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.12

require (
github.com/PuerkitoBio/goquery v1.5.0
github.com/a-urth/go-bindata v0.0.0-20180209162145-df38da164efc // indirect
github.com/fanux/sealos v2.0.3+incompatible
github.com/pkg/sftp v1.10.1 // indirect
github.com/spf13/cobra v0.0.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/PuerkitoBio/goquery v1.5.0 h1:uGvmFXOA73IKluu/F84Xd1tt/z07GYm8X49XKHP7EJk=
github.com/PuerkitoBio/goquery v1.5.0/go.mod h1:qD2PgZ9lccMbQlc7eEOjaeRlFQON7xY8kdmcsrnKqMg=
github.com/a-urth/go-bindata v0.0.0-20180209162145-df38da164efc h1:eXJIPWW4y4xjPWda/7ruw5PRsfcbzKTL9EhNQrBRsOU=
github.com/a-urth/go-bindata v0.0.0-20180209162145-df38da164efc/go.mod h1:D0SbCgK4DQtSNzDQzfek273VqkCnHdFCd+q2ueHGRiE=
github.com/andybalholm/cascadia v1.0.0 h1:hOCXnnZ5A+3eVDX8pvgl4kofXv2ELss0bKcqRySc45o=
github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
Expand Down
20 changes: 10 additions & 10 deletions install/command/assert.go

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions install/command/command.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package command

import (
"bytes"
"crypto/tls"
"fmt"
sealos "github.com/fanux/sealos/install"
"github.com/wonderivan/logger"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
"time"
)

var (
Expand Down Expand Up @@ -47,3 +55,34 @@ func sendPackage(host, url, fileName string) {
sealos.Copy(host, url, localFile)
}
}

func getUrl(rawurl string) ([]byte, error) {
u, err := url.Parse(rawurl)
if err != nil {
logger.Error(err)
return nil, err
}
if u == nil {
return nil, fmt.Errorf("解析url为空")
}
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
logger.Error(err)
return nil, err
}
var client = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
Timeout: 5 * time.Second,
}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
logger.Debug("client do http status:", resp.Status)
buf := bytes.NewBuffer(nil)
_, err = io.Copy(buf, resp.Body)
_ = resp.Body.Close()
return ioutil.ReadAll(buf)
}
38 changes: 15 additions & 23 deletions install/command/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/PuerkitoBio/goquery"
sealos "github.com/fanux/sealos/install"
"github.com/wonderivan/logger"
"net/http"
"os"
"text/template"
)
Expand Down Expand Up @@ -203,29 +201,23 @@ func (d *Containerd) Print() {
}

func (d *Containerd) Fetch() {
url := "https://containerd.io/downloads/"
resp, err := http.Get(url)
if err != nil {
logger.Error(err)
os.Exit(1)
}
if resp.StatusCode != 200 {
logger.Error("http code is not 200")
os.Exit(1)
//https://api.github.com/repos/containerd/containerd/tags?page=3
type tags struct {
Name string `json:"name"`
}
var versions []string
doc, err := goquery.NewDocumentFromReader(resp.Body)
if err != nil {
logger.Error(err)
os.Exit(1)
}
ahtml := doc.Find("a[class=\"button is-dark is-clipboard\"]")
for _, html := range ahtml.Nodes {
attr := html.Attr
if len(attr) == 3 {
if attr[2].Key == "data-clipboard-text" {
versions = append(versions, attr[2].Val)
logger.Debug("加入缓存值:%s", attr[2].Val)
for i := 1; ; i++ {
url := fmt.Sprintf("https://api.github.com/repos/containerd/containerd/tags?page=%d", i)
var tagses []tags
data, _ := getUrl(url)
if data != nil {
_ = json.Unmarshal(data, &tagses)
if len(tagses) > 0 {
for j := 0; j < len(tagses); j++ {
versions = append(versions, tagses[j].Name)
}
} else {
break
}
}
}
Expand Down
100 changes: 100 additions & 0 deletions install/command/containerd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
[
"v1.4.3",
"v1.4.2",
"v1.4.1",
"v1.4.0",
"v1.4.0-rc.1",
"v1.4.0-rc.0",
"v1.4.0-beta.2",
"v1.4.0-beta.1",
"v1.4.0-beta.0",
"v1.3.9",
"v1.3.8",
"v1.3.7",
"v1.3.6",
"v1.3.5",
"v1.3.4",
"v1.3.3",
"v1.3.2",
"v1.3.1",
"v1.3.0",
"v1.3.0-rc.3",
"v1.3.0-rc.2",
"v1.3.0-rc.1",
"v1.3.0-rc.0",
"v1.3.0-beta.2",
"v1.3.0-beta.1",
"v1.3.0-beta.0",
"v1.2.14",
"v1.2.13",
"v1.2.12",
"v1.2.11",
"v1.2.10",
"v1.2.9",
"v1.2.8",
"v1.2.7",
"v1.2.6",
"v1.2.5",
"v1.2.4",
"v1.2.3",
"v1.2.2",
"v1.2.1",
"v1.2.1-rc.0",
"v1.2.0",
"v1.2.0-rc.2",
"v1.2.0-rc.1",
"v1.2.0-rc.0",
"v1.2.0-beta.2",
"v1.2.0-beta.1",
"v1.2.0-beta.0",
"v1.1.8",
"v1.1.7",
"v1.1.6",
"v1.1.5",
"v1.1.4",
"v1.1.3",
"v1.1.2",
"v1.1.1",
"v1.1.1-rc.2",
"v1.1.1-rc.1",
"v1.1.1-rc.0",
"v1.1.0",
"v1.1.0-rc.2",
"v1.1.0-rc.1",
"v1.1.0-rc.0",
"v1.0.3",
"v1.0.3-rc.0",
"v1.0.2",
"v1.0.2-rc.1",
"v1.0.2-rc.0",
"v1.0.1",
"v1.0.1-rc.0",
"v1.0.0",
"v1.0.0-rc.0",
"v1.0.0-beta.3",
"v1.0.0-beta.2",
"v1.0.0-beta.1",
"v1.0.0-beta.0",
"v1.0.0-alpha6",
"v1.0.0-alpha5",
"v1.0.0-alpha4",
"v1.0.0-alpha3",
"v1.0.0-alpha2",
"v1.0.0-alpha1",
"v1.0.0-alpha0",
"v0.2.9",
"v0.2.8",
"v0.2.7",
"v0.2.6",
"v0.2.5",
"v0.2.4",
"v0.2.3",
"v0.2.2",
"v0.2.1",
"v0.2.0",
"v0.1.0",
"0.0.5",
"0.0.4",
"0.0.3",
"0.0.2"
]
58 changes: 58 additions & 0 deletions install/command/docker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
"docker-17.03.0-ce.tgz",
"docker-17.03.1-ce.tgz",
"docker-17.03.2-ce.tgz",
"docker-17.06.0-ce.tgz",
"docker-17.06.1-ce.tgz",
"docker-17.06.2-ce.tgz",
"docker-17.09.0-ce.tgz",
"docker-17.09.1-ce.tgz",
"docker-17.12.0-ce.tgz",
"docker-17.12.1-ce.tgz",
"docker-18.03.0-ce.tgz",
"docker-18.03.1-ce.tgz",
"docker-18.06.0-ce.tgz",
"docker-18.06.1-ce.tgz",
"docker-18.06.2-ce.tgz",
"docker-18.06.3-ce.tgz",
"docker-18.09.0.tgz",
"docker-18.09.1.tgz",
"docker-18.09.2.tgz",
"docker-18.09.3.tgz",
"docker-18.09.4.tgz",
"docker-18.09.5.tgz",
"docker-18.09.6.tgz",
"docker-18.09.7.tgz",
"docker-18.09.8.tgz",
"docker-18.09.9.tgz",
"docker-19.03.0.tgz",
"docker-19.03.1.tgz",
"docker-19.03.10.tgz",
"docker-19.03.11.tgz",
"docker-19.03.12.tgz",
"docker-19.03.13.tgz",
"docker-19.03.14.tgz",
"docker-19.03.2.tgz",
"docker-19.03.3.tgz",
"docker-19.03.4.tgz",
"docker-19.03.5.tgz",
"docker-19.03.6.tgz",
"docker-19.03.7.tgz",
"docker-19.03.8.tgz",
"docker-19.03.9.tgz",
"docker-rootless-extras-19.03.0.tgz",
"docker-rootless-extras-19.03.1.tgz",
"docker-rootless-extras-19.03.10.tgz",
"docker-rootless-extras-19.03.11.tgz",
"docker-rootless-extras-19.03.12.tgz",
"docker-rootless-extras-19.03.13.tgz",
"docker-rootless-extras-19.03.14.tgz",
"docker-rootless-extras-19.03.2.tgz",
"docker-rootless-extras-19.03.3.tgz",
"docker-rootless-extras-19.03.4.tgz",
"docker-rootless-extras-19.03.5.tgz",
"docker-rootless-extras-19.03.6.tgz",
"docker-rootless-extras-19.03.7.tgz",
"docker-rootless-extras-19.03.8.tgz",
"docker-rootless-extras-19.03.9.tgz"
]

0 comments on commit 33e8274

Please sign in to comment.