WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 0827566

Browse files
authored
Merge pull request #1566 from cicoyle/wf-rsrc-path2
[1.16] wf resource path
2 parents df58963 + f8ada9d commit 0827566

File tree

16 files changed

+145
-42
lines changed

16 files changed

+145
-42
lines changed

cmd/buildinfo.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
"github.com/spf13/cobra"
2121

22+
"github.com/dapr/cli/cmd/runtime"
2223
"github.com/dapr/cli/pkg/print"
2324
"github.com/dapr/cli/pkg/standalone"
2425
)
@@ -31,7 +32,7 @@ var BuildInfoCmd = &cobra.Command{
3132
dapr build-info
3233
`,
3334
Run: func(cmd *cobra.Command, args []string) {
34-
out, err := standalone.GetBuildInfo(daprRuntimePath, cliVersion)
35+
out, err := standalone.GetBuildInfo(runtime.GetDaprRuntimePath(), cliVersion)
3536
if err != nil {
3637
print.FailureStatusEvent(os.Stderr, "Error getting build info: %s", err.Error())
3738
os.Exit(1)

cmd/dapr.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/spf13/cobra"
2222
"github.com/spf13/viper"
2323

24+
"github.com/dapr/cli/cmd/runtime"
2425
"github.com/dapr/cli/cmd/scheduler"
2526
"github.com/dapr/cli/cmd/workflow"
2627
"github.com/dapr/cli/pkg/api"
@@ -62,11 +63,10 @@ const (
6263
)
6364

6465
var (
65-
cliVersion string
66-
versionFlag bool
67-
daprVer daprVersion
68-
logAsJSON bool
69-
daprRuntimePath string
66+
cliVersion string
67+
versionFlag bool
68+
daprVer daprVersion
69+
logAsJSON bool
7070
)
7171

7272
// Execute adds all child commands to the root command.
@@ -93,7 +93,7 @@ func initConfig() {
9393
print.EnableJSONFormat()
9494
}
9595
// err intentionally ignored since daprd may not yet be installed.
96-
runtimeVer, _ := standalone.GetRuntimeVersion(daprRuntimePath)
96+
runtimeVer, _ := standalone.GetRuntimeVersion(runtime.GetDaprRuntimePath())
9797

9898
daprVer = daprVersion{
9999
// Set in Execute() method in this file before initConfig() is called by cmd.Execute().
@@ -108,8 +108,8 @@ func initConfig() {
108108

109109
func init() {
110110
RootCmd.Flags().BoolVarP(&versionFlag, "version", "v", false, "version for dapr")
111-
RootCmd.PersistentFlags().StringVarP(&daprRuntimePath, "runtime-path", "", "", "The path to the dapr runtime installation directory")
112111
RootCmd.PersistentFlags().BoolVarP(&logAsJSON, "log-as-json", "", false, "Log output in JSON format")
112+
runtime.Register(RootCmd)
113113

114114
RootCmd.AddCommand(scheduler.SchedulerCmd)
115115
RootCmd.AddCommand(workflow.WorkflowCmd)

cmd/dashboard.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/pkg/browser"
2424
"github.com/spf13/cobra"
2525

26+
"github.com/dapr/cli/cmd/runtime"
2627
"github.com/dapr/cli/pkg/kubernetes"
2728
"github.com/dapr/cli/pkg/print"
2829
"github.com/dapr/cli/pkg/standalone"
@@ -83,7 +84,7 @@ dapr dashboard -k -p 0
8384
`,
8485
Run: func(cmd *cobra.Command, args []string) {
8586
if dashboardVersionCmd {
86-
dashboardVer, err := standalone.GetDashboardVersion(daprRuntimePath)
87+
dashboardVer, err := standalone.GetDashboardVersion(runtime.GetDaprRuntimePath())
8788
if err != nil {
8889
print.FailureStatusEvent(os.Stderr, "Failed to get Dapr install directory: %v", err)
8990
os.Exit(1)
@@ -195,7 +196,7 @@ dapr dashboard -k -p 0
195196
<-portForward.GetStop()
196197
} else {
197198
// Standalone mode.
198-
dashboardCmd, err := standalone.NewDashboardCmd(daprRuntimePath, dashboardLocalPort)
199+
dashboardCmd, err := standalone.NewDashboardCmd(runtime.GetDaprRuntimePath(), dashboardLocalPort)
199200
if err != nil {
200201
print.FailureStatusEvent(os.Stderr, "Failed to get Dapr install directory: %v", err)
201202
} else {

cmd/init.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/spf13/cobra"
2323
"github.com/spf13/viper"
2424

25+
"github.com/dapr/cli/cmd/runtime"
2526
"github.com/dapr/cli/pkg/kubernetes"
2627
"github.com/dapr/cli/pkg/print"
2728
"github.com/dapr/cli/pkg/standalone"
@@ -107,7 +108,7 @@ dapr init --runtime-path <path-to-install-directory>
107108
imageRegistryURI := ""
108109
var err error
109110

110-
if len(strings.TrimSpace(daprRuntimePath)) != 0 {
111+
if len(strings.TrimSpace(runtime.GetDaprRuntimePath())) != 0 {
111112
print.FailureStatusEvent(os.Stderr, "--runtime-path is only valid for self-hosted mode")
112113
os.Exit(1)
113114
}
@@ -178,7 +179,7 @@ dapr init --runtime-path <path-to-install-directory>
178179
schedulerHostPort = nil
179180
}
180181

181-
err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir, containerRuntime, imageVariant, daprRuntimePath, &schedulerVolume, schedulerHostPort)
182+
err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir, containerRuntime, imageVariant, runtime.GetDaprRuntimePath(), &schedulerVolume, schedulerHostPort)
182183
if err != nil {
183184
print.FailureStatusEvent(os.Stderr, err.Error())
184185
os.Exit(1)

cmd/run.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333

3434
daprRuntime "github.com/dapr/dapr/pkg/runtime"
3535

36+
cmdruntime "github.com/dapr/cli/cmd/runtime"
3637
"github.com/dapr/cli/pkg/kubernetes"
3738
"github.com/dapr/cli/pkg/metadata"
3839
"github.com/dapr/cli/pkg/print"
@@ -159,7 +160,7 @@ dapr run --run-file /path/to/directory -k
159160
fmt.Println(print.WhiteBold("WARNING: no application command found."))
160161
}
161162

162-
daprDirPath, err := standalone.GetDaprRuntimePath(daprRuntimePath)
163+
daprDirPath, err := standalone.GetDaprRuntimePath(cmdruntime.GetDaprRuntimePath())
163164
if err != nil {
164165
print.FailureStatusEvent(os.Stderr, "Failed to get Dapr install directory: %v", err)
165166
os.Exit(1)
@@ -206,7 +207,7 @@ dapr run --run-file /path/to/directory -k
206207
AppHealthThreshold: appHealthThreshold,
207208
EnableAPILogging: enableAPILogging,
208209
APIListenAddresses: apiListenAddresses,
209-
DaprdInstallPath: daprRuntimePath,
210+
DaprdInstallPath: cmdruntime.GetDaprRuntimePath(),
210211
}
211212

212213
// placement-host-address flag handling: only set pointer if flag was explicitly changed

cmd/runtime/runtime.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
Copyright 2025 The Dapr Authors
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package runtime
15+
16+
import "github.com/spf13/cobra"
17+
18+
var (
19+
daprRuntimePath string
20+
)
21+
22+
func Register(cmd *cobra.Command) {
23+
cmd.PersistentFlags().StringVarP(&daprRuntimePath, "runtime-path", "", "", "The path to the dapr runtime installation directory")
24+
}
25+
26+
func GetDaprRuntimePath() string {
27+
return daprRuntimePath
28+
}

cmd/uninstall.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/spf13/cobra"
2222
"github.com/spf13/viper"
2323

24+
cmdruntime "github.com/dapr/cli/cmd/runtime"
2425
"github.com/dapr/cli/pkg/kubernetes"
2526
"github.com/dapr/cli/pkg/print"
2627
"github.com/dapr/cli/pkg/standalone"
@@ -70,7 +71,7 @@ dapr uninstall --runtime-path <path-to-install-directory>
7071
var err error
7172

7273
if uninstallKubernetes {
73-
if len(strings.TrimSpace(daprRuntimePath)) != 0 {
74+
if len(strings.TrimSpace(cmdruntime.GetDaprRuntimePath())) != 0 {
7475
print.FailureStatusEvent(os.Stderr, "--runtime-path is only valid for self-hosted mode")
7576
os.Exit(1)
7677
}
@@ -84,7 +85,7 @@ dapr uninstall --runtime-path <path-to-install-directory>
8485
}
8586
print.InfoStatusEvent(os.Stdout, "Removing Dapr from your machine...")
8687
dockerNetwork := viper.GetString("network")
87-
err = standalone.Uninstall(uninstallAll, dockerNetwork, uninstallContainerRuntime, daprRuntimePath)
88+
err = standalone.Uninstall(uninstallAll, dockerNetwork, uninstallContainerRuntime, cmdruntime.GetDaprRuntimePath())
8889
}
8990

9091
if err != nil {

pkg/version/version_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ func TestGetVersionsGithub(t *testing.T) {
210210
}
211211
m := http.NewServeMux()
212212
s := http.Server{Addr: ":12345", Handler: m, ReadHeaderTimeout: time.Duration(5) * time.Second}
213+
defer s.Close()
213214

214215
for _, tc := range tests {
215216
body := tc.ResponseBody
@@ -319,6 +320,7 @@ entries:
319320
}
320321
m := http.NewServeMux()
321322
s := http.Server{Addr: ":12346", Handler: m, ReadHeaderTimeout: time.Duration(5) * time.Second}
323+
defer s.Close()
322324

323325
for _, tc := range tests {
324326
body := tc.ResponseBody

pkg/workflow/dclient/dclient.go

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ import (
2727
"github.com/dapr/kit/ptr"
2828
)
2929

30+
type Options struct {
31+
KubernetesMode bool
32+
Namespace string
33+
AppID string
34+
RuntimePath string
35+
}
36+
3037
type Client struct {
3138
Dapr client.Client
3239
Cancel context.CancelFunc
@@ -35,44 +42,54 @@ type Client struct {
3542
TableName *string
3643
}
3744

38-
func DaprClient(ctx context.Context, kubernetesMode bool, namespace, appID string) (*Client, error) {
45+
func DaprClient(ctx context.Context, opts Options) (*Client, error) {
3946
client.SetLogger(nil)
4047

4148
var client *Client
4249
var err error
43-
if kubernetesMode {
44-
client, err = kube(namespace, appID)
50+
if opts.KubernetesMode {
51+
client, err = kube(opts)
4552
} else {
46-
client, err = stand(ctx, appID)
53+
client, err = stand(ctx, opts)
4754
}
4855

4956
return client, err
5057
}
5158

52-
func stand(ctx context.Context, appID string) (*Client, error) {
59+
func stand(ctx context.Context, opts Options) (*Client, error) {
5360
list, err := standalone.List()
5461
if err != nil {
5562
return nil, err
5663
}
5764

5865
var proc *standalone.ListOutput
5966
for _, c := range list {
60-
if c.AppID == appID {
67+
if c.AppID == opts.AppID {
6168
proc = &c
6269
break
6370
}
6471
}
6572

6673
if proc == nil {
67-
return nil, fmt.Errorf("Dapr app with id '%s' not found", appID)
74+
return nil, fmt.Errorf("Dapr app with id '%s' not found", opts.AppID)
75+
}
76+
77+
if len(proc.ResourcePaths) == 0 {
78+
var daprDirPath string
79+
daprDirPath, err = standalone.GetDaprRuntimePath(opts.RuntimePath)
80+
if err != nil {
81+
return nil, err
82+
}
83+
84+
proc.ResourcePaths = []string{standalone.GetDaprComponentsPath(daprDirPath)}
6885
}
6986

70-
comps, err := loader.NewLocalLoader(appID, proc.ResourcePaths).Load(ctx)
87+
comps, err := loader.NewLocalLoader(opts.AppID, proc.ResourcePaths).Load(ctx)
7188
if err != nil {
7289
return nil, err
7390
}
7491

75-
c, err := clientFromComponents(comps, appID, strconv.Itoa(proc.GRPCPort))
92+
c, err := clientFromComponents(comps, opts.AppID, strconv.Itoa(proc.GRPCPort))
7693
if err != nil {
7794
return nil, err
7895
}
@@ -81,22 +98,22 @@ func stand(ctx context.Context, appID string) (*Client, error) {
8198
return c, nil
8299
}
83100

84-
func kube(namespace string, appID string) (*Client, error) {
85-
list, err := kubernetes.List(namespace)
101+
func kube(opts Options) (*Client, error) {
102+
list, err := kubernetes.List(opts.Namespace)
86103
if err != nil {
87104
return nil, err
88105
}
89106

90107
var pod *kubernetes.ListOutput
91108
for _, p := range list {
92-
if p.AppID == appID {
109+
if p.AppID == opts.AppID {
93110
pod = &p
94111
break
95112
}
96113
}
97114

98115
if pod == nil {
99-
return nil, fmt.Errorf("Dapr app with id '%s' not found in namespace %s", appID, namespace)
116+
return nil, fmt.Errorf("Dapr app with id '%s' not found in namespace %s", opts.AppID, opts.Namespace)
100117
}
101118

102119
config, _, err := kubernetes.GetKubeConfigClient()
@@ -111,7 +128,7 @@ func kube(namespace string, appID string) (*Client, error) {
111128

112129
portForward, err := kubernetes.NewPortForward(
113130
config,
114-
namespace,
131+
opts.Namespace,
115132
pod.PodName,
116133
"localhost",
117134
port,
@@ -136,7 +153,7 @@ func kube(namespace string, appID string) (*Client, error) {
136153
return nil, err
137154
}
138155

139-
c, err := clientFromComponents(comps.Items, appID, pod.DaprGRPCPort)
156+
c, err := clientFromComponents(comps.Items, opts.AppID, pod.DaprGRPCPort)
140157
if err != nil {
141158
portForward.Stop()
142159
}

pkg/workflow/events.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package workflow
1616
import (
1717
"context"
1818

19+
"github.com/dapr/cli/cmd/runtime"
1920
"github.com/dapr/cli/pkg/workflow/dclient"
2021
"github.com/dapr/durabletask-go/workflow"
2122
)
@@ -30,7 +31,12 @@ type RaiseEventOptions struct {
3031
}
3132

3233
func RaiseEvent(ctx context.Context, opts RaiseEventOptions) error {
33-
cli, err := dclient.DaprClient(ctx, opts.KubernetesMode, opts.Namespace, opts.AppID)
34+
cli, err := dclient.DaprClient(ctx, dclient.Options{
35+
KubernetesMode: opts.KubernetesMode,
36+
Namespace: opts.Namespace,
37+
AppID: opts.AppID,
38+
RuntimePath: runtime.GetDaprRuntimePath(),
39+
})
3440
if err != nil {
3541
return err
3642
}
@@ -55,7 +61,12 @@ type SuspendOptions struct {
5561
}
5662

5763
func Suspend(ctx context.Context, opts SuspendOptions) error {
58-
cli, err := dclient.DaprClient(ctx, opts.KubernetesMode, opts.Namespace, opts.AppID)
64+
cli, err := dclient.DaprClient(ctx, dclient.Options{
65+
KubernetesMode: opts.KubernetesMode,
66+
Namespace: opts.Namespace,
67+
AppID: opts.AppID,
68+
RuntimePath: runtime.GetDaprRuntimePath(),
69+
})
5970
if err != nil {
6071
return err
6172
}
@@ -75,7 +86,12 @@ type ResumeOptions struct {
7586
}
7687

7788
func Resume(ctx context.Context, opts ResumeOptions) error {
78-
cli, err := dclient.DaprClient(ctx, opts.KubernetesMode, opts.Namespace, opts.AppID)
89+
cli, err := dclient.DaprClient(ctx, dclient.Options{
90+
KubernetesMode: opts.KubernetesMode,
91+
Namespace: opts.Namespace,
92+
AppID: opts.AppID,
93+
RuntimePath: runtime.GetDaprRuntimePath(),
94+
})
7995
if err != nil {
8096
return err
8197
}
@@ -95,7 +111,12 @@ type TerminateOptions struct {
95111
}
96112

97113
func Terminate(ctx context.Context, opts TerminateOptions) error {
98-
cli, err := dclient.DaprClient(ctx, opts.KubernetesMode, opts.Namespace, opts.AppID)
114+
cli, err := dclient.DaprClient(ctx, dclient.Options{
115+
KubernetesMode: opts.KubernetesMode,
116+
Namespace: opts.Namespace,
117+
AppID: opts.AppID,
118+
RuntimePath: runtime.GetDaprRuntimePath(),
119+
})
99120
if err != nil {
100121
return err
101122
}

0 commit comments

Comments
 (0)