get.porter.sh/porter@v1.3.0/cmd/porter/server.go (about) 1 package main 2 3 import ( 4 "time" 5 6 grpc "get.porter.sh/porter/pkg/grpc" 7 "get.porter.sh/porter/pkg/porter" 8 "get.porter.sh/porter/pkg/signals" 9 "github.com/spf13/cobra" 10 ) 11 12 func buildGRPCServerCommands(p *porter.Porter) *cobra.Command { 13 cmd := &cobra.Command{ 14 Use: "api-server", 15 Short: "API server", 16 Long: "Launch API server for porter", 17 Hidden: true, // This is a hidden command and is currently only meant to be used by the porter operator 18 } 19 cmd.Annotations = map[string]string{ 20 "group": "api-server", 21 } 22 cmd.AddCommand(buildServerRunCommand(p)) 23 return cmd 24 } 25 26 func buildServerRunCommand(p *porter.Porter) *cobra.Command { 27 opts := porter.ServiceOptions{} 28 cmd := &cobra.Command{ 29 Use: "run", 30 Short: "Run the gRPC server", 31 Long: `Run the gRPC server for porter. 32 33 This command starts the gRPC server for porter which is able to expose limited porter functionality via RPC. 34 Currently only data operations are supported, creation of resources such as installations, credential sets, or parameter sets is not supported. 35 36 A list of the supported RPCs can be found at <link?> 37 `, 38 PreRunE: func(cmd *cobra.Command, args []string) error { 39 return opts.Validate() 40 }, 41 RunE: func(cmd *cobra.Command, args []string) error { 42 srv, err := grpc.NewServer(cmd.Context(), &opts) 43 if err != nil { 44 return err 45 } 46 grpcServer, err := srv.ListenAndServe() 47 stopCh := signals.SetupSignalHandler() 48 serverShutdownTimeout := time.Duration(time.Second * 30) 49 sd, _ := signals.NewShutdown(serverShutdownTimeout, cmd.Context()) 50 sd.Graceful(stopCh, grpcServer, cmd.Context()) 51 return err 52 }, 53 } 54 f := cmd.Flags() 55 f.Int64VarP(&opts.Port, "port", "p", 3001, "Port to run the server on") 56 f.StringVarP(&opts.ServiceName, "service-name", "s", "api-server", "Server service name") 57 return cmd 58 }