Skip to content

Commit c5646d4

Browse files
committed
merge master and fix conflicts
Signed-off-by: Pravin Pushkar <[email protected]>
2 parents 771b256 + c1f9627 commit c5646d4

34 files changed

+1233
-161
lines changed

.github/workflows/self_hosted_e2e.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ jobs:
132132
env:
133133
DAPR_E2E_INIT_SLIM: ${{ contains(matrix.os, 'windows-latest') || contains(matrix.dapr_install_mode, 'slim') }}
134134
CONTAINER_RUNTIME: ${{ env.CONTAINER_RUNTIME }}
135+
E2E_SH_TEST_TIMEOUT: ${{ env.E2E_SH_TEST_TIMEOUT }}
135136
run: |
136137
export TEST_OUTPUT_FILE=$GITHUB_WORKSPACE/test-e2e-standalone.json
137138
echo "TEST_OUTPUT_FILE=$TEST_OUTPUT_FILE" >> $GITHUB_ENV

Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ export GOOS ?= $(TARGET_OS_LOCAL)
7070
export BINARY_EXT ?= $(BINARY_EXT_LOCAL)
7171

7272
TEST_OUTPUT_FILE ?= test_output.json
73-
E2E_SH_TEST_TIMEOUT ?= 10m
73+
74+
# Set the default timeout for tests to 10 minutes
75+
ifndef E2E_SH_TEST_TIMEOUT
76+
override E2E_SH_TEST_TIMEOUT := 10m
77+
endif
7478

7579
# Use the variable H to add a header (equivalent to =>) to informational output
7680
H = $(shell printf "\033[34;1m=>\033[0m")

cmd/buildinfo.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ package cmd
1515

1616
import (
1717
"fmt"
18+
"os"
1819

1920
"github.com/spf13/cobra"
2021

22+
"github.com/dapr/cli/pkg/print"
2123
"github.com/dapr/cli/pkg/standalone"
2224
)
2325

@@ -29,7 +31,12 @@ var BuildInfoCmd = &cobra.Command{
2931
dapr build-info
3032
`,
3133
Run: func(cmd *cobra.Command, args []string) {
32-
fmt.Println(standalone.GetBuildInfo(RootCmd.Version))
34+
out, err := standalone.GetBuildInfo(daprPath, RootCmd.Version)
35+
if err != nil {
36+
print.FailureStatusEvent(os.Stderr, "Error getting build info: %s", err.Error())
37+
os.Exit(1)
38+
}
39+
fmt.Println(out)
3340
},
3441
}
3542

cmd/dapr.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,20 @@ type daprVersion struct {
4949
var (
5050
daprVer daprVersion
5151
logAsJSON bool
52+
daprPath string
5253
)
5354

5455
// Execute adds all child commands to the root command.
5556
func Execute(version, apiVersion string) {
5657
RootCmd.Version = version
5758
api.RuntimeAPIVersion = apiVersion
5859

60+
// err intentionally ignored since daprd may not yet be installed.
61+
runtimeVer, _ := standalone.GetRuntimeVersion(daprPath)
62+
5963
daprVer = daprVersion{
6064
CliVersion: version,
61-
RuntimeVersion: strings.ReplaceAll(standalone.GetRuntimeVersion(), "\n", ""),
65+
RuntimeVersion: strings.ReplaceAll(runtimeVer, "\n", ""),
6266
}
6367

6468
cobra.OnInitialize(initConfig)
@@ -87,5 +91,6 @@ func initConfig() {
8791
}
8892

8993
func init() {
94+
RootCmd.PersistentFlags().StringVarP(&daprPath, "dapr-path", "", "", "The path to the dapr installation directory")
9095
RootCmd.PersistentFlags().BoolVarP(&logAsJSON, "log-as-json", "", false, "Log output in JSON format")
9196
}

cmd/dashboard.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ dapr dashboard -k -p 0
7979
`,
8080
Run: func(cmd *cobra.Command, args []string) {
8181
if dashboardVersionCmd {
82-
fmt.Println(standalone.GetDashboardVersion())
82+
dashboardVer, err := standalone.GetDashboardVersion(daprPath)
83+
if err != nil {
84+
print.FailureStatusEvent(os.Stderr, "Failed to get Dapr install directory: %v", err)
85+
os.Exit(1)
86+
}
87+
88+
fmt.Println(dashboardVer)
8389
os.Exit(0)
8490
}
8591

@@ -179,9 +185,14 @@ dapr dashboard -k -p 0
179185
<-portForward.GetStop()
180186
} else {
181187
// Standalone mode.
182-
err := standalone.NewDashboardCmd(dashboardLocalPort).Run()
188+
dashboardCmd, err := standalone.NewDashboardCmd(daprPath, dashboardLocalPort)
183189
if err != nil {
184-
print.FailureStatusEvent(os.Stderr, "Dapr dashboard not found. Is Dapr installed?")
190+
print.FailureStatusEvent(os.Stderr, "Failed to get Dapr install directory: %v", err)
191+
} else {
192+
err = dashboardCmd.Run()
193+
if err != nil {
194+
print.FailureStatusEvent(os.Stderr, "Dapr dashboard failed to run: %v", err)
195+
}
185196
}
186197
}
187198
},
@@ -199,5 +210,6 @@ func init() {
199210
DashboardCmd.Flags().IntVarP(&dashboardLocalPort, "port", "p", defaultLocalPort, "The local port on which to serve Dapr dashboard")
200211
DashboardCmd.Flags().StringVarP(&dashboardNamespace, "namespace", "n", daprSystemNamespace, "The namespace where Dapr dashboard is running")
201212
DashboardCmd.Flags().BoolP("help", "h", false, "Print this help message")
213+
202214
RootCmd.AddCommand(DashboardCmd)
203215
}

