Example #1
0
func uploadProject(appInfo *apps.AppInfo, repoPath string) (*api.File, error) {
	// TODO: ignore files

	fileDir, err := ioutil.TempDir("", "leanengine")
	if err != nil {
		return nil, err
	}

	filePath := filepath.Join(fileDir, "leanengine.zip")
	println(filePath)

	log.Println("压缩项目文件 ...")
	zip := new(archivex.ZipFile)
	func() {
		defer zip.Close()
		zip.Create(filePath)
		zip.AddAll(repoPath, false)
	}()

	log.Println("上传项目文件 ...")
	client := api.NewKeyAuthClient(appInfo.AppID, appInfo.MasterKey)
	file, err := client.UploadFile(filePath)
	utils.CheckError(err)

	return file, nil
}
Example #2
0
func deployGroupName(appInfo *apps.AppInfo) (string, error) {
	client := api.NewKeyAuthClient(appInfo.AppID, appInfo.MasterKey)

	engineInfo, err := client.EngineInfo()
	if err != nil {
		return "", err
	}
	mode := engineInfo.Get("mode").MustString()

	groups, err := client.Groups()
	if err != nil {
		return "", err
	}

	groupName, found, err := linq.From(groups.MustArray()).Where(func(_group linq.T) (bool, error) {
		groupName := _group.(map[string]interface{})["groupName"].(string)
		if mode == "free" {
			return groupName != "staging", nil
		}
		return groupName == "staging", nil
	}).Select(func(group linq.T) (linq.T, error) {
		return group.(map[string]interface{})["groupName"], nil
	}).First()
	if err != nil {
		return "", err
	}
	if !found {
		return "", errors.New("group not found")
	}
	return groupName.(string), nil
}
Example #3
0
func getAppInfoFromServer(appID string) (*AppInfo, error) {
	masterKey := new(string)
	wizard.Ask([]wizard.Question{
		{
			Content: "请输入应用的 Master Key:",
			Input: &wizard.Input{
				Hidden: true,
				Result: masterKey,
			},
		},
	})

	client := api.NewKeyAuthClient(appID, *masterKey)

	content, err := client.AppDetail()
	if err != nil {
		return nil, err
	}

	return &AppInfo{
		AppID:     appID,
		AppKey:    content.Get("app_key").MustString(),
		MasterKey: *masterKey,
	}, nil
}
Example #4
0
func deployFromLocal(appInfo *apps.AppInfo, groupName string) {
	file, err := uploadProject(appInfo, "")
	utils.CheckError(err)

	client := api.NewKeyAuthClient(appInfo.AppID, appInfo.MasterKey)

	_, err = client.BuildFromURL(groupName, file.URL)
	utils.CheckError(err)

	err = client.DeleteFile(file.ID)
	utils.CheckError(err)
}
Example #5
0
func newAction(*cli.Context) error {
	apps, err := api.GetAppList()
	if err != nil {
		return err
	}
	app := selectApp(apps)
	appID := app["app_id"].(string)
	masterKey := app["master_key"].(string)

	runtime := selectRuntime()

	client := api.NewKeyAuthClient(appID, masterKey)

	detail, err := client.AppDetail()
	utils.CheckError(err)
	appName := detail.Get("app_name").MustString()

	err = boilerplate.FetchRepo(runtime, appName, appID)
	return err
}
Example #6
0
func deployFromGit(appInfo *apps.AppInfo, groupName string) {
	client := api.NewKeyAuthClient(appInfo.AppID, appInfo.MasterKey)

	_, err := client.BuildFromGit(groupName)
	utils.CheckError(err)
}