-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from carolynvs/experimental
Support "edge" releases
- Loading branch information
Showing
11 changed files
with
265 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package dockerversion | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
|
||
"bytes" | ||
"regexp" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
var hrefRegex = regexp.MustCompile("href=\"docker-(.*).tgz\"") | ||
|
||
func findLatestEdgeVersion(mirrorURL string) (Version, error) { | ||
if mirrorURL == "" { | ||
mirrorURL = "https://download.docker.com" | ||
} | ||
|
||
mirror, err := url.Parse(mirrorURL) | ||
if err != nil { | ||
return Version{}, errors.Wrapf(err, "Unable to parse the mirror URL: %s", mirrorURL) | ||
} | ||
|
||
edgeReleasesUrl := fmt.Sprintf("%s://%s/%s/static/edge/%s", mirror.Scheme, mirror.Host, mobyOS, dockerArch) | ||
response, err := http.Get(edgeReleasesUrl) | ||
if err != nil { | ||
return Version{}, errors.Wrapf(err, "Unable to list edge releases at %s", edgeReleasesUrl) | ||
} | ||
defer response.Body.Close() | ||
|
||
b := bytes.Buffer{} | ||
_, err = b.ReadFrom(response.Body) | ||
if err != nil { | ||
} | ||
errors.Wrapf(err, "Unable to read the listing of edge releases at %s", edgeReleasesUrl) | ||
|
||
matches := hrefRegex.FindAllStringSubmatch(b.String(), -1) | ||
var results []Version | ||
for _, match := range matches { | ||
version := Parse(match[1]) | ||
if version.semver == nil { | ||
continue | ||
} | ||
results = append(results, version) | ||
} | ||
|
||
Sort(results) | ||
|
||
if len(results) == 0 { | ||
return Version{}, errors.Errorf("No valid edge versions were found at %s", edgeReleasesUrl) | ||
} | ||
|
||
last := len(results) - 1 | ||
return results[last], nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dockerversion | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/howtowhale/dvm/dvm-helper/internal/test" | ||
) | ||
|
||
func TestVersion_findLatestEdgeVersion(t *testing.T) { | ||
releaseListing := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "text/html") | ||
fmt.Fprintln(w, test.LoadTestData("edge_releases.html")) | ||
})) | ||
|
||
v, err := findLatestEdgeVersion(releaseListing.URL) | ||
if err != nil { | ||
t.Fatalf("%#v", err) | ||
} | ||
|
||
wantV := "17.06.0-ce" | ||
gotV := v.String() | ||
if wantV != gotV { | ||
t.Fatalf("Expected '%s', got '%s'", wantV, gotV) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Index of /linux/static/edge/x86_64/</title> | ||
</head> | ||
<body> | ||
<h1>Index of /linux/static/edge/x86_64/</h1> | ||
<hr> | ||
<pre><a href="../">../</a> | ||
<a href="docker-17.03.0-ce.tgz">docker-17.03.0-ce.tgz</a> 2017-03-01 11:46 27M | ||
<a href="docker-17.04.0-ce.tgz">docker-17.04.0-ce.tgz</a> 2017-04-06 01:07 26M | ||
<a href="docker-17.05.0-ce.tgz">docker-17.05.0-ce.tgz</a> 2017-05-05 04:11 28M | ||
<a href="docker-17.06.0-ce.tgz">docker-17.06.0-ce.tgz</a> 2017-06-28 04:51 29M | ||
</pre><hr></body></html> |
Oops, something went wrong.