Skip to content

Commit 668bab4

Browse files
authored
Add --run-file support for stdin (#1364)
If the run-file argument is speficied as '-', read the config file from stdin Signed-off-by: Stuart Leeks <[email protected]>
1 parent a339bdf commit 668bab4

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Diff for: cmd/run.go

+6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ dapr run --run-file dapr.yaml
108108
# Run multiple apps by providing a directory path containing the run config file(dapr.yaml)
109109
dapr run --run-file /path/to/directory
110110
111+
# Run multiple apps by providing config via stdin
112+
cat dapr.template.yaml | envsubst | dapr run --run-file -
113+
111114
# Run multiple apps in Kubernetes by proficing path of a run config file
112115
dapr run --run-file dapr.yaml -k
113116
@@ -1008,6 +1011,9 @@ func putDaprLogFilePathInMeta(runE *runExec.RunExec, daprLogFilePath string) {
10081011
// If the provided path is a path to a YAML file then return the same.
10091012
// Else it returns the path of "dapr.yaml" in the provided directory.
10101013
func getRunFilePath(path string) (string, error) {
1014+
if path == "-" {
1015+
return path, nil // will be read from stdin later.
1016+
}
10111017
fileInfo, err := os.Stat(path)
10121018
if err != nil {
10131019
return "", fmt.Errorf("error getting file info for %s: %w", path, err)

Diff for: utils/utils.go

+7
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,13 @@ func ResolveHomeDir(filePath string) (string, error) {
392392
}
393393

394394
func ReadFile(filePath string) ([]byte, error) {
395+
if filePath == "-" {
396+
bytes, err := io.ReadAll(os.Stdin)
397+
if err != nil {
398+
return nil, fmt.Errorf("error in reading the provided app config from stdin: %w", err)
399+
}
400+
return bytes, nil
401+
}
395402
bytes, err := os.ReadFile(filePath)
396403
if err != nil {
397404
return nil, fmt.Errorf("error in reading the provided app config file: %w", err)

0 commit comments

Comments
 (0)