mirror of https://github.com/dapr/cli.git
(cherry picked from commit a9a8bc3ac2
)
This commit is contained in:
parent
9e106e8de4
commit
3c7c0fc733
|
@ -245,7 +245,7 @@ func init() {
|
|||
RunCmd.Flags().StringVarP(&logLevel, "log-level", "", "info", "Sets the log verbosity. Valid values are: debug, info, warn, error, fatal, or panic. Default is info")
|
||||
RunCmd.Flags().IntVarP(&maxConcurrency, "max-concurrency", "", -1, "controls the concurrency level of the app. Default is unlimited")
|
||||
RunCmd.Flags().StringVarP(&protocol, "protocol", "", "http", "tells Dapr to use HTTP or gRPC to talk to the app. Default is http")
|
||||
RunCmd.Flags().StringVarP(&componentsPath, "components-path", "", "", "Path for components directory. Default is ./components.")
|
||||
RunCmd.Flags().StringVarP(&componentsPath, "components-path", "", standalone.GetDefaultComponentsFolder(), "Path for components directory. Default is ./components.")
|
||||
RunCmd.Flags().String("redis-host", "localhost", "the host on which the Redis service resides")
|
||||
RunCmd.Flags().String("placement-host", "localhost", "the host on which the placement service resides")
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
// getDefaultComponentsFolder returns the hidden .components folder created at init time
|
||||
func getDefaultComponentsFolder() string {
|
||||
func GetDefaultComponentsFolder() string {
|
||||
const daprDirName = ".dapr"
|
||||
const componentsDirName = "components"
|
||||
daprDirPath := os.Getenv("HOME")
|
||||
|
|
|
@ -73,7 +73,7 @@ type componentMetadataItem struct {
|
|||
Value string `yaml:"value"`
|
||||
}
|
||||
|
||||
func getDaprCommand(appID string, daprHTTPPort int, daprGRPCPort int, appPort int, configFile, protocol string, enableProfiling bool, profilePort int, logLevel string, maxConcurrency int, placementHost string) (*exec.Cmd, int, int, int, error) {
|
||||
func getDaprCommand(appID string, daprHTTPPort int, daprGRPCPort int, appPort int, configFile, protocol string, enableProfiling bool, profilePort int, logLevel string, maxConcurrency int, placementHost string, componentsPath string) (*exec.Cmd, int, int, int, error) {
|
||||
if daprHTTPPort < 0 {
|
||||
port, err := freeport.GetFreePort()
|
||||
if err != nil {
|
||||
|
@ -106,7 +106,7 @@ func getDaprCommand(appID string, daprHTTPPort int, daprGRPCPort int, appPort in
|
|||
return nil, -1, -1, -1, err
|
||||
}
|
||||
|
||||
args := []string{"--app-id", appID, "--dapr-http-port", fmt.Sprintf("%v", daprHTTPPort), "--dapr-grpc-port", fmt.Sprintf("%v", daprGRPCPort), "--log-level", logLevel, "--max-concurrency", fmt.Sprintf("%v", maxConcurrency), "--protocol", protocol, "--metrics-port", fmt.Sprintf("%v", metricsPort)}
|
||||
args := []string{"--app-id", appID, "--dapr-http-port", fmt.Sprintf("%v", daprHTTPPort), "--dapr-grpc-port", fmt.Sprintf("%v", daprGRPCPort), "--log-level", logLevel, "--max-concurrency", fmt.Sprintf("%v", maxConcurrency), "--protocol", protocol, "--metrics-port", fmt.Sprintf("%v", metricsPort), "--components-path", componentsPath}
|
||||
if appPort > -1 {
|
||||
args = append(args, "--app-port", fmt.Sprintf("%v", appPort))
|
||||
}
|
||||
|
@ -259,6 +259,11 @@ func Run(config *RunConfig) (*RunOutput, error) {
|
|||
appID = strings.Replace(sillyname.GenerateStupidName(), " ", "-", -1)
|
||||
}
|
||||
|
||||
_, err := os.Stat(config.ComponentsPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dapr, err := List()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -270,12 +275,7 @@ func Run(config *RunConfig) (*RunOutput, error) {
|
|||
}
|
||||
}
|
||||
|
||||
componentsPath, err := getComponentsPath(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
componentsLoader := components.NewStandaloneComponents(modes.StandaloneConfig{ComponentsPath: componentsPath})
|
||||
componentsLoader := components.NewStandaloneComponents(modes.StandaloneConfig{ComponentsPath: config.ComponentsPath})
|
||||
components, err := componentsLoader.LoadComponents()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -293,20 +293,20 @@ func Run(config *RunConfig) (*RunOutput, error) {
|
|||
}
|
||||
|
||||
if stateStore == "" {
|
||||
err = createRedisStateStore(config.RedisHost, componentsPath)
|
||||
err = createRedisStateStore(config.RedisHost, config.ComponentsPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if pubSub == "" {
|
||||
err = createRedisPubSub(config.RedisHost, componentsPath)
|
||||
err = createRedisPubSub(config.RedisHost, config.ComponentsPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
daprCMD, daprHTTPPort, daprGRPCPort, metricsPort, err := getDaprCommand(appID, config.HTTPPort, config.GRPCPort, config.AppPort, config.ConfigFile, config.Protocol, config.EnableProfiling, config.ProfilePort, config.LogLevel, config.MaxConcurrency, config.PlacementHost)
|
||||
daprCMD, daprHTTPPort, daprGRPCPort, metricsPort, err := getDaprCommand(appID, config.HTTPPort, config.GRPCPort, config.AppPort, config.ConfigFile, config.Protocol, config.EnableProfiling, config.ProfilePort, config.LogLevel, config.MaxConcurrency, config.PlacementHost, config.ComponentsPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -343,13 +343,3 @@ func Run(config *RunConfig) (*RunOutput, error) {
|
|||
DaprGRPCPort: daprGRPCPort,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getComponentsPath(config *RunConfig) (string, error) {
|
||||
if config.ComponentsPath == "" {
|
||||
componentsPath := getDefaultComponentsFolder()
|
||||
return componentsPath, nil
|
||||
}
|
||||
|
||||
_, err := os.Stat(config.ComponentsPath)
|
||||
return config.ComponentsPath, err
|
||||
}
|
||||
|
|
|
@ -31,13 +31,13 @@ func assertArgument(t *testing.T, key string, expectedValue string, args []strin
|
|||
}
|
||||
|
||||
func setupRun(t *testing.T) {
|
||||
componentsDir := getDefaultComponentsFolder()
|
||||
componentsDir := GetDefaultComponentsFolder()
|
||||
err := os.MkdirAll(componentsDir, 0700)
|
||||
assert.Equal(t, nil, err, "Unable to setup components dir before running test")
|
||||
}
|
||||
|
||||
func tearDownRun(t *testing.T) {
|
||||
componentsDir := getDefaultComponentsFolder()
|
||||
componentsDir := GetDefaultComponentsFolder()
|
||||
err := os.RemoveAll(componentsDir)
|
||||
assert.Equal(t, nil, err, "Unable to delete components dir after running test")
|
||||
}
|
||||
|
@ -62,6 +62,7 @@ func TestRun(t *testing.T) {
|
|||
Protocol: "http",
|
||||
RedisHost: "localhost",
|
||||
PlacementHost: "localhost",
|
||||
ComponentsPath: GetDefaultComponentsFolder(),
|
||||
})
|
||||
|
||||
assert.Nil(t, err)
|
||||
|
@ -79,7 +80,7 @@ func TestRun(t *testing.T) {
|
|||
assertArgument(t, "max-concurrency", "-1", output.DaprCMD.Args)
|
||||
assertArgument(t, "protocol", "http", output.DaprCMD.Args)
|
||||
assertArgument(t, "app-port", "3000", output.DaprCMD.Args)
|
||||
assertArgument(t, "components-path", "", output.DaprCMD.Args)
|
||||
assertArgument(t, "components-path", GetDefaultComponentsFolder(), output.DaprCMD.Args)
|
||||
if runtime.GOOS == "windows" {
|
||||
assertArgument(t, "placement-address", "localhost:6050", output.DaprCMD.Args)
|
||||
} else {
|
||||
|
@ -102,6 +103,7 @@ func TestRun(t *testing.T) {
|
|||
Protocol: "http",
|
||||
RedisHost: "localhost",
|
||||
PlacementHost: "localhost",
|
||||
ComponentsPath: GetDefaultComponentsFolder(),
|
||||
})
|
||||
|
||||
assert.Nil(t, err)
|
||||
|
@ -119,7 +121,7 @@ func TestRun(t *testing.T) {
|
|||
assertArgument(t, "max-concurrency", "-1", output.DaprCMD.Args)
|
||||
assertArgument(t, "protocol", "http", output.DaprCMD.Args)
|
||||
assertArgument(t, "app-port", "3000", output.DaprCMD.Args)
|
||||
assertArgument(t, "components-path", "", output.DaprCMD.Args)
|
||||
assertArgument(t, "components-path", GetDefaultComponentsFolder(), output.DaprCMD.Args)
|
||||
if runtime.GOOS == "windows" {
|
||||
assertArgument(t, "placement-address", "localhost:6050", output.DaprCMD.Args)
|
||||
} else {
|
||||
|
|
|
@ -398,7 +398,7 @@ func createComponentsDir(wg *sync.WaitGroup, errorChan chan<- error, dir, versio
|
|||
defer wg.Done()
|
||||
|
||||
// Make default components directory
|
||||
componentsDir := getDefaultComponentsFolder()
|
||||
componentsDir := GetDefaultComponentsFolder()
|
||||
_, err := os.Stat(componentsDir)
|
||||
if os.IsNotExist(err) {
|
||||
errDir := os.MkdirAll(componentsDir, 0777)
|
||||
|
|
|
@ -50,7 +50,7 @@ func removeContainers(uninstallAll bool, dockerNetwork string) []error {
|
|||
}
|
||||
|
||||
func removeDefaultComponentsFolder() (string, error) {
|
||||
defaultComponentsPath := getDefaultComponentsFolder()
|
||||
defaultComponentsPath := GetDefaultComponentsFolder()
|
||||
err := os.RemoveAll(defaultComponentsPath)
|
||||
|
||||
return defaultComponentsPath, err
|
||||
|
|
Loading…
Reference in New Issue