Example #1
0
func (cli *DogestryCli) exportToFiles(image string, r remote.Remote, imageRoot string) error {
	imageHistory, err := cli.Client.ImageHistory(image)
	if err != nil {
		fmt.Printf("Error getting image history: %v\n", err)
		return err
	}

	fmt.Println("Checking layers on remote")

	imageID := remote.ID(imageHistory[0].ID)
	repoName, repoTag := remote.NormaliseImageName(image)

	// Check the remote to see what layers are missing. Only missing Ids will
	// need to be saved to disk when exporting the docker image.

	missingIds := make(set)

	for _, i := range imageHistory {
		id := remote.ID(i.ID)
		_, err = r.ImageMetadata(id)
		if err == nil {
			fmt.Printf("  exists   : %v\n", id)
		} else {
			fmt.Printf("  not found: %v\n", id)
			missingIds[id] = empty
		}
	}

	if len(missingIds) > 0 {
		if err := cli.exportImageToFiles(image, imageRoot, missingIds); err != nil {
			return err
		}
	}

	if err := cli.exportMetaDataToFiles(repoName, repoTag, imageID, imageRoot); err != nil {
		return err
	}

	return nil
}
Example #2
0
func (cli *DogestryCli) createRepositoriesJsonFile(image, imageRoot string, r remote.Remote) error {
	repoName, repoTag := remote.NormaliseImageName(image)

	id, err := r.ParseTag(repoName, repoTag)
	if err != nil {
		return err
	} else if id == "" {
		return nil
	}

	reposPath := filepath.Join(imageRoot, "repositories")
	reposFile, err := os.Create(reposPath)
	if err != nil {
		return err
	}
	defer reposFile.Close()

	repositories := map[string]Repository{}
	repositories[repoName] = Repository{}
	repositories[repoName][repoTag] = string(id)

	return json.NewEncoder(reposFile).Encode(&repositories)
}