@@ -28,6 +28,7 @@ import (
2828 "github.com/dapr/cli/pkg/metadata"
2929 "github.com/dapr/cli/pkg/print"
3030 "github.com/dapr/cli/pkg/standalone"
31+ "github.com/dapr/cli/pkg/standalone/runfileconfig"
3132 "github.com/dapr/cli/utils"
3233)
3334
5758 appHealthThreshold int
5859 enableAPILogging bool
5960 apiListenAddresses string
61+ runFilePath string
6062)
6163
6264const (
@@ -84,16 +86,39 @@ dapr run --app-id myapp
8486
8587# Run a gRPC application written in Go (listening on port 3000)
8688dapr run --app-id myapp --app-port 3000 --app-protocol grpc -- go run main.go
89+
90+ # Run sidecar only specifying dapr runtime installation directory
91+ dapr run --app-id myapp --dapr-path /usr/local/dapr
8792 ` ,
8893 Args : cobra .MinimumNArgs (0 ),
8994 PreRun : func (cmd * cobra.Command , args []string ) {
9095 viper .BindPFlag ("placement-host-address" , cmd .Flags ().Lookup ("placement-host-address" ))
9196 },
9297 Run : func (cmd * cobra.Command , args []string ) {
98+ if len (runFilePath ) > 0 {
99+ executeRunWithAppsConfigFile (runFilePath )
100+ return
101+ }
93102 if len (args ) == 0 {
94103 fmt .Println (print .WhiteBold ("WARNING: no application command found." ))
95104 }
96105
106+ daprDirPath , err := standalone .GetDaprPath (daprPath )
107+ if err != nil {
108+ print .FailureStatusEvent (os .Stderr , "Failed to get Dapr install directory: %v" , err )
109+ os .Exit (1 )
110+ }
111+
112+ // Fallback to default config file if not specified.
113+ if configFile == "" {
114+ configFile = standalone .GetDaprConfigPath (daprDirPath )
115+ }
116+
117+ // Fallback to default components directory if not specified.
118+ if componentsPath == "" {
119+ componentsPath = standalone .GetResourcesDir (daprDirPath )
120+ }
121+
97122 if unixDomainSocket != "" {
98123 // TODO(@daixiang0): add Windows support.
99124 if runtime .GOOS == "windows" {
@@ -107,34 +132,38 @@ dapr run --app-id myapp --app-port 3000 --app-protocol grpc -- go run main.go
107132 }
108133 }
109134
110- output , err := standalone .Run (& standalone.RunConfig {
111- AppID : appID ,
112- AppPort : appPort ,
113- HTTPPort : port ,
114- GRPCPort : grpcPort ,
135+ sharedRunConfig := & standalone.SharedRunConfig {
115136 ConfigFile : configFile ,
116- Arguments : args ,
117137 EnableProfiling : enableProfiling ,
118- ProfilePort : profilePort ,
119138 LogLevel : logLevel ,
120139 MaxConcurrency : maxConcurrency ,
121- Protocol : protocol ,
140+ AppProtocol : protocol ,
122141 PlacementHostAddr : viper .GetString ("placement-host-address" ),
123142 ComponentsPath : componentsPath ,
124143 ResourcesPath : resourcesPath ,
125144 AppSSL : appSSL ,
126- MetricsPort : metricsPort ,
127145 MaxRequestBodySize : maxRequestBodySize ,
128146 HTTPReadBufferSize : readBufferSize ,
129- UnixDomainSocket : unixDomainSocket ,
130147 EnableAppHealth : enableAppHealth ,
131148 AppHealthPath : appHealthPath ,
132149 AppHealthInterval : appHealthInterval ,
133150 AppHealthTimeout : appHealthTimeout ,
134151 AppHealthThreshold : appHealthThreshold ,
135152 EnableAPILogging : enableAPILogging ,
136- InternalGRPCPort : internalGRPCPort ,
137153 APIListenAddresses : apiListenAddresses ,
154+ }
155+ output , err := standalone .Run (& standalone.RunConfig {
156+ AppID : appID ,
157+ AppPort : appPort ,
158+ HTTPPort : port ,
159+ GRPCPort : grpcPort ,
160+ ProfilePort : profilePort ,
161+ Command : args ,
162+ MetricsPort : metricsPort ,
163+ UnixDomainSocket : unixDomainSocket ,
164+ InternalGRPCPort : internalGRPCPort ,
165+ DaprPathCmdFlag : daprPath ,
166+ SharedRunConfig : * sharedRunConfig ,
138167 })
139168 if err != nil {
140169 print .FailureStatusEvent (os .Stderr , err .Error ())
@@ -368,7 +397,7 @@ dapr run --app-id myapp --app-port 3000 --app-protocol grpc -- go run main.go
368397func init () {
369398 RunCmd .Flags ().IntVarP (& appPort , "app-port" , "p" , - 1 , "The port your application is listening on" )
370399 RunCmd .Flags ().StringVarP (& appID , "app-id" , "a" , "" , "The id for your application, used for service discovery" )
371- RunCmd .Flags ().StringVarP (& configFile , "config" , "c" , standalone . DefaultConfigFilePath () , "Dapr configuration file" )
400+ RunCmd .Flags ().StringVarP (& configFile , "config" , "c" , "" , "Dapr configuration file" )
372401 RunCmd .Flags ().IntVarP (& port , "dapr-http-port" , "H" , - 1 , "The HTTP port for Dapr to listen on" )
373402 RunCmd .Flags ().IntVarP (& grpcPort , "dapr-grpc-port" , "G" , - 1 , "The gRPC port for Dapr to listen on" )
374403 RunCmd .Flags ().IntVarP (& internalGRPCPort , "dapr-internal-grpc-port" , "I" , - 1 , "The gRPC port for the Dapr internal API to listen on" )
@@ -377,7 +406,7 @@ func init() {
377406 RunCmd .Flags ().StringVarP (& logLevel , "log-level" , "" , "info" , "The log verbosity. Valid values are: debug, info, warn, error, fatal, or panic" )
378407 RunCmd .Flags ().IntVarP (& maxConcurrency , "app-max-concurrency" , "" , - 1 , "The concurrency level of the application, otherwise is unlimited" )
379408 RunCmd .Flags ().StringVarP (& protocol , "app-protocol" , "P" , "http" , "The protocol (gRPC or HTTP) Dapr uses to talk to the application" )
380- RunCmd .Flags ().StringVarP (& componentsPath , "components-path" , "d" , standalone . GetResourcesDir () , "The path for resources directory" )
409+ RunCmd .Flags ().StringVarP (& componentsPath , "components-path" , "d" , "" , "The path for components directory" )
381410 RunCmd .Flags ().StringVarP (& resourcesPath , "resources-path" , "" , "" , "The path for resources directory" )
382411 // TODO: Remove below line once the flag is removed in the future releases.
383412 // By marking this as deprecated, the flag will be hidden from the help menu, but will continue to work. It will show a warning message when used.
@@ -396,5 +425,19 @@ func init() {
396425 RunCmd .Flags ().IntVar (& appHealthThreshold , "app-health-threshold" , 0 , "Number of consecutive failures for the app to be considered unhealthy" )
397426 RunCmd .Flags ().BoolVar (& enableAPILogging , "enable-api-logging" , false , "Log API calls at INFO verbosity. Valid values are: true or false" )
398427 RunCmd .Flags ().StringVar (& apiListenAddresses , "dapr-listen-addresses" , "" , "Comma separated list of IP addresses that sidecar will listen to" )
428+ RunCmd .Flags ().StringVarP (& runFilePath , "run-file" , "f" , "" , "Path to the configuration file for the apps to run" )
399429 RootCmd .AddCommand (RunCmd )
400430}
431+
432+ func executeRunWithAppsConfigFile (runFilePath string ) {
433+ config := runfileconfig.RunFileConfig {}
434+ apps , err := config .GetApps (runFilePath )
435+ if err != nil {
436+ print .FailureStatusEvent (os .Stdout , fmt .Sprintf ("Error getting apps from config file: %s" , err ))
437+ os .Exit (1 )
438+ }
439+ if len (apps ) == 0 {
440+ print .FailureStatusEvent (os .Stdout , "No apps to run" )
441+ os .Exit (1 )
442+ }
443+ }
0 commit comments