Skip to content

Commit 6c1bc53

Browse files
hueifengmukundansundaryaron2shubham1172pravinpushkar
authored
support resources-path (#1012)
* support spec-resources-path Signed-off-by: HueiFeng <[email protected]> * Update resource-path Signed-off-by: hueifeng <[email protected]> * Update resource-path Signed-off-by: hueifeng <[email protected]> * fix Signed-off-by: hueifeng <[email protected]> * added deprecation message and e2e tests Signed-off-by: Pravin Pushkar <[email protected]> * added messages in readme for deprecation and use of resource-path Signed-off-by: Pravin Pushkar <[email protected]> * fix lint and failing test case Signed-off-by: Pravin Pushkar <[email protected]> Signed-off-by: HueiFeng <[email protected]> Signed-off-by: hueifeng <[email protected]> Signed-off-by: Pravin Pushkar <[email protected]> Co-authored-by: Mukundan Sundararajan <[email protected]> Co-authored-by: Yaron Schneider <[email protected]> Co-authored-by: Shubham Sharma <[email protected]> Co-authored-by: Pravin Pushkar <[email protected]>
1 parent 63f14c3 commit 6c1bc53

File tree

5 files changed

+52
-5
lines changed

5 files changed

+52
-5
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Output should look like so:
9999
100100
This step creates the following defaults:
101101

102-
1. components folder which is later used during `dapr run` unless the `--components-path` option is provided. For Linux/MacOS, the default components folder path is `$HOME/.dapr/components` and for Windows it is `%USERPROFILE%\.dapr\components`.
102+
1. components folder which is later used during `dapr run` unless the `--resources-path` (`--components-path` is deprecated and will be removed in future releases) option is provided. For Linux/MacOS, the default components folder path is `$HOME/.dapr/components` and for Windows it is `%USERPROFILE%\.dapr\components`.
103103
2. component files in the components folder called `pubsub.yaml` and `statestore.yaml`.
104104
3. default config file `$HOME/.dapr/config.yaml` for Linux/MacOS or for Windows at `%USERPROFILE%\.dapr\config.yaml` to enable tracing on `dapr init` call. Can be overridden with the `--config` flag on `dapr run`.
105105

@@ -121,7 +121,7 @@ Output should look like so:
121121
✅ Success! Dapr is up and running. To get started, go here: https://aka.ms/dapr-getting-started
122122
```
123123

124-
>Note: When initializing Dapr with the `--slim` flag only the Dapr runtime binary and the placement service binary are installed. An empty default components folder is created with no default configuration files. During `dapr run` user should use `--components-path` to point to a components directory with custom configurations files or alternatively place these files in the default directory. For Linux/MacOS, the default components directory path is `$HOME/.dapr/components` and for Windows it is `%USERPROFILE%\.dapr\components`.
124+
>Note: When initializing Dapr with the `--slim` flag only the Dapr runtime binary and the placement service binary are installed. An empty default components folder is created with no default configuration files. During `dapr run` user should use `--resources-path` (`--components-path` is deprecated and will be removed in future releases) to point to a components directory with custom configurations files or alternatively place these files in the default directory. For Linux/MacOS, the default components directory path is `$HOME/.dapr/components` and for Windows it is `%USERPROFILE%\.dapr\components`.
125125
126126
#### Install a specific runtime version
127127

@@ -444,7 +444,7 @@ Launch Dapr and your app:
444444
dapr run --app-id nodeapp --app-port 3000 node app.js
445445
```
446446

447-
Note: To choose a non-default components folder, use the --components-path option.
447+
Note: To choose a non-default components folder, use the --resources-path(--components-path is deprecated) option.
448448

449449
Invoke your app:
450450

@@ -561,7 +561,8 @@ dapr components --kubernetes --namespace target-namespace
561561
To use a custom path for component definitions
562562

563563
```bash
564-
dapr run --components-path [custom path]
564+
dapr run --resources-path [custom path]
565+
> Note: --components-path flag is deprecated. It will continue to work until it is removed completely.
565566
```
566567
567568

cmd/run.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var (
4444
logLevel string
4545
protocol string
4646
componentsPath string
47+
resourcesPath string
4748
appSSL bool
4849
metricsPort int
4950
maxRequestBodySize int
@@ -120,6 +121,7 @@ dapr run --app-id myapp --app-port 3000 --app-protocol grpc -- go run main.go
120121
Protocol: protocol,
121122
PlacementHostAddr: viper.GetString("placement-host-address"),
122123
ComponentsPath: componentsPath,
124+
ResourcesPath: resourcesPath,
123125
AppSSL: appSSL,
124126
MetricsPort: metricsPort,
125127
MaxRequestBodySize: maxRequestBodySize,
@@ -376,6 +378,10 @@ func init() {
376378
RunCmd.Flags().IntVarP(&maxConcurrency, "app-max-concurrency", "", -1, "The concurrency level of the application, otherwise is unlimited")
377379
RunCmd.Flags().StringVarP(&protocol, "app-protocol", "P", "http", "The protocol (gRPC or HTTP) Dapr uses to talk to the application")
378380
RunCmd.Flags().StringVarP(&componentsPath, "components-path", "d", standalone.DefaultComponentsDirPath(), "The path for components directory")
381+
RunCmd.Flags().StringVarP(&resourcesPath, "resources-path", "", "", "The path for resources directory")
382+
// TODO: Remove below line once the flag is removed in the future releases.
383+
// 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.
384+
RunCmd.Flags().MarkDeprecated("components-path", "This flag is deprecated and will be removed in the future releases. Use \"resources-path\" flag instead")
379385
RunCmd.Flags().String("placement-host-address", "localhost", "The address of the placement service. Format is either <hostname> for default port or <hostname>:<port> for custom port")
380386
RunCmd.Flags().BoolVar(&appSSL, "app-ssl", false, "Enable https when Dapr invokes the application")
381387
RunCmd.Flags().IntVarP(&metricsPort, "metrics-port", "M", -1, "The port of metrics on dapr")

pkg/standalone/run.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type RunConfig struct {
4949
MaxConcurrency int `arg:"app-max-concurrency"`
5050
PlacementHostAddr string `arg:"placement-host-address"`
5151
ComponentsPath string `arg:"components-path"`
52+
ResourcesPath string `arg:"resources-path"`
5253
AppSSL bool `arg:"app-ssl"`
5354
MetricsPort int `env:"DAPR_METRICS_PORT" arg:"metrics-port"`
5455
MaxRequestBodySize int `arg:"dapr-http-max-request-size"`
@@ -132,6 +133,10 @@ func (config *RunConfig) validate() error {
132133
return err
133134
}
134135

136+
if config.ResourcesPath != "" {
137+
config.ComponentsPath = ""
138+
}
139+
135140
if config.AppPort < 0 {
136141
config.AppPort = 0
137142
}
@@ -231,6 +236,7 @@ func newDaprMeta() (*DaprMeta, error) {
231236

232237
func (config *RunConfig) getArgs() []string {
233238
args := []string{}
239+
234240
schema := reflect.ValueOf(*config)
235241
for i := 0; i < schema.NumField(); i++ {
236242
valueField := schema.Field(i).Interface()
@@ -255,6 +261,7 @@ func (config *RunConfig) getArgs() []string {
255261
}
256262
}
257263
}
264+
258265
if config.ConfigFile != "" {
259266
sentryAddress := mtlsEndpoint(config.ConfigFile)
260267
if sentryAddress != "" {
@@ -266,7 +273,6 @@ func (config *RunConfig) getArgs() []string {
266273
if print.IsJSONLogEnabled() {
267274
args = append(args, "--log-as-json")
268275
}
269-
270276
return args
271277
}
272278

tests/e2e/standalone/run_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,32 @@ func TestStandaloneRun(t *testing.T) {
121121
assert.Contains(t, output, "Exited Dapr successfully")
122122
})
123123

124+
t.Run(fmt.Sprintf("check run with resources-path flag"), func(t *testing.T) {
125+
args := []string{
126+
"--app-id", "testapp",
127+
"--resources-path", "../testdata/nonexistentdir",
128+
"--", "bash", "-c", "echo 'test'",
129+
}
130+
output, err := cmdRun("", args...)
131+
t.Log(output)
132+
require.NoError(t, err, "run failed")
133+
assert.Contains(t, output, "failed to load components: open ../testdata/nonexistentdir:")
134+
assert.Contains(t, output, "Exited App successfully")
135+
assert.Contains(t, output, "Exited Dapr successfully")
136+
137+
args = []string{
138+
"--app-id", "testapp",
139+
"--resources-path", "../testdata/resources",
140+
"--", "bash", "-c", "echo 'test'",
141+
}
142+
output, err = cmdRun("", args...)
143+
t.Log(output)
144+
require.NoError(t, err, "run failed")
145+
assert.Contains(t, output, "component loaded. name: test-statestore, type: state.in-memory/v1")
146+
assert.Contains(t, output, "Exited App successfully")
147+
assert.Contains(t, output, "Exited Dapr successfully")
148+
})
149+
124150
t.Run("run with unknown flags", func(t *testing.T) {
125151
output, err := cmdRun("", "--flag")
126152
require.Error(t, err, "expected error on run unknown flag")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: dapr.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: test-statestore
5+
spec:
6+
type: state.in-memory
7+
version: v1
8+
metadata:

0 commit comments

Comments
 (0)