github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/pkg/client/manifest_add.go (about)

     1  package client
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/buildpacks/pack/internal/style"
     8  )
     9  
    10  type ManifestAddOptions struct {
    11  	// Image index we want to update
    12  	IndexRepoName string
    13  
    14  	// Name of image we wish to add into the image index
    15  	RepoName string
    16  }
    17  
    18  // AddManifest implements commands.PackClient.
    19  func (c *Client) AddManifest(ctx context.Context, opts ManifestAddOptions) (err error) {
    20  	idx, err := c.indexFactory.LoadIndex(opts.IndexRepoName)
    21  	if err != nil {
    22  		return err
    23  	}
    24  
    25  	if err = c.addManifestToIndex(ctx, opts.RepoName, idx); err != nil {
    26  		return err
    27  	}
    28  
    29  	if err = idx.SaveDir(); err != nil {
    30  		return fmt.Errorf("failed to save manifest list %s to local storage: %w", style.Symbol(opts.RepoName), err)
    31  	}
    32  
    33  	c.logger.Infof("Successfully added image %s to index", style.Symbol(opts.RepoName))
    34  	return nil
    35  }