コード例 #1
0
ファイル: dev_release.go プロジェクト: hpcloud/fissile
func (r *Release) getLatestDevVersion() (ver string, err error) {
	devReleaseIndexContent, err := ioutil.ReadFile(r.getDevReleaseIndexPath())
	if err != nil {
		return "", err
	}

	var devReleaseIndex map[interface{}]interface{}

	if err := yaml.Unmarshal([]byte(devReleaseIndexContent), &devReleaseIndex); err != nil {
		return "", err
	}

	var semiVer version.Version
	var builds map[interface{}]interface{}

	if value, ok := devReleaseIndex["builds"]; !ok {
		return "", fmt.Errorf("builds key did not exist in dev releases index file for release: %s", r.Name)
	} else if builds, ok = value.(map[interface{}]interface{}); !ok {
		return "", fmt.Errorf("builds key in dev releases index file was not a map for release: %s, type: %T, value: %v", r.Name, value, value)
	}

	for _, build := range builds {
		var buildVersion string

		if buildMap, ok := build.(map[interface{}]interface{}); !ok {
			return "", fmt.Errorf("build entry was not a map in release: %s, type: %T, value: %v", r.Name, build, build)
		} else if value, ok := buildMap["version"]; !ok {
			return "", fmt.Errorf("version key did not exist in a build entry for release: %s", r.Name)
		} else if buildVersion, ok = value.(string); !ok {
			return "", fmt.Errorf("version was not a string in a build entry for release: %s, type: %T, value: %v", r.Name, value, value)
		}

		if ver == "" {
			ver = buildVersion
			semiVer, err = version.NewVersionFromString(ver)
			if err != nil {
				return "", err
			}

			continue
		}

		semiBuildVer, err := version.NewVersionFromString(buildVersion)
		if err != nil {
			return "", err
		}

		if semiBuildVer.IsGt(semiVer) {
			ver = buildVersion
			semiVer = semiBuildVer
		}
	}

	return ver, nil
}
コード例 #2
0
func (r byVersion) Less(i, j int) bool {
	first, err := version.NewVersionFromString(determineVersionFromTag(*r[i].TagName))
	if err != nil {
		return true
	}

	second, err := version.NewVersionFromString(determineVersionFromTag(*r[j].TagName))
	if err != nil {
		return false
	}

	return first.IsLt(second)
}
コード例 #3
0
ファイル: s3_binary.go プロジェクト: pivotalservices/bosh-hub
func NewS3Binary(key, etag string, size uint64, lastModified, url string) *S3Binary {
	m := matchS3FileKey(key)

	if len(m) == 0 {
		return nil
	}

	version, err := semiver.NewVersionFromString(m["version"])
	if err != nil {
		return nil
	}

	binary := &S3Binary{
		name: key,

		version:   version,
		updatedAt: lastModified,

		size: size,
		etag: strings.Trim(etag, "\""),

		platform: m["platform"],
		arch:     m["arch"],

		url: url,
	}

	return binary
}
コード例 #4
0
ファイル: release.go プロジェクト: pivotalservices/bosh-hub
func parseVersion(versionRaw string) semiver.Version {
	ver, err := semiver.NewVersionFromString(versionRaw)
	if err != nil {
		panic(fmt.Sprintf("Version '%s' is not valid: %s", versionRaw, err))
	}

	return ver
}
コード例 #5
0
ファイル: watcher.go プロジェクト: pivotalservices/bosh-hub
func (r WatcherRec) MinVersion() semiver.Version {
	// Validate should not allow invalid version to be saved
	ver, err := semiver.NewVersionFromString(r.MinVersionRaw)
	if err != nil {
		panic(fmt.Sprintf("Version '%s' is not valid: %s", r.MinVersionRaw, err))
	}

	return ver
}
コード例 #6
0
ファイル: watcher.go プロジェクト: pivotalservices/bosh-hub
func (r WatcherRec) Validate() error {
	if len(r.RelSource) == 0 {
		return bosherr.New("Expected release source to be non-empty")
	}

	if len(r.MinVersionRaw) == 0 {
		return bosherr.New("Expected min version to be non-empty")
	}

	_, err := semiver.NewVersionFromString(r.MinVersionRaw)
	if err != nil {
		return bosherr.WrapError(err, "Expected min version to be a valid version")
	}

	return nil
}
コード例 #7
0
// Show uses '_1' param as stemcell name and 'v' param as release version
func (c StemcellsController) Download(req *http.Request, r martrend.Render, params mart.Params) {
	relSource := params["_1"]

	if len(relSource) == 0 {
		err := bosherr.New("Param 'source' must be non-empty")
		r.HTML(400, c.errorTmpl, err)
		return
	}

	stemcells, err := c.stemcellsRepo.FindAll(relSource)
	if err != nil {
		r.HTML(500, c.errorTmpl, err)
		return
	}

	filter := bhstemui.StemcellFilter{Name: relSource, IncludeAll: true}

	// List of versions for the specific stemcell name
	// todo really filtering below should be part of the repo instead of ui
	uniqVerStems := bhstemui.NewUniqueVersionStemcells(stemcells, filter)

	sortedStemcells := uniqVerStems.ForAPI()

	relVersion := req.URL.Query().Get("v")

	preferLight := true

	lightParam := req.URL.Query().Get("light")
	if lightParam != "" {
		preferLight = c.isParamTrue(lightParam)
	}

	// todo remove china stemcell once consolidated into light stemcells
	chinaParam := req.URL.Query().Get("china")
	mustBeForChina := c.isParamTrue(chinaParam)

	if relVersion == "" {
		if len(sortedStemcells) == 0 {
			err := bosherr.New("Latest stemcell is not found")
			r.HTML(404, c.errorTmpl, err)
			return
		}

		url, err := sortedStemcells[0].ActualDownloadURL(preferLight, mustBeForChina)
		if err != nil {
			r.HTML(404, c.errorTmpl, err)
			return
		}

		r.Redirect(url)
		return
	}

	ver, err := semiver.NewVersionFromString(relVersion)
	if err != nil {
		err = bosherr.New("Version '%s' is not valid: %s", relVersion, err)
		r.HTML(400, c.errorTmpl, err)
		return
	}

	for _, stemcell := range sortedStemcells {
		if stemcell.Version.IsEq(ver) {
			url, err := stemcell.ActualDownloadURL(preferLight, mustBeForChina)
			if err != nil {
				r.HTML(404, c.errorTmpl, err)
				return
			}

			r.Redirect(url)
			return
		}
	}

	err = bosherr.New("Stemcell version '%s' is not found", relVersion)
	r.HTML(404, c.errorTmpl, err)
}
コード例 #8
0
func NewS3Stemcell(key, etag string, size uint64, lastModified, url string) *S3Stemcell {
	m := matchS3FileKey(key)

	if len(m) == 0 {
		return nil
	}

	version, err := semiver.NewVersionFromString(m["version"])
	if err != nil {
		return nil
	}

	var osName, osVersion, agentType string

	osName = m["os_name"]

	if len(m["os_version"]) > 0 {
		osVersion = strings.Trim(m["os_version"], "-")
	}

	if len(m["agent_type"]) > 0 {
		agentType = strings.Trim(m["agent_type"], "-")
	} else {
		agentType = "ruby_agent"
	}

	if s3StemcellAgentRegexp.MatchString(osVersion) {
		if osName == "ubuntu" {
			agentType = osVersion
			osVersion = "lucid"
		} else {
			agentType = osVersion
			osVersion = ""
		}
	}

	if len(osVersion) == 0 && osName == "ubuntu" {
		osVersion = "lucid"
	}

	s3Stemcell := &S3Stemcell{
		// todo assume that piece of the stemcell file name
		// matches actual stemcell name used in a manifest
		name:   "bosh-" + m["name"],
		flavor: m["flavor"],

		version:   version,
		updatedAt: lastModified,

		size: size,
		etag: strings.Trim(etag, "\""),

		infName:    m["inf_name"],
		hvName:     m["hv_name"],
		diskFormat: strings.Trim(m["disk_fmt"], "-"),

		osName:    osName,
		osVersion: osVersion,

		agentType: strings.Replace(agentType, "_agent", "", 1),

		url: url,
	}

	return s3Stemcell
}
コード例 #9
0
func (c *CheckCommand) Run(request CheckRequest) ([]Version, error) {
	releases, err := c.github.ListReleases()
	if err != nil {
		return []Version{}, err
	}

	if len(releases) == 0 {
		return []Version{}, nil
	}

	var filteredReleases []github.RepositoryRelease

	for _, release := range releases {
		if request.Source.Drafts != *release.Draft {
			continue
		}
		if release.TagName == nil {
			continue
		}
		if _, err := version.NewVersionFromString(determineVersionFromTag(*release.TagName)); err != nil {
			continue
		}

		filteredReleases = append(filteredReleases, release)
	}

	sort.Sort(byVersion(filteredReleases))

	if len(filteredReleases) == 0 {
		return []Version{}, nil
	}
	latestRelease := filteredReleases[len(filteredReleases)-1]

	if (request.Version == Version{}) {
		return []Version{
			versionFromRelease(&latestRelease),
		}, nil
	}

	if *latestRelease.TagName == request.Version.Tag {
		return []Version{}, nil
	}

	upToLatest := false
	reversedVersions := []Version{}

	for _, release := range filteredReleases {
		if !upToLatest {
			if *release.Draft {
				id := *release.ID
				upToLatest = request.Version.ID == strconv.Itoa(id)
			} else {
				version := *release.TagName
				upToLatest = request.Version.Tag == version
			}
		}

		if upToLatest {
			reversedVersions = append(reversedVersions, versionFromRelease(&release))
		}
	}

	if !upToLatest {
		// current version was removed; start over from latest
		reversedVersions = append(
			reversedVersions,
			versionFromRelease(&filteredReleases[len(filteredReleases)-1]),
		)
	}

	return reversedVersions, nil
}