Exemplo n.º 1
0
func dockerLoadImage(client *docker.Client, download_url string, datatoken string) (err error) {

	image_stream, err := shock.FetchShockStream(download_url, datatoken) // token empty here, assume that images are public
	if err != nil {
		return errors.New(fmt.Sprintf("Error getting Shock stream, err=%s", err.Error()))
	}

	gr, err := gzip.NewReader(image_stream) //returns (*Reader, error) // TODO not sure if I have to close gr later ?

	logger.Debug(1, fmt.Sprintf("loading image..."))
	//go io.Copy(image_writer, image_stream)

	var buf bytes.Buffer

	if client != nil {
		opts := docker.LoadImageOptions{InputStream: gr}
		err = client.LoadImage(opts)

	} else {

		//pipe stream into docker binary "docker load"
		cmd := exec.Command(conf.DOCKER_BINARY, "load")

		stdin, err := cmd.StdinPipe() // stdin is a io.WriteCloser

		//stderr, err := cmd.StderrPipe()
		//if err != nil {
		//	return err
		//}

		if err = cmd.Start(); err != nil {
			return err
		}

		go io.Copy(stdin, gr)

		err = cmd.Wait()

	}

	if err != nil {
		return errors.New(fmt.Sprintf("Error loading image, err=%s", err.Error()))
	}
	logger.Debug(1, fmt.Sprintf("load image returned: %v", &buf))

	return
}
Exemplo n.º 2
0
func dockerLoadImage(client *docker.Client, download_url string) (err error) {

	image_stream, err := shock.FetchShockStream(download_url, "") // token empty here, assume that images are public
	if err != nil {
		return errors.New(fmt.Sprintf("Error getting Shock stream, err=%s", err.Error()))
	}

	gr, err := gzip.NewReader(image_stream) //returns (*Reader, error) // TODO not sure if I have to close gr later ?

	logger.Debug(1, fmt.Sprintf("loading image..."))
	//go io.Copy(image_writer, image_stream)

	var buf bytes.Buffer

	err = client.LoadImage(gr, &buf) // in io.Reader, w io.Writer
	if err != nil {
		return errors.New(fmt.Sprintf("Error loading image, err=%s", err.Error()))
	}

	logger.Debug(1, fmt.Sprintf("load image returned: %v", &buf))
	return
}