add config switch (#46)

This commit is contained in:
Haishi2016 2019-08-26 14:43:33 -07:00 committed by Yaron Schneider
parent ce7a31b8f6
commit 427981528a
2 changed files with 15 additions and 6 deletions

View File

@ -19,6 +19,7 @@ import (
var appPort int var appPort int
var appID string var appID string
var configFile string
var port int var port int
var image string var image string
@ -55,6 +56,7 @@ var RunCmd = &cobra.Command{
AppID: appID, AppID: appID,
AppPort: appPort, AppPort: appPort,
Port: port, Port: port,
ConfigFile: configFile,
Arguments: args, Arguments: args,
}) })
if err != nil { if err != nil {
@ -184,6 +186,7 @@ var RunCmd = &cobra.Command{
func init() { func init() {
RunCmd.Flags().IntVarP(&appPort, "app-port", "", -1, "the port your application is listening on") RunCmd.Flags().IntVarP(&appPort, "app-port", "", -1, "the port your application is listening on")
RunCmd.Flags().StringVarP(&appID, "app-id", "", "", "an id for your application, used for service discovery") RunCmd.Flags().StringVarP(&appID, "app-id", "", "", "an id for your application, used for service discovery")
RunCmd.Flags().StringVarP(&configFile, "config", "", "", "Actions configuration file")
RunCmd.Flags().IntVarP(&port, "port", "p", -1, "the port for Actions to listen on") RunCmd.Flags().IntVarP(&port, "port", "p", -1, "the port for Actions to listen on")
RunCmd.Flags().StringVarP(&image, "image", "", "", "the image to build the code in. input is repository/image") RunCmd.Flags().StringVarP(&image, "image", "", "", "the image to build the code in. input is repository/image")
RunCmd.Flags().BoolVar(&kubernetesMode, "kubernetes", false, "Build and deploy your app and Actions to a Kubernetes cluster") RunCmd.Flags().BoolVar(&kubernetesMode, "kubernetes", false, "Build and deploy your app and Actions to a Kubernetes cluster")

View File

@ -17,10 +17,11 @@ import (
) )
type RunConfig struct { type RunConfig struct {
AppID string AppID string
AppPort int AppPort int
Port int Port int
Arguments []string ConfigFile string
Arguments []string
} }
type RunOutput struct { type RunOutput struct {
@ -42,7 +43,7 @@ type component struct {
} `json:"spec"` } `json:"spec"`
} }
func getActionsCommand(appID string, actionsPort int, appPort int) (*exec.Cmd, int, error) { func getActionsCommand(appID string, actionsPort int, appPort int, configFile string) (*exec.Cmd, int, error) {
if actionsPort < 0 { if actionsPort < 0 {
port, err := freeport.GetFreePort() port, err := freeport.GetFreePort()
if err != nil { if err != nil {
@ -79,6 +80,11 @@ func getActionsCommand(appID string, actionsPort int, appPort int) (*exec.Cmd, i
args = append(args, fmt.Sprintf("%v", grpcPort)) args = append(args, fmt.Sprintf("%v", grpcPort))
if configFile != "" {
args = append(args, "--config")
args = append(args, configFile)
}
cmd := exec.Command(actionsCMD, args...) cmd := exec.Command(actionsCMD, args...)
return cmd, actionsPort, nil return cmd, actionsPort, nil
} }
@ -180,7 +186,7 @@ func Run(config *RunConfig) (*RunOutput, error) {
return nil, err return nil, err
} }
actionsCMD, actionsPort, err := getActionsCommand(appID, config.Port, config.AppPort) actionsCMD, actionsPort, err := getActionsCommand(appID, config.Port, config.AppPort, config.ConfigFile)
if err != nil { if err != nil {
return nil, err return nil, err
} }