コード例 #1
0
ファイル: deploy_handler.go プロジェクト: kgrvamsi/goship
// getDeployCommand returns the deployment command for a given
// environment as a string slice that has been split on spaces.
func getDeployCommand(projects []config.Project, projectName, environmentName string) (s []string, err error) {
	e, err := config.EnvironmentFromName(projects, projectName, environmentName)
	if err != nil {
		return s, err
	}

	return strings.Split(e.Deploy, " "), nil
}
コード例 #2
0
ファイル: types_test.go プロジェクト: kgrvamsi/goship
func TestGetEnvironmentFromName(t *testing.T) {
	var (
		want = config.Environment{Name: "TestEnvironment"}
		envs = []config.Environment{want}
	)
	projects := []config.Project{config.Project{Name: "TestProject", Environments: envs}}
	got, err := config.EnvironmentFromName(projects, "TestProject", "TestEnvironment")
	if err != nil {
		t.Fatal(err)
	}
	if !reflect.DeepEqual(got, &want) {
		t.Errorf("config.EnvironmentFromName = %v, want %v", got, want)
	}
	got, err = config.EnvironmentFromName(projects, "BadProject", "BadEnvironment")
	if err == nil {
		t.Errorf("config.EnvironmentFromName error case did not error")
	}
}
コード例 #3
0
ファイル: main.go プロジェクト: kgrvamsi/goship
func extractDeployLogHandler(ac acl.AccessControl, ecl *etcd.Client, fn func(http.ResponseWriter, *http.Request, string, config.Environment, string)) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		m := validPathWithEnv.FindStringSubmatch(r.URL.Path)
		if m == nil {
			http.NotFound(w, r)
			return
		}
		c, err := config.Load(ecl)
		if err != nil {
			glog.Errorf("Failed to get current configuration: %v", err)
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		// auth check for user
		u, err := auth.CurrentUser(r)
		if err != nil {
			glog.Error("Failed to get a user while deploying in Auth Mode: %v", err)
			http.Error(w, err.Error(), http.StatusUnauthorized)
		}
		c.Projects = acl.ReadableProjects(ac, c.Projects, u)
		// get project name and env from url
		a := strings.Split(m[2], "-")
		l := len(a)
		environmentName := a[l-1]
		var projectName string
		if m[1] == "commits" {
			projectName = m[2]
		} else {
			projectName = strings.Join(a[0:l-1], "-")
		}
		e, err := config.EnvironmentFromName(c.Projects, projectName, environmentName)
		if err != nil {
			glog.Errorf("Can't get environment from name: %v", err)
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		fn(w, r, m[2], *e, projectName)
	}
}
コード例 #4
0
ファイル: deploy.go プロジェクト: kgrvamsi/goship
func main() {
	flag.Parse()
	conf := parseConfig()
	if *skipUpdate == false {
		updateChefRepo(conf)
	}
	if *pullOnly == false {
		c, err := gsconfig.Load(etcd.NewClient([]string{conf.etcdServer}))
		if err != nil {
			glog.Fatalf("Error parsing ETCD: %s", err)
		}
		projectEnv, err := gsconfig.EnvironmentFromName(c.Projects, *deployProj, *deployEnv)
		if err != nil {
			glog.Fatalf("Error getting project %s %s %s", *deployProj, *deployEnv, err)
		}
		glog.Infof("Deploying project name: %s environment Name: %s", *deployEnv, projectEnv.Name)
		servers := projectEnv.Hosts
		var d, e string
		if *chefRunlist != "" {
			e = " -o \"" + *chefRunlist + "\" "
		}
		for _, h := range servers {
			if *bootstrap == true {
				d = "knife solo bootstrap -c " + conf.knifePath + " -i " + conf.pemKey + " --no-host-key-verify " + e + conf.deployUser + "@" + h.URI
			} else {
				d = "knife solo cook -c " + conf.knifePath + " -i " + conf.pemKey + " --no-host-key-verify " + e + conf.deployUser + "@" + h.URI
			}
			glog.Infof("Deploying to server: %s", h.URI)
			glog.Infof("Preparing Knife command: %s", d)
			_, err := execCmd(d, conf)
			if err != nil {
				glog.Fatalf("Error Executing command %s", err)
			}
		}
	}

}