func (v *RabbitVersions) PreparationRequired() bool {
	toVersion := enforceSemver(v.Desired)
	fromVersion := enforceSemver(v.Deployed)
	breakingVersion := enforceSemver("3.6.6")

	patchUpgrade, _ := version.NewConstraint(fmt.Sprintf("~> %s", fromVersion))
	breakingVersionUpgrade, _ := version.NewConstraint(fmt.Sprintf("> %s, <= %s", fromVersion, toVersion))
	return breakingVersionUpgrade.Check(breakingVersion) || !patchUpgrade.Check(toVersion)
}
Esempio n. 2
0
// NewRethinkdb creates a new Rethinkdb database adaptor
func NewRethinkdb(p *pipe.Pipe, path string, extra Config) (StopStartListener, error) {
	var (
		conf rethinkDbConfig
		err  error
	)
	if err = extra.Construct(&conf); err != nil {
		return nil, err
	}

	u, err := url.Parse(conf.URI)
	if err != nil {
		return nil, err
	}

	if conf.Debug {
		fmt.Printf("rethinkDbConfig: %#v\n", conf)
	}

	r := &Rethinkdb{
		uri:  u,
		pipe: p,
		path: path,
		tail: conf.Tail,
	}

	r.database, r.table, err = extra.splitNamespace()
	if err != nil {
		return r, err
	}
	r.debug = conf.Debug

	opts := gorethink.ConnectOpts{
		Address: r.uri.Host,
		MaxIdle: 10,
		Timeout: time.Second * 10,
	}
	if conf.Timeout > 0 {
		opts.Timeout = time.Duration(conf.Timeout) * time.Second
	}

	r.client, err = gorethink.Connect(opts)
	if err != nil {
		return r, err
	}
	r.client.Use(r.database)

	if r.tail {
		constraint, _ := version.NewConstraint(">= 1.16")
		if err := r.assertServerVersion(constraint); err != nil {
			return r, err
		}
	}

	return r, nil
}
Esempio n. 3
0
func Constraint(constraint, version string) bool {
	c, err := semver.NewConstraint(constraint)
	if err != nil {
		idl.Err(err)
		return false
	}

	v, err := semver.NewVersion(version)
	if err != nil {
		idl.Debug(err)
		return false
	}

	return c.Check(v)
}
Esempio n. 4
0
func CheckDockerVersion(t Target) (res Result) {
	res.Name = "1.5 Keep Docker up to date"
	verConstr := os.Getenv("VERSION")
	info, err := t.Client.ServerVersion()
	if err != nil {
		log.Fatalf("Could not retrieve info for Docker host")
	}
	constraints, _ := version.NewConstraint(">= " + verConstr)
	hostVersion, _ := version.NewVersion(info.Version)
	if constraints.Check(hostVersion) {
		res.Pass()
	} else {
		output := fmt.Sprintf("Host is using an outdated Docker server: %s ",
			info.Version)
		res.Fail(output)
	}
	return
}
Esempio n. 5
0
func CheckKernelVersion(t Target) (res Result) {
	res.Name = "1.2 Use the updated Linux Kernel"
	info := t.Info
	constraints, _ := version.NewConstraint(">= 3.10")
	hostVersion, err := version.NewVersion(info.KernelVersion)
	if err != nil {
		// necessary fix for incompatible kernel versions (e.g. Fedora 23)
		log.Print("Incompatible kernel version")
		output := "Incompatible kernel version reported"
		res.Info(output)
		return
	}
	if constraints.Check(hostVersion) {
		res.Pass()
	} else {
		output := fmt.Sprintf("Host is not using an updated kernel: %s",
			info.KernelVersion)
		res.Fail(output)
	}
	return
}
Esempio n. 6
0
func main() {
	config := config.New()
	apiConfig, err := config.Registry.Config()
	if err != nil {
		log.Fatal(err.Error())
	}

	kv, err := consul.NewKV(apiConfig)
	if err != nil {
		log.Fatal(err.Error())
	}

	consul := consul.NewConsul(kv, config.Registry.Prefix)

	// set up initial sync
	remote, err := config.Marathon.NewMarathon()
	if err != nil {
		log.Fatal(err.Error())
	}
	sync := marathon.NewMarathonSync(remote, consul)
	go sync.Sync()

	fh := &ForwardHandler{consul}

	v, err := remote.Version()
	if err != nil {
		log.WithError(err).Warn("version parsing failed, assuming >= 0.9.0")
		v, _ = version.NewVersion("0.9.0")
	}
	minVersion, _ := version.NewConstraint(">= 0.9.0")

	if minVersion.Check(v) {
		log.WithField("version", v).Info("detected Marathon events endpoint")
		SubscribeToEventStream(config, remote, fh)
	} else {
		log.WithField("version", v).Info("detected old Marathon version -- make sure to set up an eventSubscription for this process")
		ServeWebhookReceiver(config, fh)
	}
}
Esempio n. 7
0
// gitPreflight is the pre-flight command that runs for Git-based VCSs
func gitPreflight(path string) error {
	var stderr, stdout bytes.Buffer

	cmd := exec.Command("git", "--version")
	cmd.Dir = path
	cmd.Stdout = &stdout
	cmd.Stderr = &stderr
	if err := cmd.Run(); err != nil {
		return fmt.Errorf("error getting git version: %s\nstdout: %s\nstderr: %s",
			err, stdout.String(), stderr.String())
	}

	// Check if the output is valid
	output := strings.Split(strings.TrimSpace(stdout.String()), " ")
	if len(output) < 1 {
		log.Printf("[WARN] could not extract version output from Git")
		return nil
	}

	// Parse the version
	gitv, err := version.NewVersion(output[len(output)-1])
	if err != nil {
		log.Printf("[WARN] could not parse version output from Git")
		return nil
	}

	constraint, err := version.NewConstraint("> 1.8")
	if err != nil {
		log.Printf("[WARN] could not create version constraint to check")
		return nil
	}
	if !constraint.Check(gitv) {
		return fmt.Errorf("git version (%s) is too old, please upgrade", gitv.String())
	}

	return nil
}
Esempio n. 8
0
// NewRethinkdb creates a new Rethinkdb database adaptor
func NewRethinkdb(p *pipe.Pipe, path string, extra Config) (StopStartListener, error) {
	var (
		conf rethinkDbConfig
		err  error
	)
	if err = extra.Construct(&conf); err != nil {
		return nil, err
	}

	u, err := url.Parse(conf.URI)
	if err != nil {
		return nil, err
	}

	if conf.Debug {
		fmt.Printf("RethinkDB Config %+v\n", conf)
	}

	r := &Rethinkdb{
		uri:  u,
		pipe: p,
		path: path,
		tail: conf.Tail,
	}

	r.database, r.tableMatch, err = extra.compileNamespace()
	if err != nil {
		return r, err
	}
	r.debug = conf.Debug
	if r.debug {
		fmt.Printf("tableMatch: %+v\n", r.tableMatch)
	}

	// test the connection with a timeout
	testConn, err := gorethink.Connect(gorethink.ConnectOpts{
		Address: r.uri.Host,
		Timeout: time.Second * 10,
	})
	if err != nil {
		return r, err
	}
	testConn.Close()

	// we don't want a timeout here because we want to keep connections open
	r.client, err = gorethink.Connect(gorethink.ConnectOpts{
		Address: r.uri.Host,
		MaxIdle: 10,
	})
	if err != nil {
		return r, err
	}
	r.client.Use(r.database)

	constraint, _ := version.NewConstraint(">= 2.0")
	if err := r.assertServerVersion(constraint); err != nil {
		return r, err
	}

	return r, nil
}
Esempio n. 9
0
func getLatestVersionMatchingPattern(repo string, versionPattern string) (string, error) {
	repoPath, err := getPackageRootDir(repo)
	if err != nil {
		return "", errors.Trace(err)
	}

	if exists, _ := pathExists(repoPath); !exists {
		return versionPattern, nil
	}

	wd, err := os.Getwd()
	if err != nil {
		return "", errors.Trace(err)
	}

	err = os.Chdir(repoPath)
	if err != nil {
		return "", errors.Trace(err)
	}

	defer func() {
		_ = os.Chdir(wd)
	}()

	var repoType string

	if exists, _ := pathExists(".git"); exists {
		repoType = "git"
	} else if exists, _ := pathExists(".hg"); exists {
		repoType = "hg"
	} else if exists, _ := pathExists(".bzr"); exists {
		repoType = "bzr"
	} else {
		return versionPattern, nil
	}

	if versionPattern == "" {
		if repoType == "git" {
			return "master", nil
		} else if repoType == "hg" {
			return "tip", nil
		} else if repoType == "bzr" {
			return "", nil
		}
	}

	if repoType == "hg" || repoType == "bzr" {
		return versionPattern, nil
	}

	// first, try feeding it through git to see if it's a valid rev
	gitResolveCommand := []string{"git", "rev-parse", "-q", "--verify", versionPattern}
	output, err := exec.Command(gitResolveCommand[0], gitResolveCommand[1:]...).Output()

	if err != nil {
		if _, ok := err.(*exec.ExitError); !ok {
			return "", errors.Trace(err)
		}
	}

	gitResolvedString := strings.TrimSpace(string(output))

	if gitResolvedString != "" {
		return gitResolvedString, nil
	}

	// second, try parsing it
	tagListB, err := exec.Command("git", "tag").Output()
	if err != nil {
		return "", errors.Trace(err)
	}

	versionToTag := make(map[*version.Version]string)

	tagList := strings.Split(strings.TrimSpace(string(tagListB)), "\n")
	processedTagList := make([]*version.Version, len(tagList))
	for i, tag := range tagList {
		stringVersion := tag

		if strings.HasPrefix(tag, "v") {
			stringVersion = strings.Replace(tag, "v", "", 1)
		}

		v, err := version.NewVersion(stringVersion)
		if err != nil {
			continue
		}

		processedTagList[i] = v
		versionToTag[v] = tag
	}

	sort.Sort(version.Collection(processedTagList))

	constraints, err := version.NewConstraint(versionPattern)
	if err != nil {
		return "", errors.Trace(err)
	}

	var resultVersion string
	for i := len(processedTagList) - 1; i >= 0; i-- {
		ver := processedTagList[i]
		if constraints.Check(ver) {
			resultVersion = versionToTag[ver]
		}
	}

	if resultVersion == "" {
		return "", fmt.Errorf("unable to find a version matching constraint %s for package %s", versionPattern, repo)
	}

	gitResolveCommand = []string{"git", "rev-parse", "-q", "--verify", resultVersion}
	output, err = exec.Command(gitResolveCommand[0], gitResolveCommand[1:]...).Output()

	if err != nil {
		return "", errors.Trace(err)
	} else {
		return strings.TrimSpace(string(output)), nil
	}
}