当前位置: 首页>>代码示例>>Golang>>正文


Golang PullImageOptions.OutputStream方法代码示例

本文整理汇总了Golang中github.com/fsouza/go-dockerclient.PullImageOptions.OutputStream方法的典型用法代码示例。如果您正苦于以下问题:Golang PullImageOptions.OutputStream方法的具体用法?Golang PullImageOptions.OutputStream怎么用?Golang PullImageOptions.OutputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/fsouza/go-dockerclient.PullImageOptions的用法示例。


在下文中一共展示了PullImageOptions.OutputStream方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: LoadImage

// LoadImage checks the client for an image matching from. If not found,
// attempts to pull the image and then tries to inspect again.
func (e *ClientExecutor) LoadImage(from string) (*docker.Image, error) {
	image, err := e.Client.InspectImage(from)
	if err == nil {
		return image, nil
	}
	if err != docker.ErrNoSuchImage {
		return nil, err
	}

	if !e.AllowPull {
		glog.V(4).Infof("image %s did not exist", from)
		return nil, docker.ErrNoSuchImage
	}

	repository, tag := docker.ParseRepositoryTag(from)
	if len(tag) == 0 {
		tag = "latest"
	}

	glog.V(4).Infof("attempting to pull %s with auth from repository %s:%s", from, repository, tag)

	// TODO: we may want to abstract looping over multiple credentials
	auth, _ := e.AuthFn(repository)
	if len(auth) == 0 {
		auth = append(auth, credentialprovider.LazyAuthConfiguration{})
	}

	if e.LogFn != nil {
		e.LogFn("Image %s was not found, pulling ...", from)
	}

	var lastErr error
	outputProgress := func(s string) {
		e.LogFn("%s", s)
	}
	for _, config := range auth {
		// TODO: handle IDs?
		pullImageOptions := docker.PullImageOptions{
			Repository:    repository,
			Tag:           tag,
			OutputStream:  imageprogress.NewPullWriter(outputProgress),
			RawJSONStream: true,
		}
		if glog.V(5) {
			pullImageOptions.OutputStream = os.Stderr
			pullImageOptions.RawJSONStream = false
		}
		authConfig := docker.AuthConfiguration{Username: config.Username, ServerAddress: config.ServerAddress, Password: config.Password}
		if err = e.Client.PullImage(pullImageOptions, authConfig); err == nil {
			break
		}
		lastErr = err
		continue
	}
	if lastErr != nil {
		return nil, fmt.Errorf("unable to pull image (from: %s, tag: %s): %v", repository, tag, lastErr)
	}

	return e.Client.InspectImage(from)
}
开发者ID:Xmagicer,项目名称:origin,代码行数:62,代码来源:client.go

示例2: pullImage

func pullImage(client DockerClient, name string, authConfig docker.AuthConfiguration) error {
	logProgress := func(s string) {
		glog.V(0).Infof("%s", s)
	}
	opts := docker.PullImageOptions{
		Repository:    name,
		OutputStream:  imageprogress.NewPullWriter(logProgress),
		RawJSONStream: true,
	}
	if glog.Is(5) {
		opts.OutputStream = os.Stderr
		opts.RawJSONStream = false
	}
	err := client.PullImage(opts, authConfig)
	if err == nil {
		return nil
	}
	return err
}
开发者ID:pweil-,项目名称:origin,代码行数:19,代码来源:dockerutil.go

示例3: PullImage

// PullImage will pull the localkube image on the connected Docker daemon
func (d *Controller) PullImage(imageTag string, silent bool) error {
	pullOpts := docker.PullImageOptions{
		Repository: LocalkubeImageName,
		Tag:        imageTag,
	}

	in, out := io.Pipe()
	// print pull progress if not silent
	if !silent {
		pullOpts.RawJSONStream = true
		pullOpts.OutputStream = out
		outFd, isTerminal := term.GetFdInfo(d.out)
		go jsonmessage.DisplayJSONMessagesStream(in, d.out, outFd, isTerminal)
	}

	err := d.Client.PullImage(pullOpts, docker.AuthConfiguration{})
	if err != nil {
		return fmt.Errorf("failed to pull localkube image: %v", err)
	}
	return nil
}
开发者ID:redspread,项目名称:spread,代码行数:22,代码来源:controller.go


注:本文中的github.com/fsouza/go-dockerclient.PullImageOptions.OutputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。