Beispiel #1
0
func MakeContainer(run ds.Run) (_ Container, err error) {
	if dkr == "" {
		return nil, errors.New("docker not enabled on this server")
	}
	ch := make(chan error, 1)
	con := &container{
		name: "via-circuit-" + lang.ChooseReceiverID().String()[1:],
		exit: ch,
	}
	con.cmd = exec.Command(dkr, run.Arg(con.name)...)
	con.cmd.Stdin, con.stdin = interruptible.BufferPipe(StdBufferLen)
	con.stdout, con.cmd.Stdout = interruptible.BufferPipe(StdBufferLen)
	con.stderr, con.cmd.Stderr = interruptible.BufferPipe(StdBufferLen)
	if err = con.cmd.Start(); err != nil {
		return nil, err
	}
	go func() {
		ch <- con.cmd.Wait()
		close(ch)
		con.cmd.Stdout.(io.Closer).Close()
		con.cmd.Stderr.(io.Closer).Close()
	}()
	runtime.SetFinalizer(con,
		func(c *container) {
			exec.Command(dkr, "rm", c.name).Run()
		},
	)
	return con, nil
}
Beispiel #2
0
func mkdkr(x *cli.Context) {
	defer func() {
		if r := recover(); r != nil {
			fatalf("error, likely due to missing server or misspelled anchor: %v", r)
		}
	}()
	c := dial(x)
	args := x.Args()
	if len(args) != 1 {
		fatalf("mkdkr needs an anchor argument")
	}
	w, _ := parseGlob(args[0])
	buf, _ := ioutil.ReadAll(os.Stdin)
	var run docker.Run
	if err := json.Unmarshal(buf, &run); err != nil {
		fatalf("command json not parsing: %v", err)
	}
	if x.Bool("scrub") {
		run.Scrub = true
	}
	_, err := c.Walk(w).MakeDocker(run)
	if err != nil {
		fatalf("mkdkr error: %s", err)
	}
}