-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add capability to run to support
-f
flag (#1161)
* refactor run into functions Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> * renamed Apps struct as App Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> * redirect logs to files. set informational logs. set command dirs Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> * fix linter errors Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> * fix e2e test on non-existent resources-path Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> * more fixes Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> * fix merge conflict Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> * set default ports for zero values Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> * fix linter errors Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> * add more details in error, fix logs in run -f Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> * address review comments Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> * address review comments Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> * add more fixes in template run based on e2e tests Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
- Loading branch information
1 parent
b51eda4
commit 36893d9
Showing
9 changed files
with
765 additions
and
99 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
Copyright 2023 The Dapr Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package runexec | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os/exec" | ||
|
||
"github.com/dapr/cli/pkg/standalone" | ||
) | ||
|
||
type CmdProcess struct { | ||
Command *exec.Cmd | ||
CommandErr error | ||
OutputWriter io.Writer | ||
ErrorWriter io.Writer | ||
} | ||
|
||
type RunExec struct { | ||
DaprCMD *CmdProcess | ||
AppCMD *CmdProcess | ||
AppID string | ||
DaprHTTPPort int | ||
DaprGRPCPort int | ||
DaprMetricPort int | ||
} | ||
|
||
// RunOutput represents the run execution. | ||
type RunOutput struct { | ||
DaprCMD *exec.Cmd | ||
DaprErr error | ||
DaprHTTPPort int | ||
DaprGRPCPort int | ||
AppID string | ||
AppCMD *exec.Cmd | ||
AppErr error | ||
} | ||
|
||
func New(config *standalone.RunConfig, daprCmdProcess *CmdProcess, appCmdProcess *CmdProcess) *RunExec { | ||
return &RunExec{ | ||
DaprCMD: daprCmdProcess, | ||
AppCMD: appCmdProcess, | ||
AppID: config.AppID, | ||
DaprHTTPPort: config.HTTPPort, | ||
DaprGRPCPort: config.GRPCPort, | ||
DaprMetricPort: config.MetricsPort, | ||
} | ||
} | ||
|
||
func GetDaprCmdProcess(config *standalone.RunConfig) (*CmdProcess, error) { | ||
daprCMD, err := standalone.GetDaprCommand(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &CmdProcess{ | ||
Command: daprCMD, | ||
}, nil | ||
} | ||
|
||
func GetAppCmdProcess(config *standalone.RunConfig) (*CmdProcess, error) { | ||
//nolint | ||
var appCMD *exec.Cmd = standalone.GetAppCommand(config) | ||
return &CmdProcess{ | ||
Command: appCMD, | ||
}, nil | ||
} | ||
|
||
func (c *CmdProcess) WithOutputWriter(w io.Writer) { | ||
c.OutputWriter = w | ||
} | ||
|
||
// SetStdout should be called after WithOutputWriter. | ||
func (c *CmdProcess) SetStdout() error { | ||
if c.Command == nil { | ||
return fmt.Errorf("command is nil") | ||
} | ||
c.Command.Stdout = c.OutputWriter | ||
return nil | ||
} | ||
|
||
func (c *CmdProcess) WithErrorWriter(w io.Writer) { | ||
c.ErrorWriter = w | ||
} | ||
|
||
// SetStdErr should be called after WithErrorWriter. | ||
func (c *CmdProcess) SetStderr() error { | ||
if c.Command == nil { | ||
return fmt.Errorf("command is nil") | ||
} | ||
c.Command.Stderr = c.ErrorWriter | ||
return nil | ||
} | ||
|
||
func NewOutput(config *standalone.RunConfig) (*RunOutput, error) { | ||
// set default values from RunConfig struct's tag. | ||
config.SetDefaultFromSchema() | ||
//nolint | ||
err := config.Validate() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
daprCMD, err := standalone.GetDaprCommand(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
//nolint | ||
var appCMD *exec.Cmd = standalone.GetAppCommand(config) | ||
return &RunOutput{ | ||
DaprCMD: daprCMD, | ||
DaprErr: nil, | ||
AppCMD: appCMD, | ||
AppErr: nil, | ||
AppID: config.AppID, | ||
DaprHTTPPort: config.HTTPPort, | ||
DaprGRPCPort: config.GRPCPort, | ||
}, nil | ||
} |
Oops, something went wrong.