/
depot.go
73 lines (59 loc) · 1.6 KB
/
depot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package gardenrunc
import (
"fmt"
"os"
"os/exec"
"path"
"github.com/nu7hatch/gouuid"
"github.com/onsi/gomega/gexec"
)
//go:generate counterfeiter . Depot
type Depot interface {
Create() (string, error)
}
type ContainerDepot struct {
Dir string
}
func (depot *ContainerDepot) Create() (string, error) {
containerDir := path.Join(depot.Dir, guid())
runDir := path.Join(containerDir, "run")
binDir := path.Join(containerDir, "bin")
processesDir := path.Join(containerDir, "processes")
os.MkdirAll(runDir, 0700)
os.MkdirAll(processesDir, 0700)
if err := os.MkdirAll(binDir, 0777); err != nil {
panic(err)
}
// FIXME(jz) remove all this hackery and just re-exec
iodaemonPath, err := gexec.Build("github.com/cloudfoundry-incubator/garden-linux/iodaemon")
if err != nil {
return "", fmt.Errorf("build iodaemon: %s", err)
}
doshPath, err := gexec.Build("github.com/julz/garden-runc/cmd/dosh")
if err != nil {
return "", fmt.Errorf("build dosh: %s", err)
}
cp := exec.Command("cp", iodaemonPath, path.Join(binDir, "iodaemon"))
cp.Stderr = os.Stderr
if err := cp.Run(); err != nil {
return "", fmt.Errorf("copy iodaemon: %s", err)
}
cp = exec.Command("cp", doshPath, path.Join(binDir, "dosh"))
cp.Stderr = os.Stderr
if err := cp.Run(); err != nil {
return "", fmt.Errorf("copy dosh: %s", err)
}
cp = exec.Command("chmod", "u+x", path.Join(binDir, "dosh"))
cp.Stderr = os.Stderr
if err := cp.Run(); err != nil {
return "", fmt.Errorf("chmod dosh: %s", err)
}
return containerDir, nil
}
func guid() string {
u, err := uuid.NewV4()
if err != nil {
panic(err)
}
return u.String()
}