Esempio n. 1
0
// RegistrySync walks the service tree and syncs all images from docker to local registry
func (a *api) RegistrySync() (err error) {
	client, err := a.connectDocker()
	if err != nil {
		return err
	}

	services, err := a.GetServices()
	if err != nil {
		return err
	} else if services == nil || len(services) == 0 {
		return fmt.Errorf("no services found")
	}

	glog.V(2).Infof("RegistrySync from local docker repo %+v", client)
	synced := map[string]bool{}
	for _, svc := range services {
		if len(svc.ImageID) == 0 {
			continue
		}

		if _, ok := synced[svc.ImageID]; ok {
			continue
		}

		fmt.Fprintf(os.Stderr, "Syncing image to local docker registry: %s ...", svc.ImageID)
		if err := docker.PushImage(svc.ImageID); err != nil {
			return err
		}
		synced[svc.ImageID] = true
	}

	fmt.Printf("images synced to local docker registry")
	return nil
}
Esempio n. 2
0
func (dfs *DistributedFilesystem) registerImages(basename string) error {
	images, err := docker.Images()
	if err != nil {
		return err
	}

	for _, image := range images {
		imageID := image.ID
		if imageID.BaseName() == basename {
			imageID.Host, imageID.Port = dfs.dockerHost, dfs.dockerPort
			if t, err := image.Tag(imageID.String()); err != nil {
				glog.Errorf("Could not add tag %s to %s: %s", imageID, image.ID, err)
				return err
			} else if err := docker.PushImage(t.ID.String()); err != nil {
				glog.Errorf("Could not push image %s: %s", t.ID, err)
				return err
			}
		}
	}

	return nil
}