Пример #1
0
func mkRuntimeFromEngine(eng *engine.Engine, t utils.Fataler) *docker.Runtime {
	iRuntime := eng.Hack_GetGlobalVar("httpapi.runtime")
	if iRuntime == nil {
		panic("Legacy runtime field not set in engine")
	}
	runtime, ok := iRuntime.(*docker.Runtime)
	if !ok {
		panic("Legacy runtime field in engine does not cast to *docker.Runtime")
	}
	return runtime
}
Пример #2
0
func mkServerFromEngine(eng *engine.Engine, t utils.Fataler) *docker.Server {
	iSrv := eng.Hack_GetGlobalVar("httpapi.server")
	if iSrv == nil {
		panic("Legacy server field not set in engine")
	}
	srv, ok := iSrv.(*docker.Server)
	if !ok {
		panic("Legacy server field in engine does not cast to *docker.Server")
	}
	return srv
}
Пример #3
0
func mkDaemonFromEngine(eng *engine.Engine, t utils.Fataler) *daemon.Daemon {
	iDaemon := eng.Hack_GetGlobalVar("httpapi.daemon")
	if iDaemon == nil {
		panic("Legacy daemon field not set in engine")
	}
	daemon, ok := iDaemon.(*daemon.Daemon)
	if !ok {
		panic("Legacy daemon field in engine does not cast to *daemon.Daemon")
	}
	return daemon
}
Пример #4
0
func buildImage(context testContextTemplate, t *testing.T, eng *engine.Engine, useCache bool) (*image.Image, error) {
	if eng == nil {
		eng = NewTestEngine(t)
		runtime := mkDaemonFromEngine(eng, t)
		// FIXME: we might not need runtime, why not simply nuke
		// the engine?
		defer nuke(runtime)
	}
	srv := mkServerFromEngine(eng, t)

	httpServer, err := mkTestingFileServer(context.remoteFiles)
	if err != nil {
		t.Fatal(err)
	}
	defer httpServer.Close()

	idx := strings.LastIndex(httpServer.URL, ":")
	if idx < 0 {
		t.Fatalf("could not get port from test http server address %s", httpServer.URL)
	}
	port := httpServer.URL[idx+1:]

	iIP := eng.Hack_GetGlobalVar("httpapi.bridgeIP")
	if iIP == nil {
		t.Fatal("Legacy bridgeIP field not set in engine")
	}
	ip, ok := iIP.(net.IP)
	if !ok {
		panic("Legacy bridgeIP field in engine does not cast to net.IP")
	}
	dockerfile := constructDockerfile(context.dockerfile, ip, port)

	buildfile := server.NewBuildFile(srv, ioutil.Discard, ioutil.Discard, false, useCache, false, false, ioutil.Discard, utils.NewStreamFormatter(false), nil, nil)
	id, err := buildfile.Build(context.Archive(dockerfile, t))
	if err != nil {
		return nil, err
	}

	job := eng.Job("image_inspect", id)
	buffer := bytes.NewBuffer(nil)
	image := &image.Image{}
	job.Stdout.Add(buffer)
	if err := job.Run(); err != nil {
		return nil, err
	}
	err = json.NewDecoder(buffer).Decode(image)
	return image, err
}
Пример #5
0
func buildImage(context testContextTemplate, t *testing.T, eng *engine.Engine, useCache bool) *docker.Image {
	if eng == nil {
		eng = NewTestEngine(t)
		runtime := mkRuntimeFromEngine(eng, t)
		// FIXME: we might not need runtime, why not simply nuke
		// the engine?
		defer nuke(runtime)
	}
	srv := mkServerFromEngine(eng, t)

	httpServer, err := mkTestingFileServer(context.remoteFiles)
	if err != nil {
		t.Fatal(err)
	}
	defer httpServer.Close()

	idx := strings.LastIndex(httpServer.URL, ":")
	if idx < 0 {
		t.Fatalf("could not get port from test http server address %s", httpServer.URL)
	}
	port := httpServer.URL[idx+1:]

	iIP := eng.Hack_GetGlobalVar("httpapi.bridgeIP")
	if iIP == nil {
		t.Fatal("Legacy bridgeIP field not set in engine")
	}
	ip, ok := iIP.(net.IP)
	if !ok {
		panic("Legacy bridgeIP field in engine does not cast to net.IP")
	}
	dockerfile := constructDockerfile(context.dockerfile, ip, port)

	buildfile := docker.NewBuildFile(srv, ioutil.Discard, false, useCache, false)
	id, err := buildfile.Build(mkTestContext(dockerfile, context.files, t))
	if err != nil {
		t.Fatal(err)
	}

	img, err := srv.ImageInspect(id)
	if err != nil {
		t.Fatal(err)
	}
	return img
}