Ejemplo n.º 1
0
// parseYAML parses the config.yml file and returns the appropriate structs and strings.
func YAMLtoETCD(client *etcd.Client) (c goship.Config, err error) {
	config, err := yaml.ReadFile(*ConfigFile)
	if err != nil {
		return c, err
	}
	log.Printf("Setting project root => /projects")
	client.CreateDir("/projects", 0)
	configRoot, _ := config.Root.(yaml.Map)
	projects, _ := configRoot["projects"].(yaml.List)
	for _, p := range projects {
		for k, v := range p.(yaml.Map) {

			projectPath := "/projects/" + k + "/"

			log.Printf("Setting project => %s \n", projectPath)
			client.CreateDir(projectPath, 0)

			name := getYAMLString(v, "project_name")
			setETCD(client, projectPath+"project_name", name)

			repoOwner := getYAMLString(v, "repo_owner")
			setETCD(client, projectPath+"repo_owner", repoOwner)

			repoName := getYAMLString(v, "repo_name")
			setETCD(client, projectPath+"repo_name", repoName)

			for _, v := range v.(yaml.Map)["environments"].(yaml.List) {
				YAMLtoETCDEnvironment(v, client, projectPath)
			}

		}
	}

	pivProject, _ := config.Get("pivotal_project")
	setETCD(client, "pivotal_project", pivProject)

	pivToken, _ := config.Get("pivotal_token")
	setETCD(client, "pivotal_token", pivToken)

	deployUser, _ := config.Get("deploy_user")
	setETCD(client, "deploy_user", deployUser)

	goshipHost, _ := config.Get("goship_host")
	setETCD(client, "goship_host", goshipHost)

	notify, _ := config.Get("notify")
	setETCD(client, "notify", notify)

	return c, err
}
Ejemplo n.º 2
0
// parseYAMLEnvironment populates an Environment given a yaml.Node and returns the Environment.
func YAMLtoETCDEnvironment(m yaml.Node, client *etcd.Client, projPath string) {

	for k, v := range m.(yaml.Map) {
		projPath = projPath + "environments/" + k + "/"

		log.Printf("Setting env name=> %s \n", projPath)
		client.CreateDir(projPath, 0)

		branch := getYAMLString(v, "branch")
		setETCD(client, projPath+"branch", branch)

		repoPath := getYAMLString(v, "repo_path")
		setETCD(client, projPath+"repo_path", repoPath)

		deploy := getYAMLString(v, "deploy")
		setETCD(client, projPath+"deploy", deploy)

		projPath = projPath + "hosts/"
		log.Printf("Creating Host Directory => %s \n", projPath+"hosts/")
		client.CreateDir(projPath, 0)

		for _, host := range v.(yaml.Map)["hosts"].(yaml.List) {
			h := goship.Host{URI: host.(yaml.Scalar).String()}
			log.Printf("Setting Hosts => %s \n", projPath+h.URI)
			client.CreateDir(projPath+h.URI, 0)
		}
	}
}
Ejemplo n.º 3
0
// NewEtcdEphemeral creates a etcd implementation of ephemeral
// TODO: add option for user to support:
//       1. fatal after retrying set heartbeat many times
func NewEtcdEphemeral(client *etcd.Client, options ...func(*EtcdEphemeral) error) (*EtcdEphemeral, error) {
	impl := &EtcdEphemeral{
		client:       client,
		ctr:          dummyStat{},
		ephemeralTTL: DefaultEphemeralTTL,
		listCancel:   make(map[context.Context]func()),
	}

	// Set options.
	for _, option := range options {
		if err := option(impl); err != nil {
			return nil, err
		}
	}

	// ensure ephemeral dir exists, the error is not important
	if _, err := client.CreateDir(WatcherDir, 0); err != nil &&
		translateEtcdErr(err) != ErrPathExists {
		return nil, err
	}

	return impl, nil
}
Ejemplo n.º 4
0
func mkdirEtcd(client *etcd.Client, path string) {
	_, err := client.CreateDir(path, 0)
	if err != nil && !strings.Contains(err.Error(), "Key already exists") {
		log.Warn(err)
	}
}
Ejemplo n.º 5
0
func mkdirEtcd(client *etcd.Client, path string) {
	_, err := client.CreateDir(path, 0)
	if err != nil {
		log.Warn(err)
	}
}