Exemplo n.º 1
0
func (s *Server) executeServiceHandler(w http.ResponseWriter, r *http.Request) {
	logRequest(r)
	imageID := r.FormValue("imageID")
	if imageID == "" {
		vars := mux.Vars(r)
		imageID = vars["imageID"]
	}
	if imageID == "" {
		Response{w}.ServerNewError("execute docker image: imageID required")
		return
	}
	logParam("imageID", imageID)

	image, err := s.docker.InspectImage(dckr.ImageID(imageID))
	if err != nil {
		Response{w}.ServerError("execute docker image: inspectImage: ", err)
	}
	binds, err := makeBinds(r, image)
	if err != nil {
		Response{w}.ServerError("execute docker image: binds: ", err)
		return
	}
	logParam("binds", strings.Join(binds, " : "))

	containerID, err := s.docker.ExecuteImage(dckr.ImageID(imageID), binds)
	fmt.Println("EXECUTE")
	fmt.Println((dckr.ImageID(imageID)))
	if err != nil {
		Response{w}.ServerError("execute docker image: ", err)
		return
	}
	loc := apiRootPath + jobsAPIPath + "/" + string(containerID)
	Response{w}.Location(loc).Created(jmap("Location", loc, "jobID", containerID))
}
Exemplo n.º 2
0
func (s *Server) inspectVolumeHandler(w http.ResponseWriter, r *http.Request) {
	logRequest(r)
	volumeItems := VolumeItems{}
	vars := mux.Vars(r)
	volId := string(dckr.ImageID(vars["volumeID"]))
	files, _ := ioutil.ReadDir("/var/lib/docker/volumes/" + volId + "/_data")
	for _, f := range files {
		//fmt.Println(f.Name())
		volumeItems = append(volumeItems, VolumeItem{Name: f.Name(), Size: f.Size(), Modified: f.ModTime(), IsFolder: f.IsDir()})
	}

	//imageName := "sha256:2b8fd9751c4c0f5dd266fcae00707e67a2545ef34f9a29354585f93dac906749"
	//imageID := "2b8fd9751c4c0f5dd266fcae00707e67a2545ef34f9a29354585f93dac906749"
	imageID := "d755f01f457926e662451aa753a627c84e6e1f76d517d0982000795630673182"
	//imageID2 := "0cc497676af005168f1a814923bd2050e9edcc4d4e6fd60a2478417c48603175"

	//containerID, err := s.docker.ExecuteImage(dckr.ImageID(imageID), []string{"/test:/tes

	volumesToMount := []string{
		"/var/lib/docker/volumes/" + volId + "/_data:/home"}

	containerID, err := s.docker.ExecuteImage(dckr.ImageID(imageID), volumesToMount)
	fmt.Println("EXECUTE")
	fmt.Println((dckr.ImageID(imageID)))
	fmt.Println(containerID)

	if err != nil {
		Response{w}.ServerError("execute docker image: ", err)
		return
	}

	//loc := apiRootPath + jobsAPIPath + "/" + string(containerID)

	/*image, err := s.docker.BuildImage("/home/vagrant")
	if err != nil {
		Response{w}.ServerError("build docker image: ", err)
		return
	}
	fmt.Println(image)*/

	json.NewEncoder(w).Encode(volumeItems)

}
Exemplo n.º 3
0
func (s *Server) inspectServiceHandler(w http.ResponseWriter, r *http.Request) {
	logRequest(r)
	vars := mux.Vars(r)
	imageID := dckr.ImageID(vars["imageID"])
	image, err := s.docker.InspectImage(imageID)
	if err != nil {
		Response{w}.ServerError("inspect docker image: ", err)
		return
	}
	Response{w}.Ok(jmap("Image", image, "Service", extractServiceInfo(image)))
}