Example #1
0
func push(c *config.Config, q *registry.Queue) error {
	scriptsPath := utils.PackagePath(selfPkg)
	host := c.GetRequired("push")

	// FTP User & password
	user := q.NextTask()
	if user == "" {
		return fmt.Errorf("ftp user required as the first argument")
	}
	q.RemoveNextTask()

	password, err := gopass.GetPass(fmt.Sprintf("Enter \"%s\" password: "******"cannot read password: %s", err)
	}
	if password == "" {
		return fmt.Errorf("ftp password is required")
	}

	// Hash local files
	log.Printf("Hashing local files... ")
	localHashes, err := hashLocalFiles()
	if err != nil {
		return fmt.Errorf("hash local files failed: %s", err)
	}
	log.Printf("Hashing local files... %s[SUCCESS]%s\n", colors.Green, colors.Reset)

	// Hash remote files
	log.Printf("Hashing remote files... ")
	remoteHashes, err := retrieveRemoteHashes(scriptsPath, user, password, host)
	if err != nil {
		return fmt.Errorf("retrieve remote hashes failed: %s", err)
	}
	log.Printf("Hashing remote files... %s[SUCCESS]%s\n", colors.Green, colors.Reset)

	if err := saveLocalHashes(localHashes); err != nil {
		return fmt.Errorf("save local hashes failed: %s", err)
	}

	// Prepare FTP commands
	log.Printf("Preparing FTP commands... ")
	if err := prepareFTPCommands(localHashes, remoteHashes); err != nil {
		return fmt.Errorf("prepare FTP commands failed: %s", err)
	}
	log.Printf("Preparing FTP commands... %s[SUCCESS]%s\n", colors.Green, colors.Reset)

	// Upload files
	log.Printf("Uploading files... ")
	if err := uploadFiles(scriptsPath, user, password, host); err != nil {
		return fmt.Errorf("uploading files failed: %s", err)
	}
	log.Printf("Uploading files... %s[SUCCESS]%s\n", colors.Green, colors.Reset)

	return nil
}
Example #2
0
func fetchCurrentCommit() (string, error) {
	path := utils.PackagePath("github.com/ernestokarim/cb")

	args := []string{
		"--git-dir", filepath.Join(path, ".git"),
		"--work-tree", path,
		"rev-parse",
		"HEAD",
	}
	output, err := utils.Exec("git", args)
	if err != nil {
		return "", fmt.Errorf("cannot parse git head revision: %s", err)
	}

	return strings.TrimSpace(output), nil
}
Example #3
0
func deploy(c *config.Config, q *registry.Queue) error {
	parts := strings.Split(q.CurTask, ":")
	base := utils.PackagePath(filepath.Join(selfPkg, parts[1]+".sh"))

	args := []string{
		filepath.Base(c.GetRequired("paths.base")),
	}
	if err := utils.ExecCopyOutput(base, args); err != nil {
		return fmt.Errorf("deploy failed: %s", err)
	}

	if err := organizeResult(c); err != nil {
		return fmt.Errorf("cannot organize result: %s", err)
	}

	return nil
}
Example #4
0
func htmlcompressor(src, dest string) error {
	base := utils.PackagePath(selfPkg)
	jarFile := filepath.Join(base, "htmlcompressor-1.5.3.jar")

	args := []string{
		"-jar", jarFile,
		"--type", "html",
		"-o", dest,
		"-r", src,
	}
	output, err := utils.Exec("java", args)
	if err != nil {
		fmt.Println(output)
		return fmt.Errorf("compressor error: %s", err)
	}

	return nil
}
Example #5
0
func writeFile(path string, tmpl string, data interface{}) error {
	if *config.Verbose {
		log.Printf("write file %s\n", path)
	}

	exists := true
	if _, err := os.Stat(path); err != nil {
		if os.IsNotExist(err) {
			exists = false
		} else {
			return fmt.Errorf("stat failed: %s", err)
		}
	}

	dir := filepath.Dir(path)
	if err := os.MkdirAll(dir, 0755); err != nil {
		return fmt.Errorf("mkdir all failed (%s): %s", dir, err)
	}

	f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		return fmt.Errorf("open file failed: %s", err)
	}
	defer f.Close()

	tmpl = filepath.Join(utils.PackagePath(selfPkg), tmpl)
	t, err := template.ParseFiles(tmpl)
	if err != nil {
		return fmt.Errorf("parse template failed: %s", err)
	}

	if err := t.Execute(f, &fileData{data, exists}); err != nil {
		return fmt.Errorf("execute template failed: %s", err)
	}

	return nil
}
Example #6
0
func initTask(c *config.Config, q *registry.Queue) error {
	// Check for updates
	if err := q.RunTasks(c, []string{"update:check"}); err != nil {
		return err
	}

	// Retrieve the current working directory
	cur, err := os.Getwd()
	if err != nil {
		return fmt.Errorf("getwd failed: %s", err)
	}

	// Go back one folder if we're inside the client one
	if filepath.Base(cur) == "client" {
		cur = filepath.Dir(cur)
		if pathErr := os.Chdir(cur); pathErr != nil {
			return fmt.Errorf("chdir to root folder failed: %s", err)
		}
	}

	// Prepare some paths and start copying from the root templates folder
	parts := strings.Split(q.CurTask, ":")
	base := utils.PackagePath(filepath.Join(selfPkg, parts[1]))
	appname := filepath.Base(cur)

	if err := copyFiles(c, appname, base, cur, cur); err != nil {
		return fmt.Errorf("copy files failed: %s", err)
	}

	// Post-init steps
	if err := postInit(); err != nil {
		return fmt.Errorf("post init failed: %s", err)
	}

	return nil
}