github.com/replicatedhq/ship@v0.55.0/pkg/cli/init.go (about)

     1  package cli
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/pkg/errors"
     8  	"github.com/replicatedhq/ship/pkg/ship"
     9  	"github.com/spf13/cobra"
    10  	"github.com/spf13/viper"
    11  )
    12  
    13  const (
    14  	developerFlagUsage = "Useful for debugging your specs on the command line, without having to make round trips to the server"
    15  )
    16  
    17  func Init() *cobra.Command {
    18  	cmd := &cobra.Command{
    19  		Use:   "init UPSTREAM",
    20  		Short: "Build and deploy kubernetes applications with kustomize.",
    21  		Long: `
    22  Build and deploy applications to be integrated
    23  with a gitops style workflow.
    24  
    25  
    26  Upstream can be one of:
    27  
    28  - A path to Kubernetes manifests in a github repo [github.com/replicatedhq/test-charts/plain-k8s]
    29  - A path to a helm chart in a github repo         [github.com/helm/charts/stable/anchore-engine]
    30  - A path to a specific "ref" to a helm chart or
    31    Kubernetes manifests in a github repo           [github.com/helm/charts/tree/abcdef123456/stable/anchore-engine]
    32  - A go-getter compatible URL
    33    (github.com/hashicorp/go-getter)              [git::gitlab.com/myrepo/mychart, ./local-charts/nginx-ingress, github.com/myrepo/mychart?ref=abcdef123456//my/path]
    34  `,
    35  		PreRun: func(cmd *cobra.Command, args []string) {
    36  			_ = viper.BindPFlags(cmd.Flags())
    37  			_ = viper.BindPFlags(cmd.PersistentFlags())
    38  		},
    39  		RunE: func(cmd *cobra.Command, args []string) error {
    40  			v := viper.GetViper()
    41  			if len(args) == 0 {
    42  				_ = cmd.Help()
    43  				return errors.New("Error: please supply an upstream")
    44  			}
    45  
    46  			v.Set("upstream", args[0])
    47  			s, err := ship.Get(v)
    48  			if err != nil {
    49  				return err
    50  			}
    51  
    52  			return s.InitAndMaybeExit(context.Background())
    53  		},
    54  	}
    55  
    56  	cmd.Flags().String("file", "", "File path to helm chart")
    57  
    58  	cmd.Flags().Bool("rm-asset-dest", false, "Always remove asset destinations if already present")
    59  	cmd.Flags().Int("retries", 3, "Number of times to retry retrieving upstream")
    60  	cmd.Flags().Bool("preserve-state", false, "Skips prompt to remove existing state. If an existing state file is present, ship update --headed lifecycle will be used.")
    61  
    62  	// optional developer flags for "ship init replicated.app"
    63  	cmd.Flags().String("set-channel-name", "", developerFlagUsage)
    64  	cmd.Flags().String("set-channel-icon", "", developerFlagUsage)
    65  	cmd.Flags().StringSlice("set-github-contents", []string{}, fmt.Sprintf("Specify a REPO:REPO_PATH:REF:LOCAL_PATH to override github checkouts to use a local path on the filesystem. %s. ", developerFlagUsage))
    66  	cmd.Flags().String("set-entitlements-json", "{\"values\":[]}", fmt.Sprintf("Specify json for entitlements payload. %s", developerFlagUsage))
    67  
    68  	return cmd
    69  }