예제 #1
0
파일: context.go 프로젝트: devick/flynn
func (c *Context) PullTUF(url string, client *tuf.Client, progress chan<- layer.PullInfo) error {
	ref, err := registry.NewRef(url)
	if err != nil {
		return err
	}
	return c.pull(url, registry.NewTUFSession(client, ref), progress)
}
예제 #2
0
파일: context.go 프로젝트: devick/flynn
func (c *Context) PullDocker(url string, progress chan<- layer.PullInfo) error {
	ref, err := registry.NewRef(url)
	if err != nil {
		return err
	}
	return c.pull(url, registry.NewDockerSession(ref), progress)
}
예제 #3
0
func (c *Context) Pull(url string, progress chan<- LayerPullInfo) error {
	defer func() {
		if progress != nil {
			close(progress)
		}
	}()

	ref, err := registry.NewRef(url)
	if err != nil {
		return err
	}

	if id := ref.ImageID(); id != "" && c.Exists(id) {
		if progress != nil {
			progress <- LayerPullInfo{ID: id, Status: LayerStatusExists}
		}
		return nil
	}

	image, err := ref.Get()
	if err != nil {
		return err
	}

	layers, err := image.Ancestors()
	if err != nil {
		return err
	}

	for i := len(layers) - 1; i >= 0; i-- {
		layer := layers[i]
		if c.Exists(layer.ID) {
			if progress != nil {
				progress <- LayerPullInfo{ID: layer.ID, Status: LayerStatusExists}
			}
			continue
		}

		if err := layer.Fetch(); err != nil {
			return err
		}
		status := LayerStatusDownloaded
		if err := c.Add(layer); err != nil {
			if err == store.ErrExists {
				status = LayerStatusExists
			} else {
				return err
			}
		}
		if progress != nil {
			progress <- LayerPullInfo{ID: layer.ID, Status: status}
		}
	}

	// TODO: update sizes

	return nil
}
예제 #4
0
func (c *Context) Pull(url string) {
	ref, err := registry.NewRef(url)
	if err != nil {
		log.Fatal(err)
	}

	if id := ref.ImageID(); id != "" && c.Exists(id) {
		c.writeLayerInfo(id, "exists")
		return
	}

	image, err := ref.Get()
	if err != nil {
		log.Fatal(err)
	}

	layers, err := image.Ancestors()
	if err != nil {
		log.Fatal(err)
	}

	for i := len(layers) - 1; i >= 0; i-- {
		layer := layers[i]
		if c.Exists(layer.ID) {
			c.writeLayerInfo(layer.ID, "exists")
			continue
		}

		if err := layer.Fetch(); err != nil {
			log.Fatal(err)
		}
		status := "downloaded"
		if err := c.Add(layer); err != nil {
			if err == store.ErrExists {
				status = "exists"
			} else {
				log.Fatal(err)
			}
		}
		c.writeLayerInfo(layer.ID, status)
	}

	// TODO: update sizes
}