func main() { root := os.Args[1] config := configuration.Configuration{ Storage: configuration.Storage{ "filesystem": configuration.Parameters{ "rootdirectory": root, }, }, } app := handlers.NewApp(context.Background(), config) if err := http.ListenAndServe(":8080", app); err != nil { log.Fatal(err) } }
func TestDocker(t *testing.T) { if os.Getuid() != 0 { t.Skip("pinkerton: must be root to create AUFS mounts") } // start Docker registry using test files cwd, err := os.Getwd() if err != nil { t.Fatal(err) } root := filepath.Join(cwd, "test", "files") config := configuration.Configuration{ Storage: configuration.Storage{ "filesystem": configuration.Parameters{ "rootdirectory": root, }, }, } logrus.SetLevel(logrus.ErrorLevel) app := handlers.NewApp(context.Background(), config) srv := httptest.NewServer(app) defer srv.Close() // create context tmp, err := ioutil.TempDir("", "pinkerton-test") if err != nil { t.Fatal(err) } defer os.RemoveAll(tmp) ctx, err := BuildContext("aufs", tmp) if err != nil { t.Fatal(err) } // pull image using digest imageID, err := ctx.PullDocker(srv.URL+"?name=pinkerton-test&id="+testImageDigest, ioutil.Discard) if err != nil { t.Fatal(err) } if imageID != testImageID { t.Fatalf("expected image to have ID %q, got %q", testImageID, imageID) } // checkout image name := random.String(8) path, err := ctx.Checkout(name, imageID) if err != nil { t.Fatal(err) } defer ctx.Cleanup(name) // check foo.txt exists and has correct data f, err := os.Open(filepath.Join(path, "foo.txt")) if err != nil { t.Fatal(err) } data, err := ioutil.ReadAll(f) f.Close() if err != nil { t.Fatal(err) } if !reflect.DeepEqual(data, []byte(testImageData)) { t.Fatalf("expected foo.txt to contain %q, got %q", testImageData, string(data)) } }