@@ -28,6 +28,7 @@ import (
28
28
"github.com/dapr/cli/pkg/metadata"
29
29
"github.com/dapr/cli/pkg/print"
30
30
"github.com/dapr/cli/pkg/standalone"
31
+ "github.com/dapr/cli/pkg/standalone/runfileconfig"
31
32
"github.com/dapr/cli/utils"
32
33
)
33
34
57
58
appHealthThreshold int
58
59
enableAPILogging bool
59
60
apiListenAddresses string
61
+ runFilePath string
60
62
)
61
63
62
64
const (
@@ -84,16 +86,39 @@ dapr run --app-id myapp
84
86
85
87
# Run a gRPC application written in Go (listening on port 3000)
86
88
dapr 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
87
92
` ,
88
93
Args : cobra .MinimumNArgs (0 ),
89
94
PreRun : func (cmd * cobra.Command , args []string ) {
90
95
viper .BindPFlag ("placement-host-address" , cmd .Flags ().Lookup ("placement-host-address" ))
91
96
},
92
97
Run : func (cmd * cobra.Command , args []string ) {
98
+ if len (runFilePath ) > 0 {
99
+ executeRunWithAppsConfigFile (runFilePath )
100
+ return
101
+ }
93
102
if len (args ) == 0 {
94
103
fmt .Println (print .WhiteBold ("WARNING: no application command found." ))
95
104
}
96
105
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
+
97
122
if unixDomainSocket != "" {
98
123
// TODO(@daixiang0): add Windows support.
99
124
if runtime .GOOS == "windows" {
@@ -107,34 +132,38 @@ dapr run --app-id myapp --app-port 3000 --app-protocol grpc -- go run main.go
107
132
}
108
133
}
109
134
110
- output , err := standalone .Run (& standalone.RunConfig {
111
- AppID : appID ,
112
- AppPort : appPort ,
113
- HTTPPort : port ,
114
- GRPCPort : grpcPort ,
135
+ sharedRunConfig := & standalone.SharedRunConfig {
115
136
ConfigFile : configFile ,
116
- Arguments : args ,
117
137
EnableProfiling : enableProfiling ,
118
- ProfilePort : profilePort ,
119
138
LogLevel : logLevel ,
120
139
MaxConcurrency : maxConcurrency ,
121
- Protocol : protocol ,
140
+ AppProtocol : protocol ,
122
141
PlacementHostAddr : viper .GetString ("placement-host-address" ),
123
142
ComponentsPath : componentsPath ,
124
143
ResourcesPath : resourcesPath ,
125
144
AppSSL : appSSL ,
126
- MetricsPort : metricsPort ,
127
145
MaxRequestBodySize : maxRequestBodySize ,
128
146
HTTPReadBufferSize : readBufferSize ,
129
- UnixDomainSocket : unixDomainSocket ,
130
147
EnableAppHealth : enableAppHealth ,
131
148
AppHealthPath : appHealthPath ,
132
149
AppHealthInterval : appHealthInterval ,
133
150
AppHealthTimeout : appHealthTimeout ,
134
151
AppHealthThreshold : appHealthThreshold ,
135
152
EnableAPILogging : enableAPILogging ,
136
- InternalGRPCPort : internalGRPCPort ,
137
153
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 ,
138
167
})
139
168
if err != nil {
140
169
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
368
397
func init () {
369
398
RunCmd .Flags ().IntVarP (& appPort , "app-port" , "p" , - 1 , "The port your application is listening on" )
370
399
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" )
372
401
RunCmd .Flags ().IntVarP (& port , "dapr-http-port" , "H" , - 1 , "The HTTP port for Dapr to listen on" )
373
402
RunCmd .Flags ().IntVarP (& grpcPort , "dapr-grpc-port" , "G" , - 1 , "The gRPC port for Dapr to listen on" )
374
403
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() {
377
406
RunCmd .Flags ().StringVarP (& logLevel , "log-level" , "" , "info" , "The log verbosity. Valid values are: debug, info, warn, error, fatal, or panic" )
378
407
RunCmd .Flags ().IntVarP (& maxConcurrency , "app-max-concurrency" , "" , - 1 , "The concurrency level of the application, otherwise is unlimited" )
379
408
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" )
381
410
RunCmd .Flags ().StringVarP (& resourcesPath , "resources-path" , "" , "" , "The path for resources directory" )
382
411
// TODO: Remove below line once the flag is removed in the future releases.
383
412
// 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() {
396
425
RunCmd .Flags ().IntVar (& appHealthThreshold , "app-health-threshold" , 0 , "Number of consecutive failures for the app to be considered unhealthy" )
397
426
RunCmd .Flags ().BoolVar (& enableAPILogging , "enable-api-logging" , false , "Log API calls at INFO verbosity. Valid values are: true or false" )
398
427
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" )
399
429
RootCmd .AddCommand (RunCmd )
400
430
}
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