github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/internal/commands/set_run_image_mirrors.go (about)

     1  package commands
     2  
     3  import (
     4  	"github.com/spf13/cobra"
     5  
     6  	"github.com/buildpacks/pack/internal/config"
     7  	"github.com/buildpacks/pack/internal/style"
     8  	"github.com/buildpacks/pack/pkg/logging"
     9  )
    10  
    11  // Deprecated: Use `pack config run-image-mirrors add` instead
    12  // SetRunImagesMirrors sets run image mirros for a given run image
    13  func SetRunImagesMirrors(logger logging.Logger, cfg config.Config, cfgPath string) *cobra.Command {
    14  	var mirrors []string
    15  
    16  	cmd := &cobra.Command{
    17  		Use:     "set-run-image-mirrors <run-image-name> --mirror <run-image-mirror>",
    18  		Args:    cobra.ExactArgs(1),
    19  		Hidden:  true,
    20  		Short:   "Set mirrors to other repositories for a given run image",
    21  		Example: "pack set-run-image-mirrors cnbs/sample-stack-run:bionic --mirror index.docker.io/cnbs/sample-stack-run:bionic",
    22  		RunE: logError(logger, func(cmd *cobra.Command, args []string) error {
    23  			deprecationWarning(logger, "set-run-image-mirrors", "config run-image-mirrors")
    24  			runImage := args[0]
    25  			cfg = config.SetRunImageMirrors(cfg, runImage, mirrors)
    26  			if err := config.Write(cfg, cfgPath); err != nil {
    27  				return err
    28  			}
    29  
    30  			for _, mirror := range mirrors {
    31  				logger.Infof("Run Image %s configured with mirror %s", style.Symbol(runImage), style.Symbol(mirror))
    32  			}
    33  			if len(mirrors) == 0 {
    34  				logger.Infof("All mirrors removed for Run Image %s", style.Symbol(runImage))
    35  			}
    36  			return nil
    37  		}),
    38  	}
    39  	cmd.Flags().StringSliceVarP(&mirrors, "mirror", "m", nil, "Run image mirror"+stringSliceHelp("mirror"))
    40  	AddHelpFlag(cmd, "set-run-image-mirrors")
    41  	return cmd
    42  }