コード例 #1
0
// Launch runs a new docker container with the given process data.
func Launch(p charm.Process) (ProcDetails, error) {
	args, err := launchArgs(p)
	if err != nil {
		return ProcDetails{}, err
	}
	d := deputy.Deputy{
		Errors: deputy.FromStderr,
	}
	cmd := execCommand("docker", args...)
	out := &bytes.Buffer{}
	cmd.Stdout = out
	if err := d.Run(cmd); err != nil {
		return ProcDetails{}, err
	}
	id := string(bytes.TrimSpace(out.Bytes()))
	status, err := inspect(id)
	if err != nil {
		return ProcDetails{}, fmt.Errorf("can't get status for container %q: %s", id, err)
	}
	return ProcDetails{
		ID: strings.TrimPrefix(status.Name, "/"),
		Status: ProcStatus{
			State: status.brief(),
		},
	}, nil
}
コード例 #2
0
// inspect calls docker inspect and returns the unmarshaled json response.
func inspect(id string) (status, error) {
	cmd := execCommand("docker", "inspect", id)
	out := &bytes.Buffer{}
	cmd.Stdout = out
	d := deputy.Deputy{
		Errors: deputy.FromStderr,
	}
	if err := d.Run(cmd); err != nil {
		return status{}, err
	}
	return statusFromInspect(id, out.Bytes())
}
コード例 #3
0
ファイル: example_test.go プロジェクト: tjyang/deputy
func Example() {
	// Make a new deputy that'll return the data written to stderr as the error
	// message, log everything written to stdout to this application's log,  and
	// timeout after 30 seconds.
	d := deputy.Deputy{
		Errors:    deputy.FromStderr,
		StdoutLog: func(b []byte) { log.Print(string(b)) },
		Timeout:   time.Second * 30,
	}
	if err := d.Run(exec.Command("foo")); err != nil {
		log.Print(err)
	}
}
コード例 #4
0
// Destroy stops and removes the docker container with the given id.
func Destroy(id string) error {
	d := deputy.Deputy{
		Errors: deputy.FromStderr,
	}
	cmd := execCommand("docker", "stop", id)
	if err := d.Run(cmd); err != nil {
		return fmt.Errorf("error while stopping container %q: %s", err)
	}

	cmd = execCommand("docker", "rm", id)
	if err := d.Run(cmd); err != nil {
		return fmt.Errorf("error while removing container %q: %s", err)
	}
	return nil
}
コード例 #5
0
ファイル: main.go プロジェクト: groob/autopkgd
func makeCatalogs(makeCatalogsPath, repoPath string, execTimeout time.Duration) {
	makecatalogsCmd := exec.Command(
		makeCatalogsPath,
		repoPath,
	)
	d := deputy.Deputy{
		Errors:    deputy.FromStderr,
		StdoutLog: func(b []byte) { log.Println(string(b)) },
		Timeout:   time.Second * execTimeout,
	}
	if err := d.Run(makecatalogsCmd); err != nil {
		log.Println(err)
		return
	}
}
コード例 #6
0
ファイル: helpers.go プロジェクト: artushin/docker-build
func execute(cmd string) (string, error) {
	if len(cmd) == 0 {
		return "", ErrNoCommand
	}

	var value string
	d := deputy.Deputy{
		Errors: deputy.FromStderr,
		StdoutLog: func(b []byte) {
			value = string(b)
		},
	}
	if err := d.Run(exec.Command("sh", "-c", cmd)); err != nil {
		return "", err
	}
	return value, nil
}
コード例 #7
0
ファイル: main.go プロジェクト: groob/autopkgd
func runAutopkg(recipe, reportsPath, cmdPath string, check bool, execTimeout time.Duration) autopkgReport {
	autopkgCmd := exec.Command(cmdPath, "run", "--report-plist="+reportsPath+"/"+recipe)

	if check {
		autopkgCmd.Args = append(autopkgCmd.Args, "--check")
	}

	autopkgCmd.Args = append(autopkgCmd.Args, recipe)
	d := deputy.Deputy{
		Errors:    deputy.FromStderr,
		StdoutLog: func(b []byte) { log.Print(string(b)) },
		Timeout:   time.Second * execTimeout,
	}
	if err := d.Run(autopkgCmd); err != nil {
		log.Println(err)
		return autopkgReport{}
	}
	report, err := readReportPlist(reportsPath + "/" + recipe)
	if err != nil {
		log.Println(err)
		return autopkgReport{}
	}
	return report
}