func getInstalledVersions(pattern string) []dockerversion.Version { searchPath := filepath.Join(getVersionsDir(), pattern) versions, _ := filepath.Glob(searchPath) var results []dockerversion.Version for _, versionDir := range versions { version := dockerversion.Parse(filepath.Base(versionDir)) if version.IsExperimental() { experimentalDockerPath := filepath.Join(versionDir, getBinaryName()) experimentalVersion, err := getDockerVersion(experimentalDockerPath, true) if err != nil { writeDebug("Unable to get version of installed experimental version at %s.\n%s", versionDir, err) continue } version.SemVer = experimentalVersion.SemVer } results = append(results, version) } if glob.Glob(pattern, dockerversion.SystemAlias) { systemVersion, err := getSystemDockerVersion() if err == nil { results = append(results, systemVersion) } } dockerversion.Sort(results) return results }
func getAvailableVersions(pattern string) []dockerversion.Version { gh := buildGithubClient() options := &github.ListOptions{PerPage: 100} var allReleases []github.RepositoryRelease for { releases, response, err := gh.Repositories.ListReleases("docker", "docker", options) if err != nil { warnWhenRateLimitExceeded(err, response) die("Unable to retrieve list of Docker releases from GitHub", err, retCodeRuntimeError) } allReleases = append(allReleases, releases...) if response.StatusCode != 200 { die("Unable to retrieve list of Docker releases from GitHub (Status %s).", nil, retCodeRuntimeError, response.StatusCode) } if response.NextPage == 0 { break } options.Page = response.NextPage } versionRegex := regexp.MustCompile(`^v([1-9]+\.\d+\.\d+)$`) patternRegex, err := regexp.Compile(pattern) if err != nil { die("Invalid pattern.", err, retCodeInvalidOperation) } var results []dockerversion.Version for _, release := range allReleases { version := *release.Name match := versionRegex.FindStringSubmatch(version) if len(match) > 1 && patternRegex.MatchString(version) { results = append(results, dockerversion.Parse(match[1])) } } dockerversion.Sort(results) return results }