Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --run-file support for stdin #1364

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ dapr run --run-file dapr.yaml
# Run multiple apps by providing a directory path containing the run config file(dapr.yaml)
dapr run --run-file /path/to/directory

# Run multiple apps by providing config via stdin
cat dapr.template.yaml | envsubst | dapr run --run-file -

# Run multiple apps in Kubernetes by proficing path of a run config file
dapr run --run-file dapr.yaml -k

Expand Down Expand Up @@ -1008,6 +1011,9 @@ func putDaprLogFilePathInMeta(runE *runExec.RunExec, daprLogFilePath string) {
// If the provided path is a path to a YAML file then return the same.
// Else it returns the path of "dapr.yaml" in the provided directory.
func getRunFilePath(path string) (string, error) {
if path == "-" {
return path, nil // will be read from stdin later.
}
fileInfo, err := os.Stat(path)
if err != nil {
return "", fmt.Errorf("error getting file info for %s: %w", path, err)
Expand Down
7 changes: 7 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,13 @@ func ResolveHomeDir(filePath string) (string, error) {
}

func ReadFile(filePath string) ([]byte, error) {
if filePath == "-" {
bytes, err := io.ReadAll(os.Stdin)
if err != nil {
return nil, fmt.Errorf("error in reading the provided app config from stdin: %w", err)
}
return bytes, nil
}
bytes, err := os.ReadFile(filePath)
if err != nil {
return nil, fmt.Errorf("error in reading the provided app config file: %w", err)
Expand Down