2016-07-21 14:33:49 +00:00
|
|
|
package version
|
2015-11-01 21:59:59 +00:00
|
|
|
|
2016-10-27 14:17:02 +00:00
|
|
|
import (
|
|
|
|
"github.com/containous/traefik/log"
|
|
|
|
"github.com/google/go-github/github"
|
|
|
|
goversion "github.com/hashicorp/go-version"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
2015-11-01 21:59:59 +00:00
|
|
|
var (
|
2015-11-06 17:11:57 +00:00
|
|
|
// Version holds the current version of traefik.
|
2016-06-02 13:17:04 +00:00
|
|
|
Version = "dev"
|
2016-07-05 19:03:37 +00:00
|
|
|
// Codename holds the current version codename of traefik.
|
|
|
|
Codename = "cheddar" // beta cheese
|
2015-11-06 17:11:57 +00:00
|
|
|
// BuildDate holds the build date of traefik.
|
2016-06-02 13:17:04 +00:00
|
|
|
BuildDate = "I don't remember exactly"
|
2015-11-01 21:59:59 +00:00
|
|
|
)
|
2016-10-27 14:17:02 +00:00
|
|
|
|
|
|
|
// CheckNewVersion checks if a new version is available
|
|
|
|
func CheckNewVersion() {
|
|
|
|
if Version == "dev" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
client := github.NewClient(nil)
|
|
|
|
updateURL, err := url.Parse("https://update.traefik.io")
|
|
|
|
if err != nil {
|
|
|
|
log.Warnf("Error checking new version: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
client.BaseURL = updateURL
|
|
|
|
releases, resp, err := client.Repositories.ListReleases("containous", "traefik", nil)
|
|
|
|
if err != nil {
|
|
|
|
log.Warnf("Error checking new version: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.StatusCode != 200 {
|
|
|
|
log.Warnf("Error checking new version: status=%s", resp.Status)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
currentVersion, err := goversion.NewVersion(Version)
|
|
|
|
if err != nil {
|
|
|
|
log.Warnf("Error checking new version: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, release := range releases {
|
|
|
|
releaseVersion, err := goversion.NewVersion(*release.TagName)
|
|
|
|
if err != nil {
|
|
|
|
log.Warnf("Error checking new version: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(currentVersion.Prerelease()) == 0 && len(releaseVersion.Prerelease()) > 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if releaseVersion.GreaterThan(currentVersion) {
|
|
|
|
log.Warnf("A new release has been found: %s. Please consider updating.", releaseVersion.String())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|