Skip to content

Commit

Permalink
merge master and fix conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Pravin Pushkar <[email protected]>
  • Loading branch information
pravinpushkar committed Jan 3, 2023
2 parents 771b256 + c1f9627 commit c5646d4
Show file tree
Hide file tree
Showing 34 changed files with 1,233 additions and 161 deletions.
1 change: 1 addition & 0 deletions .github/workflows/self_hosted_e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ jobs:
env:
DAPR_E2E_INIT_SLIM: ${{ contains(matrix.os, 'windows-latest') || contains(matrix.dapr_install_mode, 'slim') }}
CONTAINER_RUNTIME: ${{ env.CONTAINER_RUNTIME }}
E2E_SH_TEST_TIMEOUT: ${{ env.E2E_SH_TEST_TIMEOUT }}
run: |
export TEST_OUTPUT_FILE=$GITHUB_WORKSPACE/test-e2e-standalone.json
echo "TEST_OUTPUT_FILE=$TEST_OUTPUT_FILE" >> $GITHUB_ENV
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ export GOOS ?= $(TARGET_OS_LOCAL)
export BINARY_EXT ?= $(BINARY_EXT_LOCAL)

TEST_OUTPUT_FILE ?= test_output.json
E2E_SH_TEST_TIMEOUT ?= 10m

# Set the default timeout for tests to 10 minutes
ifndef E2E_SH_TEST_TIMEOUT
override E2E_SH_TEST_TIMEOUT := 10m
endif

# Use the variable H to add a header (equivalent to =>) to informational output
H = $(shell printf "\033[34;1m=>\033[0m")
Expand Down
9 changes: 8 additions & 1 deletion cmd/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/dapr/cli/pkg/print"
"github.com/dapr/cli/pkg/standalone"
)

