示例#1
0
// copyBanyanData copies all the default scripts and binaries (e.g., bash-static, python-static, etc.)
// to BANYANDIR (so that it can be mounted into collector/target containers)
func copyBanyanData() {
	fsutil.CopyDir(config.COLLECTORDIR()+"/data/defaultscripts", collector.DefaultScriptsDir)
	//copy scripts from user specified/default directory to userScriptsDir for mounting
	fsutil.CopyDir(*collector.UserScriptStore, collector.UserScriptsDir)
	// * needed to copy into binDir (rather than a subdir called bin)
	fsutil.CopyDirTree(config.COLLECTORDIR()+"/data/bin/*", collector.BinDir)
}
func TestBashScriptRun(t *testing.T) {
	var e error
	DockerTransport, e = NewDockerTransport(DOCKERPROTO, DOCKERADDR)
	if e != nil {
		t.Fatal(e)
	}
	RegistrySpec = "index.docker.io"
	RegistryAPIURL, HubAPI, BasicAuth, XRegistryAuth = GetRegistryURL()
	metadata := ImageMetadataInfo{
		OtherMetadata: OtherMetadata{
			Repo: "ubuntu",
			Tag:  "latest",
		},
	}
	fmt.Println("TestPullImage %v", metadata)
	PullImage(&metadata)

	PWD := os.Getenv("PWD")
	os.Setenv("BANYAN_HOST_DIR", PWD+"/banyandir")
	fsutil.CreateDirIfNotExist(os.Getenv("BANYAN_HOST_DIR") + "/hosttarget/bin")
	defer os.RemoveAll(os.Getenv("BANYAN_HOST_DIR"))
	fsutil.CreateDirIfNotExist(os.Getenv("BANYAN_HOST_DIR") + "/hosttarget/defaultscripts")
	fsutil.CopyDirTree(os.Getenv("PWD")+"/data/bin/*", os.Getenv("BANYAN_HOST_DIR")+"/hosttarget/bin")
	fsutil.CopyDir(os.Getenv("PWD")+"/data/defaultscripts", os.Getenv("BANYAN_HOST_DIR")+"/hosttarget/defaultscripts")
	bs := newBashScript("pkgextractscript.sh", "/banyancollector/defaultscripts", []string{})
	b, err := bs.Run(ImageIDType("ubuntu"))
	if err != nil {
		t.Fatal(err)
	}
	fmt.Println("Run returned", string(b))
}