cmd/init.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ dapr init --from-dir <path-to-directory>
8181
# Initialize dapr with a particular image variant. Allowed values: "mariner"
8282
dapr init --image-variant <variant>
8383
84+
# Initialize Dapr to non-default install directory (default is $HOME/.dapr)
85+
dapr init --dapr-path <path-to-install-directory>
86+
8487
# See more at: https://docs.dapr.io/getting-started/
8588
`,
8689
Run: func(cmd *cobra.Command, args []string) {
@@ -92,6 +95,11 @@ dapr init --image-variant <variant>
9295
imageRegistryURI := ""
9396
var err error
9497

98+
if len(strings.TrimSpace(daprPath)) != 0 {
99+
print.FailureStatusEvent(os.Stderr, "--dapr-path is only valid for self-hosted mode")
100+
os.Exit(1)
101+
}
102+
95103
if len(imageRegistryFlag) != 0 {
96104
warnForPrivateRegFeat()
97105
imageRegistryURI = imageRegistryFlag
@@ -137,11 +145,12 @@ dapr init --image-variant <variant>
137145
if len(imageRegistryURI) != 0 {
138146
warnForPrivateRegFeat()
139147
}
148+
140149
if !utils.IsValidContainerRuntime(containerRuntime) {
141150
print.FailureStatusEvent(os.Stdout, "Invalid container runtime. Supported values are docker and podman.")
142151
os.Exit(1)
143152
}
144-
err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir, containerRuntime, imageVariant)
153+
err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir, containerRuntime, imageVariant, daprPath)
145154
if err != nil {
146155
print.FailureStatusEvent(os.Stderr, err.Error())
147156
os.Exit(1)
@@ -168,6 +177,7 @@ func init() {
168177
if dashboardVersionEnv != "" {
169178
defaultDashboardVersion = dashboardVersionEnv
170179
}
180+
171181
InitCmd.Flags().BoolVarP(&kubernetesMode, "kubernetes", "k", false, "Deploy Dapr to a Kubernetes cluster")
172182
InitCmd.Flags().BoolVarP(&wait, "wait", "", false, "Wait for Kubernetes initialization to complete")
173183
InitCmd.Flags().UintVarP(&timeout, "timeout", "", 300, "The wait timeout for the Kubernetes installation")
@@ -184,5 +194,6 @@ func init() {
184194
InitCmd.Flags().StringArrayVar(&values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
185195
InitCmd.Flags().String("image-registry", "", "Custom/private docker image repository URL")
186196
InitCmd.Flags().StringVarP(&containerRuntime, "container-runtime", "", "docker", "The container runtime to use. Supported values are docker (default) and podman")
197+
187198
RootCmd.AddCommand(InitCmd)
188199
}

cmd/run.go

+56-13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/dapr/cli/pkg/metadata"
2929
"github.com/dapr/cli/pkg/print"
3030
"github.com/dapr/cli/pkg/standalone"
31+
"github.com/dapr/cli/pkg/standalone/runfileconfig"
3132
"github.com/dapr/cli/utils"
3233
)
3334

@@ -57,6 +58,7 @@ var (
5758
appHealthThreshold int
5859
enableAPILogging bool
5960
apiListenAddresses string
61+
runFilePath string
6062
)
6163

6264
const (
@@ -84,16 +86,39 @@ dapr run --app-id myapp
8486
8587
# Run a gRPC application written in Go (listening on port 3000)
8688
dapr run --app-id myapp --app-port 3000 --app-protocol grpc -- go run main.go
89+
90+
# Run sidecar only specifying dapr runtime installation directory
91+
dapr run --app-id myapp --dapr-path /usr/local/dapr
8792
`,
8893
Args: cobra.MinimumNArgs(0),
8994
PreRun: func(cmd *cobra.Command, args []string) {
9095
viper.BindPFlag("placement-host-address", cmd.Flags().Lookup("placement-host-address"))
9196
},
9297
Run: func(cmd *cobra.Command, args []string) {
98+
if len(runFilePath) > 0 {
99+
executeRunWithAppsConfigFile(runFilePath)
100+
return
101+
}
93102
if len(args) == 0 {
94103
fmt.Println(print.WhiteBold("WARNING: no application command found."))
95104
}
96105

106+
daprDirPath, err := standalone.GetDaprPath(daprPath)
107+
if err != nil {
108+
print.FailureStatusEvent(os.Stderr, "Failed to get Dapr install directory: %v", err)
109+
os.Exit(1)
110+
}
111+
112+
// Fallback to default config file if not specified.
113+
if configFile == "" {
114+
configFile = standalone.GetDaprConfigPath(daprDirPath)
115+
}
116+
117+
// Fallback to default components directory if not specified.
118+
if componentsPath == "" {
119+
componentsPath = standalone.GetResourcesDir(daprDirPath)
120+
}
121+
97122
if unixDomainSocket != "" {
98123
// TODO(@daixiang0): add Windows support.
99124
if runtime.GOOS == "windows" {
@@ -107,34 +132,38 @@ dapr run --app-id myapp --app-port 3000 --app-protocol grpc -- go run main.go
107132
}
108133
}
109134

110-
output, err := standalone.Run(&standalone.RunConfig{
111-
AppID: appID,
112-
AppPort: appPort,
113-
HTTPPort: port,
114-
GRPCPort: grpcPort,
135+
sharedRunConfig := &standalone.SharedRunConfig{
115136
ConfigFile: configFile,
116-
Arguments: args,
117137
EnableProfiling: enableProfiling,
118-
ProfilePort: profilePort,
119138
LogLevel: logLevel,
120139
MaxConcurrency: maxConcurrency,
121-
Protocol: protocol,
140+
AppProtocol: protocol,
122141
PlacementHostAddr: viper.GetString("placement-host-address"),
123142
ComponentsPath: componentsPath,
124143
ResourcesPath: resourcesPath,
125144
AppSSL: appSSL,
126-
MetricsPort: metricsPort,
127145
MaxRequestBodySize: maxRequestBodySize,
128146
HTTPReadBufferSize: readBufferSize,
129-
UnixDomainSocket: unixDomainSocket,
130147
EnableAppHealth: enableAppHealth,
131148
AppHealthPath: appHealthPath,
132149
AppHealthInterval: appHealthInterval,
133150
AppHealthTimeout: appHealthTimeout,
134151
AppHealthThreshold: appHealthThreshold,
135152
EnableAPILogging: enableAPILogging,
136-
InternalGRPCPort: internalGRPCPort,
137153
APIListenAddresses: apiListenAddresses,
154+
}
155+
output, err := standalone.Run(&standalone.RunConfig{
156+
AppID: appID,
157+
AppPort: appPort,
158+
HTTPPort: port,
159+
GRPCPort: grpcPort,
160+
ProfilePort: profilePort,
161+
Command: args,
162+
MetricsPort: metricsPort,
163+
UnixDomainSocket: unixDomainSocket,
164+
InternalGRPCPort: internalGRPCPort,
165+
DaprPathCmdFlag: daprPath,
166+
SharedRunConfig: *sharedRunConfig,
138167
})
139168
if err != nil {
140169
print.FailureStatusEvent(os.Stderr, err.Error())
@@ -368,7 +397,7 @@ dapr run --app-id myapp --app-port 3000 --app-protocol grpc -- go run main.go
368397
func init() {
369398
RunCmd.Flags().IntVarP(&appPort, "app-port", "p", -1, "The port your application is listening on")
370399
RunCmd.Flags().StringVarP(&appID, "app-id", "a", "", "The id for your application, used for service discovery")
371-
RunCmd.Flags().StringVarP(&configFile, "config", "c", standalone.DefaultConfigFilePath(), "Dapr configuration file")
400+
RunCmd.Flags().StringVarP(&configFile, "config", "c", "", "Dapr configuration file")
372401
RunCmd.Flags().IntVarP(&port, "dapr-http-port", "H", -1, "The HTTP port for Dapr to listen on")
373402
RunCmd.Flags().IntVarP(&grpcPort, "dapr-grpc-port", "G", -1, "The gRPC port for Dapr to listen on")
374403
RunCmd.Flags().IntVarP(&internalGRPCPort, "dapr-internal-grpc-port", "I", -1, "The gRPC port for the Dapr internal API to listen on")
@@ -377,7 +406,7 @@ func init() {
377406
RunCmd.Flags().StringVarP(&logLevel, "log-level", "", "info", "The log verbosity. Valid values are: debug, info, warn, error, fatal, or panic")
378407
RunCmd.Flags().IntVarP(&maxConcurrency, "app-max-concurrency", "", -1, "The concurrency level of the application, otherwise is unlimited")
379408
RunCmd.Flags().StringVarP(&protocol, "app-protocol", "P", "http", "The protocol (gRPC or HTTP) Dapr uses to talk to the application")
380-
RunCmd.Flags().StringVarP(&componentsPath, "components-path", "d", standalone.GetResourcesDir(), "The path for resources directory")
409+
RunCmd.Flags().StringVarP(&componentsPath, "components-path", "d", "", "The path for components directory")
381410
RunCmd.Flags().StringVarP(&resourcesPath, "resources-path", "", "", "The path for resources directory")
382411
// TODO: Remove below line once the flag is removed in the future releases.
383412
// 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.
@@ -396,5 +425,19 @@ func init() {
396425
RunCmd.Flags().IntVar(&appHealthThreshold, "app-health-threshold", 0, "Number of consecutive failures for the app to be considered unhealthy")
397426
RunCmd.Flags().BoolVar(&enableAPILogging, "enable-api-logging", false, "Log API calls at INFO verbosity. Valid values are: true or false")
398427
RunCmd.Flags().StringVar(&apiListenAddresses, "dapr-listen-addresses", "", "Comma separated list of IP addresses that sidecar will listen to")
428+
RunCmd.Flags().StringVarP(&runFilePath, "run-file", "f", "", "Path to the configuration file for the apps to run")
399429
RootCmd.AddCommand(RunCmd)
400430
}
431+
432+
func executeRunWithAppsConfigFile(runFilePath string) {
433+
config := runfileconfig.RunFileConfig{}
434+
apps, err := config.GetApps(runFilePath)
435+
if err != nil {
436+
print.FailureStatusEvent(os.Stdout, fmt.Sprintf("Error getting apps from config file: %s", err))
437+
os.Exit(1)
438+
}
439+
if len(apps) == 0 {
440+
print.FailureStatusEvent(os.Stdout, "No apps to run")
441+
os.Exit(1)
442+
}
443+
}

cmd/uninstall.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package cmd
1616
import (
1717
"fmt"
1818
"os"
19+
"strings"
1920

2021
"github.com/spf13/cobra"
2122
"github.com/spf13/viper"
@@ -46,6 +47,9 @@ dapr uninstall --all
4647
4748
# Uninstall from Kubernetes
4849
dapr uninstall -k
50+
51+
# Uninstall Dapr from non-default install directory (default is $HOME/.dapr)
52+
dapr uninstall --dapr-path <path-to-install-directory>
4953
`,
5054
PreRun: func(cmd *cobra.Command, args []string) {
5155
viper.BindPFlag("network", cmd.Flags().Lookup("network"))
@@ -55,6 +59,11 @@ dapr uninstall -k
5559
var err error
5660

5761
if uninstallKubernetes {
62+
if len(strings.TrimSpace(daprPath)) != 0 {
63+
print.FailureStatusEvent(os.Stderr, "--dapr-path is only valid for self-hosted mode")
64+
os.Exit(1)
65+
}
66+
5867
print.InfoStatusEvent(os.Stdout, "Removing Dapr from your cluster...")
5968
err = kubernetes.Uninstall(uninstallNamespace, uninstallAll, timeout)
6069
} else {
@@ -64,7 +73,7 @@ dapr uninstall -k
6473
}
6574
print.InfoStatusEvent(os.Stdout, "Removing Dapr from your machine...")
6675
dockerNetwork := viper.GetString("network")
67-
err = standalone.Uninstall(uninstallAll, dockerNetwork, uninstallContainerRuntime)
76+
err = standalone.Uninstall(uninstallAll, dockerNetwork, uninstallContainerRuntime, daprPath)
6877
}
6978

7079
if err != nil {

0 commit comments

Comments
 (0)