Expand All @@ -29,7 +31,12 @@ var BuildInfoCmd = &cobra.Command{
dapr build-info
`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(standalone.GetBuildInfo(RootCmd.Version))
out, err := standalone.GetBuildInfo(daprPath, RootCmd.Version)
if err != nil {
print.FailureStatusEvent(os.Stderr, "Error getting build info: %s", err.Error())
os.Exit(1)
}
fmt.Println(out)
},
}

Expand Down
7 changes: 6 additions & 1 deletion cmd/dapr.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,20 @@ type daprVersion struct {
var (
daprVer daprVersion
logAsJSON bool
daprPath string
)

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

// err intentionally ignored since daprd may not yet be installed.
runtimeVer, _ := standalone.GetRuntimeVersion(daprPath)

daprVer = daprVersion{
CliVersion: version,
RuntimeVersion: strings.ReplaceAll(standalone.GetRuntimeVersion(), "\n", ""),
RuntimeVersion: strings.ReplaceAll(runtimeVer, "\n", ""),
}

cobra.OnInitialize(initConfig)
Expand Down Expand Up @@ -87,5 +91,6 @@ func initConfig() {
}

func init() {
RootCmd.PersistentFlags().StringVarP(&daprPath, "dapr-path", "", "", "The path to the dapr installation directory")
RootCmd.PersistentFlags().BoolVarP(&logAsJSON, "log-as-json", "", false, "Log output in JSON format")
}
18 changes: 15 additions & 3 deletions cmd/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ dapr dashboard -k -p 0
`,
Run: func(cmd *cobra.Command, args []string) {
if dashboardVersionCmd {
fmt.Println(standalone.GetDashboardVersion())
dashboardVer, err := standalone.GetDashboardVersion(daprPath)
if err != nil {
print.FailureStatusEvent(os.Stderr, "Failed to get Dapr install directory: %v", err)
os.Exit(1)
}

fmt.Println(dashboardVer)
os.Exit(0)
}

Expand Down Expand Up @@ -179,9 +185,14 @@ dapr dashboard -k -p 0
<-portForward.GetStop()
} else {
// Standalone mode.
err := standalone.NewDashboardCmd(dashboardLocalPort).Run()
dashboardCmd, err := standalone.NewDashboardCmd(daprPath, dashboardLocalPort)
if err != nil {
print.FailureStatusEvent(os.Stderr, "Dapr dashboard not found. Is Dapr installed?")
print.FailureStatusEvent(os.Stderr, "Failed to get Dapr install directory: %v", err)
} else {
err = dashboardCmd.Run()
if err != nil {
print.FailureStatusEvent(os.Stderr, "Dapr dashboard failed to run: %v", err)
}
}
}
},
Expand All @@ -199,5 +210,6 @@ func init() {
DashboardCmd.Flags().IntVarP(&dashboardLocalPort, "port", "p", defaultLocalPort, "The local port on which to serve Dapr dashboard")
DashboardCmd.Flags().StringVarP(&dashboardNamespace, "namespace", "n", daprSystemNamespace, "The namespace where Dapr dashboard is running")
DashboardCmd.Flags().BoolP("help", "h", false, "Print this help message")

RootCmd.AddCommand(DashboardCmd)
}
13 changes: 12 additions & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ dapr init --from-dir <path-to-directory>
# Initialize dapr with a particular image variant. Allowed values: "mariner"
dapr init --image-variant <variant>
# Initialize Dapr to non-default install directory (default is $HOME/.dapr)
dapr init --dapr-path <path-to-install-directory>
# See more at: https://docs.dapr.io/getting-started/
`,
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -92,6 +95,11 @@ dapr init --image-variant <variant>
imageRegistryURI := ""
var err error

if len(strings.TrimSpace(daprPath)) != 0 {
print.FailureStatusEvent(os.Stderr, "--dapr-path is only valid for self-hosted mode")
os.Exit(1)
}

if len(imageRegistryFlag) != 0 {
warnForPrivateRegFeat()
imageRegistryURI = imageRegistryFlag
Expand Down Expand Up @@ -137,11 +145,12 @@ dapr init --image-variant <variant>
if len(imageRegistryURI) != 0 {
warnForPrivateRegFeat()
}

if !utils.IsValidContainerRuntime(containerRuntime) {
print.FailureStatusEvent(os.Stdout, "Invalid container runtime. Supported values are docker and podman.")
os.Exit(1)
}
err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir, containerRuntime, imageVariant)
err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir, containerRuntime, imageVariant, daprPath)
if err != nil {
print.FailureStatusEvent(os.Stderr, err.Error())
os.Exit(1)
Expand All @@ -168,6 +177,7 @@ func init() {
if dashboardVersionEnv != "" {
defaultDashboardVersion = dashboardVersionEnv
}

InitCmd.Flags().BoolVarP(&kubernetesMode, "kubernetes", "k", false, "Deploy Dapr to a Kubernetes cluster")
InitCmd.Flags().BoolVarP(&wait, "wait", "", false, "Wait for Kubernetes initialization to complete")
InitCmd.Flags().UintVarP(&timeout, "timeout", "", 300, "The wait timeout for the Kubernetes installation")
Expand All @@ -184,5 +194,6 @@ func init() {
InitCmd.Flags().StringArrayVar(&values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
InitCmd.Flags().String("image-registry", "", "Custom/private docker image repository URL")
InitCmd.Flags().StringVarP(&containerRuntime, "container-runtime", "", "docker", "The container runtime to use. Supported values are docker (default) and podman")

RootCmd.AddCommand(InitCmd)
}
69 changes: 56 additions & 13 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/dapr/cli/pkg/metadata"
"github.com/dapr/cli/pkg/print"
"github.com/dapr/cli/pkg/standalone"
"github.com/dapr/cli/pkg/standalone/runfileconfig"
"github.com/dapr/cli/utils"
)

Expand Down Expand Up @@ -57,6 +58,7 @@ var (
appHealthThreshold int
enableAPILogging bool
apiListenAddresses string
runFilePath string
)

const (
Expand Down Expand Up @@ -84,16 +86,39 @@ dapr run --app-id myapp
# Run a gRPC application written in Go (listening on port 3000)
dapr run --app-id myapp --app-port 3000 --app-protocol grpc -- go run main.go
# Run sidecar only specifying dapr runtime installation directory
dapr run --app-id myapp --dapr-path /usr/local/dapr
`,
Args: cobra.MinimumNArgs(0),
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlag("placement-host-address", cmd.Flags().Lookup("placement-host-address"))
},
Run: func(cmd *cobra.Command, args []string) {
if len(runFilePath) > 0 {
executeRunWithAppsConfigFile(runFilePath)
return
}
if len(args) == 0 {
fmt.Println(print.WhiteBold("WARNING: no application command found."))
}

daprDirPath, err := standalone.GetDaprPath(daprPath)
if err != nil {
print.FailureStatusEvent(os.Stderr, "Failed to get Dapr install directory: %v", err)
os.Exit(1)
}

// Fallback to default config file if not specified.
if configFile == "" {
configFile = standalone.GetDaprConfigPath(daprDirPath)
}

// Fallback to default components directory if not specified.
if componentsPath == "" {
componentsPath = standalone.GetResourcesDir(daprDirPath)
}

if unixDomainSocket != "" {
// TODO(@daixiang0): add Windows support.
if runtime.GOOS == "windows" {
Expand All @@ -107,34 +132,38 @@ dapr run --app-id myapp --app-port 3000 --app-protocol grpc -- go run main.go
}
}

output, err := standalone.Run(&standalone.RunConfig{
AppID: appID,
AppPort: appPort,
HTTPPort: port,
GRPCPort: grpcPort,
sharedRunConfig := &standalone.SharedRunConfig{
ConfigFile: configFile,
Arguments: args,
EnableProfiling: enableProfiling,
ProfilePort: profilePort,
LogLevel: logLevel,
MaxConcurrency: maxConcurrency,
Protocol: protocol,
AppProtocol: protocol,
PlacementHostAddr: viper.GetString("placement-host-address"),
ComponentsPath: componentsPath,
ResourcesPath: resourcesPath,
AppSSL: appSSL,
MetricsPort: metricsPort,
MaxRequestBodySize: maxRequestBodySize,
HTTPReadBufferSize: readBufferSize,
UnixDomainSocket: unixDomainSocket,
EnableAppHealth: enableAppHealth,
AppHealthPath: appHealthPath,
AppHealthInterval: appHealthInterval,
AppHealthTimeout: appHealthTimeout,
AppHealthThreshold: appHealthThreshold,
EnableAPILogging: enableAPILogging,
InternalGRPCPort: internalGRPCPort,
APIListenAddresses: apiListenAddresses,
}
output, err := standalone.Run(&standalone.RunConfig{
AppID: appID,
AppPort: appPort,
HTTPPort: port,
GRPCPort: grpcPort,
ProfilePort: profilePort,
Command: args,
MetricsPort: metricsPort,
UnixDomainSocket: unixDomainSocket,
InternalGRPCPort: internalGRPCPort,
DaprPathCmdFlag: daprPath,
SharedRunConfig: *sharedRunConfig,
})
if err != nil {
print.FailureStatusEvent(os.Stderr, err.Error())
Expand Down Expand Up @@ -368,7 +397,7 @@ dapr run --app-id myapp --app-port 3000 --app-protocol grpc -- go run main.go
func init() {
RunCmd.Flags().IntVarP(&appPort, "app-port", "p", -1, "The port your application is listening on")
RunCmd.Flags().StringVarP(&appID, "app-id", "a", "", "The id for your application, used for service discovery")
RunCmd.Flags().StringVarP(&configFile, "config", "c", standalone.DefaultConfigFilePath(), "Dapr configuration file")
RunCmd.Flags().StringVarP(&configFile, "config", "c", "", "Dapr configuration file")
RunCmd.Flags().IntVarP(&port, "dapr-http-port", "H", -1, "The HTTP port for Dapr to listen on")
RunCmd.Flags().IntVarP(&grpcPort, "dapr-grpc-port", "G", -1, "The gRPC port for Dapr to listen on")
RunCmd.Flags().IntVarP(&internalGRPCPort, "dapr-internal-grpc-port", "I", -1, "The gRPC port for the Dapr internal API to listen on")
Expand All @@ -377,7 +406,7 @@ func init() {
RunCmd.Flags().StringVarP(&logLevel, "log-level", "", "info", "The log verbosity. Valid values are: debug, info, warn, error, fatal, or panic")
RunCmd.Flags().IntVarP(&maxConcurrency, "app-max-concurrency", "", -1, "The concurrency level of the application, otherwise is unlimited")
RunCmd.Flags().StringVarP(&protocol, "app-protocol", "P", "http", "The protocol (gRPC or HTTP) Dapr uses to talk to the application")
RunCmd.Flags().StringVarP(&componentsPath, "components-path", "d", standalone.GetResourcesDir(), "The path for resources directory")
RunCmd.Flags().StringVarP(&componentsPath, "components-path", "d", "", "The path for components directory")
RunCmd.Flags().StringVarP(&resourcesPath, "resources-path", "", "", "The path for resources directory")
// TODO: Remove below line once the flag is removed in the future releases.
// 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.
Expand All @@ -396,5 +425,19 @@ func init() {
RunCmd.Flags().IntVar(&appHealthThreshold, "app-health-threshold", 0, "Number of consecutive failures for the app to be considered unhealthy")
RunCmd.Flags().BoolVar(&enableAPILogging, "enable-api-logging", false, "Log API calls at INFO verbosity. Valid values are: true or false")
RunCmd.Flags().StringVar(&apiListenAddresses, "dapr-listen-addresses", "", "Comma separated list of IP addresses that sidecar will listen to")
RunCmd.Flags().StringVarP(&runFilePath, "run-file", "f", "", "Path to the configuration file for the apps to run")
RootCmd.AddCommand(RunCmd)
}

func executeRunWithAppsConfigFile(runFilePath string) {
config := runfileconfig.RunFileConfig{}
apps, err := config.GetApps(runFilePath)
if err != nil {
print.FailureStatusEvent(os.Stdout, fmt.Sprintf("Error getting apps from config file: %s", err))
os.Exit(1)
}
if len(apps) == 0 {
print.FailureStatusEvent(os.Stdout, "No apps to run")
os.Exit(1)
}
}
11 changes: 10 additions & 1 deletion cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cmd
import (
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -46,6 +47,9 @@ dapr uninstall --all
# Uninstall from Kubernetes
dapr uninstall -k
# Uninstall Dapr from non-default install directory (default is $HOME/.dapr)
dapr uninstall --dapr-path <path-to-install-directory>
`,
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlag("network", cmd.Flags().Lookup("network"))
Expand All @@ -55,6 +59,11 @@ dapr uninstall -k
var err error

if uninstallKubernetes {
if len(strings.TrimSpace(daprPath)) != 0 {
print.FailureStatusEvent(os.Stderr, "--dapr-path is only valid for self-hosted mode")
os.Exit(1)
}

print.InfoStatusEvent(os.Stdout, "Removing Dapr from your cluster...")
err = kubernetes.Uninstall(uninstallNamespace, uninstallAll, timeout)
} else {
Expand All @@ -64,7 +73,7 @@ dapr uninstall -k
}
print.InfoStatusEvent(os.Stdout, "Removing Dapr from your machine...")
dockerNetwork := viper.GetString("network")
err = standalone.Uninstall(uninstallAll, dockerNetwork, uninstallContainerRuntime)
err = standalone.Uninstall(uninstallAll, dockerNetwork, uninstallContainerRuntime, daprPath)
}

if err != nil {
Expand Down
Loading

0 comments on commit c5646d4

Please sign in to comment.