src/server/pkg/deploy/images/images.go
func Export(opts *assets.AssetOpts, out io.Writer) error {
	client, err := docker.NewClientFromEnv()
	if err != nil {
		return err
	}
	authConfigs, err := docker.NewAuthConfigurationsFromDockerCfg()
	if err != nil {
		return fmt.Errorf("error parsing auth: %s, try running `docker login`", err.Error())
	}
	if len(authConfigs.Configs) == 0 {
		return fmt.Errorf("didn't find any valid auth configurations")
	}
	images := assets.Images(opts)
	for _, image := range images {
		repository, tag := docker.ParseRepositoryTag(image)
		pulled := false
		var loopErr []error
		for registry, authConfig := range authConfigs.Configs {
			if err := client.PullImage(
				docker.PullImageOptions{
					Repository:        repository,
					Tag:               tag,
					InactivityTimeout: 5 * time.Second,
				},
				authConfig,
			); err != nil {
				loopErr = append(loopErr, fmt.Errorf("error pulling from %s: %v", registry, err))
				continue
			}
			pulled = true
			break
		}
		if !pulled {
			errStr := ""
			for _, err := range loopErr {
				errStr += err.Error() + "\n"
			}
			return fmt.Errorf("errors pulling image %s:%s:\n%s", repository, tag, errStr)
		}
	}
	return client.ExportImages(docker.ExportImagesOptions{
		Names:        images,
		OutputStream: out,
	})
}
func Export(opts *assets.AssetOpts, out io.Writer) error {
	client, err := docker.NewClientFromEnv()
	if err != nil {
		return err
	}
	authConfigs, err := docker.NewAuthConfigurationsFromDockerCfg()
	if err != nil {
		return fmt.Errorf("error parsing auth: %s, try running `docker login`", err.Error())
	}
	if len(authConfigs.Configs) == 0 {
		return fmt.Errorf("didn't find any valid auth configurations")
	}
	images := assets.Images(opts)
	for _, image := range images {
		repository, tag := docker.ParseRepositoryTag(image)
		pulled := false
		var loopErr []error
		for registry, authConfig := range authConfigs.Configs {
			if err := client.PullImage(
				docker.PullImageOptions{
					Repository:        repository,
					Tag:               tag,
					InactivityTimeout: 5 * time.Second,
				},
				authConfig,
			); err != nil {
				loopErr = append(loopErr, fmt.Errorf("error pulling from %s: %v", registry, err))
				continue
			}
			pulled = true
			break
		}
		if !pulled {
			errStr := ""
			for _, err := range loopErr {
				errStr += err.Error() + "\n"
			}
			return fmt.Errorf("errors pulling image %s:%s:\n%s", repository, tag, errStr)
		}
	}
	return client.ExportImages(docker.ExportImagesOptions{
		Names:        images,
		OutputStream: out,
	})
}
// Export a tarball of the images needed by a deployment.