Beispiel #1
0
func (cli *DogestryCli) preparePullImage(fromId remote.ID, imageRoot string, r remote.Remote) error {
	toDownload := make([]remote.ID, 0)

	// TODO flatten this list, then iterate and pull each required file
	// TODO parallelize
	err := r.WalkImages(fromId, func(id remote.ID, image docker.Image, err error) error {
		fmt.Printf("examining id '%s' on remote\n", id.Short())
		if err != nil {
			fmt.Println("err", err)
			return err
		}

		_, err = cli.client.InspectImage(string(id))
		if err == docker.ErrNoSuchImage {
			toDownload = append(toDownload, id)
			return nil
		} else {
			fmt.Printf("docker already has id '%s', stopping\n", id.Short())
			return remote.BreakWalk
		}
	})

	if err != nil {
		return err
	}

	for _, id := range toDownload {
		if err := cli.pullImage(id, filepath.Join(imageRoot, string(id)), r); err != nil {
			return err
		}
	}

	return nil
}