func BuildContext(driver, root string) (*Context, error) { d, err := graphdriver.GetDriver(driver, root, nil) if err != nil { return nil, err } s, err := store.New(root, d) if err != nil { return nil, err } return NewContext(s, d), nil }
func main() { usage := `Pinkerton manages Docker images. Usage: pinkerton pull [options] <image-url> pinkerton checkout [options] <id> <image-id> pinkerton cleanup [options] <id> pinkerton -h | --help Commands: pull Download a Docker image checkout Create a working copy of an image cleanup Destroy a working copy of an image Examples: pinkerton pull https://registry.hub.docker.com/redis pinkerton pull https://registry.hub.docker.com/ubuntu?tag=trusty pinkerton pull https://registry.hub.docker.com/flynn/slugrunner?id=1443bd6a675b959693a1a4021d660bebbdbff688d00c65ff057c46702e4b8933 pinkerton checkout slugrunner-test 1443bd6a675b959693a1a4021d660bebbdbff688d00c65ff057c46702e4b8933 pinkerton cleanup slugrunner-test Options: -h, --help show this message and exit --driver=<name> storage driver [default: aufs] --root=<path> storage root [default: /var/lib/docker] --json emit json-formatted output ` args, _ := docopt.Parse(usage, nil, true, "", false) root := args.String["--root"] driver, err := graphdriver.GetDriver(args.String["--driver"], root, nil) if err != nil { log.Fatal(err) } s, err := store.New(root, driver) if err != nil { log.Fatal(err) } ctx := &Context{Store: s, driver: driver, json: args.Bool["--json"]} switch { case args.Bool["pull"]: ctx.Pull(args.String["<image-url>"]) case args.Bool["checkout"]: ctx.Checkout(args.String["<id>"], args.String["<image-id>"]) case args.Bool["cleanup"]: ctx.Cleanup(args.String["<id>"]) } }
func newDriver(t *testing.T, name string) *Driver { root, err := ioutil.TempDir("/var/tmp", "docker-graphtest-") if err != nil { t.Fatal(err) } if err := os.MkdirAll(root, 0755); err != nil { t.Fatal(err) } d, err := graphdriver.GetDriver(name, root, nil) if err != nil { if err == graphdriver.ErrNotSupported || err == graphdriver.ErrPrerequisites { t.Skip("Driver %s not supported", name) } t.Fatal(err) } return &Driver{d, root, 1} }
func BuildContext(driver, root string) (*Context, error) { d, err := graphdriver.GetDriver(driver, root, nil, nil, nil) if err != nil { return nil, err } g, err := graph.NewGraph(filepath.Join(root, "graph"), d, nil, nil) if err != nil { return nil, err } config := &graph.TagStoreConfig{ Graph: g, Events: events.New(), Registry: registry.NewService(nil), } store, err := graph.NewTagStore(filepath.Join(root, "repositories-"+d.String()), config) if err != nil { return nil, err } return NewContext(store, g, d), nil }