mirror of https://github.com/dapr/cli.git
Change init and uninstall behavior for self hosted mode (#413)
* remove install-path option for dapr init copy bianries under $HOME/.dapr/bin
This commit is contained in:
parent
94396d6bfe
commit
2a4123efaf
20
README.md
20
README.md
|
@ -62,20 +62,20 @@ In self-hosted mode, dapr can be initialized using the CLI with the placement,
|
|||
#### Initialize Dapr
|
||||
([Prerequisite](#Prerequisites): Docker is available in the environment - recommended)
|
||||
|
||||
Use the init command to initialize Dapr. On init, multiple default configuration files and containers are installed along with the dapr runtime binary.
|
||||
Use the init command to initialize Dapr. On init, multiple default configuration files and containers are installed along with the dapr runtime binary. Dapr runtime binary is installed under $HOME/.dapr/bin for Mac, Linux and %USERPROFILE%\.dapr\bin for Windows.
|
||||
|
||||
```bash
|
||||
dapr init
|
||||
```
|
||||
|
||||
> For Linux users, if you run your docker cmds with sudo or the install path is `/usr/local/bin`(default install path), you need to use "**sudo dapr init**"
|
||||
> For Linux users, if you run your docker cmds with sudo, you need to use "**sudo dapr init**"
|
||||
|
||||
Output should look like so:
|
||||
|
||||
```
|
||||
⌛ Making the jump to hyperspace...
|
||||
✅ Downloaded binaries and completed components set up.
|
||||
ℹ️ daprd binary has been installed to /usr/local/bin.
|
||||
ℹ️ daprd binary has been installed to $HOME/.dapr/bin.
|
||||
ℹ️ dapr_placement container is running.
|
||||
ℹ️ dapr_redis container is running.
|
||||
ℹ️ dapr_zipkin container is running.
|
||||
|
@ -103,7 +103,7 @@ Output should look like so:
|
|||
```bash
|
||||
⌛ Making the jump to hyperspace...
|
||||
✅ Downloaded binaries and completed components set up.
|
||||
ℹ️ daprd binary has been installed to /usr/local/bin.
|
||||
ℹ️ daprd binary has been installed to $HOME/.dapr/bin.
|
||||
ℹ️ placement binary has been installed.
|
||||
✅ Success! Dapr is up and running. To get started, go here: https://aka.ms/dapr-getting-started
|
||||
```
|
||||
|
@ -146,13 +146,13 @@ $ dapr init --redis-host 10.0.0.1
|
|||
|
||||
### Uninstall Dapr in a standalone mode
|
||||
|
||||
Uninstalling will remove the placement container if installed with Docker or the placement binary if not, and the daprd binary installed in either the provided `--install-path` on `dapr init` or the default path `/usr/local/bin` for Linux/MacOS or `C:\dapr` for Windows.
|
||||
Uninstalling will remove daprd binary and the placement container (if installed with Docker or the placement binary if not).
|
||||
|
||||
|
||||
```bash
|
||||
$ dapr uninstall
|
||||
```
|
||||
> For Linux users, if you run your docker cmds with sudo or the install path is `/usr/local/bin`(default install path), you need to use "**sudo dapr uninstall**" to remove dapr binaries and/or the containers.
|
||||
> For Linux users, if you run your docker cmds with sudo, you need to use "**sudo dapr uninstall**" to remove the containers.
|
||||
|
||||
The command above won't remove the redis or zipkin containers by default in case you were using it for other purposes. It will also not remove the default dapr folder that was created on `dapr init`. To remove all the containers (placement, redis, zipkin) and also the default dapr folder created on init run:
|
||||
|
||||
|
@ -166,14 +166,6 @@ The above command can also be run when Dapr has been installed in a non-docker e
|
|||
|
||||
**You should always run a `dapr uninstall` before running another `dapr init`.**
|
||||
|
||||
#### Uninstall Dapr from a specific install path
|
||||
|
||||
If previously installed to a specific location for eg: `~/dapr_bin`, Dapr can be unsintalled with the `--install-path` argument
|
||||
|
||||
```bash
|
||||
dapr uninstall --install-path ~/dapr_bin
|
||||
```
|
||||
|
||||
#### Uninstall Dapr from a specific Docker network
|
||||
|
||||
If previously installed to a specific Docker network, Dapr can be uninstalled with the `--network` argument:
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/dapr/cli/pkg/api"
|
||||
"github.com/dapr/cli/pkg/version"
|
||||
"github.com/dapr/cli/pkg/standalone"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
@ -47,7 +47,7 @@ func Execute(version, apiVersion string) {
|
|||
}
|
||||
|
||||
func setVersion() {
|
||||
template := fmt.Sprintf("CLI version: %s \nRuntime version: %s", RootCmd.Version, version.GetRuntimeVersion())
|
||||
template := fmt.Sprintf("CLI version: %s \nRuntime version: %s", RootCmd.Version, standalone.GetRuntimeVersion())
|
||||
RootCmd.SetVersionTemplate(template)
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ var InitCmd = &cobra.Command{
|
|||
Run: func(cmd *cobra.Command, args []string) {
|
||||
print.PendingStatusEvent(os.Stdout, "Making the jump to hyperspace...")
|
||||
|
||||
installLocation := viper.GetString("install-path")
|
||||
if kubernetesMode {
|
||||
print.InfoStatusEvent(os.Stdout, "Note: this installation is recommended for testing purposes. For production environments, please use Helm \n")
|
||||
err := kubernetes.Init(runtimeVersion)
|
||||
|
@ -46,7 +45,7 @@ var InitCmd = &cobra.Command{
|
|||
dockerNetwork = viper.GetString("network")
|
||||
}
|
||||
redisHost := viper.GetString("redis-host")
|
||||
err := standalone.Init(runtimeVersion, dockerNetwork, installLocation, redisHost, slimMode)
|
||||
err := standalone.Init(runtimeVersion, dockerNetwork, redisHost, slimMode)
|
||||
if err != nil {
|
||||
print.FailureStatusEvent(os.Stdout, err.Error())
|
||||
return
|
||||
|
@ -61,7 +60,6 @@ func init() {
|
|||
InitCmd.Flags().BoolVarP(&slimMode, "slim", "s", false, "Initialize dapr in self-hosted mode without placement, redis and zipkin containers.")
|
||||
InitCmd.Flags().StringVarP(&runtimeVersion, "runtime-version", "", "latest", "The version of the Dapr runtime to install. for example: v0.1.0")
|
||||
InitCmd.Flags().String("network", "", "The Docker network on which to deploy the Dapr runtime")
|
||||
InitCmd.Flags().String("install-path", "", "The optional location to install Daprd binary to. The default is /usr/local/bin for Linux/Mac and C:\\dapr for Windows")
|
||||
InitCmd.Flags().String("redis-host", "localhost", "The host on which the Redis service resides")
|
||||
|
||||
RootCmd.AddCommand(InitCmd)
|
||||
|
|
|
@ -38,8 +38,7 @@ var UninstallCmd = &cobra.Command{
|
|||
} else {
|
||||
print.InfoStatusEvent(os.Stdout, "Removing Dapr from your machine...")
|
||||
dockerNetwork := viper.GetString("network")
|
||||
installLocation := viper.GetString("install-path")
|
||||
err = standalone.Uninstall(uninstallAll, installLocation, dockerNetwork)
|
||||
err = standalone.Uninstall(uninstallAll, dockerNetwork)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
@ -52,8 +51,7 @@ var UninstallCmd = &cobra.Command{
|
|||
|
||||
func init() {
|
||||
UninstallCmd.Flags().BoolVarP(&uninstallKubernetes, "kubernetes", "k", false, "Uninstall Dapr from a Kubernetes cluster")
|
||||
UninstallCmd.Flags().BoolVar(&uninstallAll, "all", false, "Remove Redis container in addition to actor placement container")
|
||||
UninstallCmd.Flags().String("install-path", "", "The optional location to uninstall Daprd binary from. The default is /usr/local/bin for Linux/Mac and C:\\dapr for Windows")
|
||||
UninstallCmd.Flags().BoolVar(&uninstallAll, "all", false, "Removes .dapr directory, Redis, Placement and Zipkin containers")
|
||||
UninstallCmd.Flags().String("network", "", "The Docker network from which to remove the Dapr runtime")
|
||||
UninstallCmd.Flags().StringVarP(&uninstallVersion, "runtime-version", "", "latest", "The version of the Dapr runtime to uninstall. for example: v0.1.0 (Kubernetes mode only)")
|
||||
RootCmd.AddCommand(UninstallCmd)
|
||||
|
|
|
@ -15,10 +15,8 @@ dapr init [flags]
|
|||
| Name | Environment Variable | Default | Description
|
||||
| --- | --- | --- | --- |
|
||||
| `--help`, `-h` | | | Help for init |
|
||||
| `--install-path` | `DAPR_INSTALL_PATH` | `Linux & Mac: /usr/local/bin` `Windows: C:\dapr` | The optional location to install Dapr to. The default is /usr/local/bin for Linux/Mac and C:\dapr for Windows |
|
||||
| `--kubernetes`, `-k` | | `false` | Deploy Dapr to a Kubernetes cluster |
|
||||
| `--network` | `DAPR_NETWORK` | | The Docker network on which to deploy the Dapr runtime |
|
||||
| `--runtime-version` | | `latest` | The version of the Dapr runtime to install, for example: `v0.1.0-alpha` |
|
||||
| `--redis-host` | `DAPR_REDIS_HOST` | `localhost` | The host on which the Redis service resides |
|
||||
| `--install-path` | | `/usr/local/bin` for Linux/Mac and `C:\dapr` for Windows | The optional location to install Dapr to. |
|
||||
| `--slim`, `-s` | | `false` | Initialize dapr in self-hosted mode without placement, redis and zipkin containers.|
|
||||
|
|
|
@ -19,4 +19,3 @@ dapr uninstall [flags]
|
|||
| `--kubernetes`, `-k` | | `false` | Uninstall Dapr from a Kubernetes cluster |
|
||||
| `--network` | `DAPR_NETWORK` | | The Docker network from which to remove the Dapr runtime |
|
||||
| `--runtime-version` | | `latest` | The version of the Dapr runtime to uninstall, for example: `v0.1.0-alpha` (Kubernetes mode only) |
|
||||
| `--install-path` | | `/usr/local/bin` for Linux/Mac and `C:\dapr` for Windows | The optional location to uninstall Dapr from. Use if provided during `dapr init`|
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
// ------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
package standalone
|
||||
|
||||
import (
|
||||
|
@ -8,40 +13,22 @@ import (
|
|||
|
||||
const (
|
||||
defaultDaprDirName = ".dapr"
|
||||
defaultDaprBinDirName = "bin"
|
||||
defaultComponentsDirName = "components"
|
||||
defaultConfigFileName = "config.yaml"
|
||||
)
|
||||
|
||||
func homeFolder() string {
|
||||
homePath := os.Getenv("HOME")
|
||||
if runtime.GOOS == daprWindowsOS {
|
||||
homePath = os.Getenv("USERPROFILE")
|
||||
}
|
||||
return homePath
|
||||
func defaultDaprDirPath() string {
|
||||
homeDir, _ := os.UserHomeDir()
|
||||
return path_filepath.Join(homeDir, defaultDaprDirName)
|
||||
}
|
||||
|
||||
// DefaultFolderPath returns the default requested path to the requested path
|
||||
func defaultFolderPath(dirName string) string {
|
||||
homePath := homeFolder()
|
||||
if dirName == defaultDaprDirName {
|
||||
return path_filepath.Join(homePath, defaultDaprDirName)
|
||||
}
|
||||
return path_filepath.Join(homePath, defaultDaprDirName, dirName)
|
||||
func defaultDaprBinPath() string {
|
||||
return path_filepath.Join(defaultDaprDirPath(), defaultDaprBinDirName)
|
||||
}
|
||||
|
||||
func binaryInstallationPath(installLocation string) string {
|
||||
if installLocation != "" {
|
||||
return installLocation
|
||||
}
|
||||
if runtime.GOOS == daprWindowsOS {
|
||||
return daprDefaultWindowsInstallPath
|
||||
}
|
||||
return daprDefaultLinuxAndMacInstallPath
|
||||
}
|
||||
|
||||
func binaryFilePath(binaryFilePrefix, installLocation string) string {
|
||||
destDir := binaryInstallationPath(installLocation)
|
||||
binaryPath := path_filepath.Join(destDir, binaryFilePrefix)
|
||||
func binaryFilePath(binaryDir string, binaryFilePrefix string) string {
|
||||
binaryPath := path_filepath.Join(binaryDir, binaryFilePrefix)
|
||||
if runtime.GOOS == daprWindowsOS {
|
||||
binaryPath += ".exe"
|
||||
}
|
||||
|
@ -49,11 +36,9 @@ func binaryFilePath(binaryFilePrefix, installLocation string) string {
|
|||
}
|
||||
|
||||
func DefaultComponentsDirPath() string {
|
||||
return defaultFolderPath(defaultComponentsDirName)
|
||||
return path_filepath.Join(defaultDaprDirPath(), defaultComponentsDirName)
|
||||
}
|
||||
|
||||
func DefaultConfigFilePath() string {
|
||||
configPath := defaultFolderPath(defaultDaprDirName)
|
||||
filePath := path_filepath.Join(configPath, defaultConfigFileName)
|
||||
return filePath
|
||||
return path_filepath.Join(defaultDaprDirPath(), defaultConfigFileName)
|
||||
}
|
||||
|
|
|
@ -73,11 +73,7 @@ func getDaprCommand(appID string, daprHTTPPort int, daprGRPCPort int, appPort in
|
|||
maxConcurrency = -1
|
||||
}
|
||||
|
||||
daprCMD := "daprd"
|
||||
if runtime.GOOS == daprWindowsOS {
|
||||
daprCMD = fmt.Sprintf("%s.exe", daprCMD)
|
||||
}
|
||||
|
||||
daprCMD := binaryFilePath(defaultDaprBinPath(), "daprd")
|
||||
metricsPort, err := freeport.GetFreePort()
|
||||
if err != nil {
|
||||
return nil, -1, -1, -1, err
|
||||
|
|
|
@ -35,7 +35,8 @@ func setupRun(t *testing.T) {
|
|||
configFile := DefaultConfigFilePath()
|
||||
err := os.MkdirAll(componentsDir, 0700)
|
||||
assert.Equal(t, nil, err, "Unable to setup components dir before running test")
|
||||
_, err = os.Create(configFile)
|
||||
file, err := os.Create(configFile)
|
||||
file.Close()
|
||||
assert.Equal(t, nil, err, "Unable to create config file before running test")
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"path"
|
||||
path_filepath "path/filepath"
|
||||
"runtime"
|
||||
|
@ -24,27 +23,25 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/briandowns/spinner"
|
||||
"github.com/dapr/cli/pkg/print"
|
||||
cli_ver "github.com/dapr/cli/pkg/version"
|
||||
"github.com/dapr/cli/utils"
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
const (
|
||||
daprDockerImageName = "daprio/dapr"
|
||||
daprRuntimeFilePrefix = "daprd"
|
||||
placementServiceFilePrefix = "placement"
|
||||
daprWindowsOS = "windows"
|
||||
daprLatestVersion = "latest"
|
||||
daprDefaultLinuxAndMacInstallPath = "/usr/local/bin"
|
||||
daprDefaultWindowsInstallPath = "c:\\dapr"
|
||||
daprDefaultHost = "localhost"
|
||||
pubSubYamlFileName = "pubsub.yaml"
|
||||
stateStoreYamlFileName = "statestore.yaml"
|
||||
zipkinYamlFileName = "zipkin.yaml"
|
||||
daprDockerImageName = "daprio/dapr"
|
||||
daprRuntimeFilePrefix = "daprd"
|
||||
placementServiceFilePrefix = "placement"
|
||||
daprWindowsOS = "windows"
|
||||
daprLatestVersion = "latest"
|
||||
daprDefaultHost = "localhost"
|
||||
pubSubYamlFileName = "pubsub.yaml"
|
||||
stateStoreYamlFileName = "statestore.yaml"
|
||||
zipkinYamlFileName = "zipkin.yaml"
|
||||
|
||||
// DaprPlacementContainerName is the container name of placement service
|
||||
DaprPlacementContainerName = "dapr_placement"
|
||||
|
@ -87,8 +84,8 @@ type componentMetadataItem struct {
|
|||
}
|
||||
|
||||
// Check if the previous version is already installed.
|
||||
func isBinaryInstallationRequired(binaryFilePrefix, installLocation, requestedVersion string) (bool, error) {
|
||||
binaryPath := binaryFilePath(binaryFilePrefix, installLocation)
|
||||
func isBinaryInstallationRequired(binaryFilePrefix, installDir string) (bool, error) {
|
||||
binaryPath := binaryFilePath(installDir, binaryFilePrefix)
|
||||
|
||||
// first time install?
|
||||
_, err := os.Stat(binaryPath)
|
||||
|
@ -99,7 +96,7 @@ func isBinaryInstallationRequired(binaryFilePrefix, installLocation, requestedVe
|
|||
}
|
||||
|
||||
// Init installs Dapr on a local machine using the supplied runtimeVersion.
|
||||
func Init(runtimeVersion string, dockerNetwork string, installLocation string, redisHost string, slimMode bool) error {
|
||||
func Init(runtimeVersion string, dockerNetwork string, redisHost string, slimMode bool) error {
|
||||
if !slimMode {
|
||||
dockerInstalled := utils.IsDockerInstalled()
|
||||
if !dockerInstalled {
|
||||
|
@ -107,13 +104,14 @@ func Init(runtimeVersion string, dockerNetwork string, installLocation string, r
|
|||
}
|
||||
}
|
||||
|
||||
downloadDest, err := getDownloadDest(installLocation)
|
||||
daprBinDir := defaultDaprBinPath()
|
||||
err := prepareDaprInstallDir(daprBinDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// confirm if installation is required
|
||||
if ok, er := isBinaryInstallationRequired(daprRuntimeFilePrefix, installLocation, runtimeVersion); !ok {
|
||||
if ok, er := isBinaryInstallationRequired(daprRuntimeFilePrefix, daprBinDir); !ok {
|
||||
return er
|
||||
}
|
||||
|
||||
|
@ -121,10 +119,6 @@ func Init(runtimeVersion string, dockerNetwork string, installLocation string, r
|
|||
errorChan := make(chan error)
|
||||
initSteps := []func(*sync.WaitGroup, chan<- error, string, string, string, string){}
|
||||
if slimMode {
|
||||
// confirm if installation is required
|
||||
if ok, er := isBinaryInstallationRequired(placementServiceFilePrefix, installLocation, runtimeVersion); !ok {
|
||||
return er
|
||||
}
|
||||
// Install 2 binaries in slim mode, daprd, placement
|
||||
wg.Add(2)
|
||||
} else {
|
||||
|
@ -154,15 +148,15 @@ func Init(runtimeVersion string, dockerNetwork string, installLocation string, r
|
|||
}
|
||||
|
||||
// Initialize daprd binary
|
||||
go installBinary(&wg, errorChan, downloadDest, runtimeVersion, daprRuntimeFilePrefix, dockerNetwork, installLocation)
|
||||
go installBinary(&wg, errorChan, daprBinDir, runtimeVersion, daprRuntimeFilePrefix, dockerNetwork)
|
||||
|
||||
if slimMode {
|
||||
// Initialize placement binary only on slim install
|
||||
go installBinary(&wg, errorChan, downloadDest, runtimeVersion, placementServiceFilePrefix, dockerNetwork, installLocation)
|
||||
go installBinary(&wg, errorChan, daprBinDir, runtimeVersion, placementServiceFilePrefix, dockerNetwork)
|
||||
} else {
|
||||
for _, step := range initSteps {
|
||||
// Run init on the configurations and containers
|
||||
go step(&wg, errorChan, downloadDest, runtimeVersion, dockerNetwork, redisHost)
|
||||
go step(&wg, errorChan, daprBinDir, runtimeVersion, dockerNetwork, redisHost)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,17 +180,10 @@ func Init(runtimeVersion string, dockerNetwork string, installLocation string, r
|
|||
|
||||
msg = "Downloaded binaries and completed components set up."
|
||||
print.SuccessStatusEvent(os.Stdout, msg)
|
||||
destDir := daprDefaultLinuxAndMacInstallPath
|
||||
if runtime.GOOS == daprWindowsOS {
|
||||
destDir = daprDefaultWindowsInstallPath
|
||||
}
|
||||
if installLocation != "" {
|
||||
destDir = installLocation
|
||||
}
|
||||
print.InfoStatusEvent(os.Stdout, "%s binary has been installed to %s.", daprRuntimeFilePrefix, destDir)
|
||||
print.InfoStatusEvent(os.Stdout, "%s binary has been installed to %s.", daprRuntimeFilePrefix, daprBinDir)
|
||||
if slimMode {
|
||||
// Print info on placement binary only on slim install
|
||||
print.InfoStatusEvent(os.Stdout, "%s binary has been installed to %s.", placementServiceFilePrefix, destDir)
|
||||
print.InfoStatusEvent(os.Stdout, "%s binary has been installed to %s.", placementServiceFilePrefix, daprBinDir)
|
||||
} else {
|
||||
dockerContainerNames := []string{DaprPlacementContainerName, DaprRedisContainerName, DaprZipkinContainerName}
|
||||
for _, container := range dockerContainerNames {
|
||||
|
@ -213,36 +200,18 @@ func Init(runtimeVersion string, dockerNetwork string, installLocation string, r
|
|||
return nil
|
||||
}
|
||||
|
||||
func getDownloadDest(installLocation string) (string, error) {
|
||||
p := ""
|
||||
|
||||
// use the install location passed in for Windows. This can't
|
||||
// be done for other environments because the install location default to a privileged dir: /usr/local/bin
|
||||
if runtime.GOOS == daprWindowsOS {
|
||||
if installLocation == "" {
|
||||
p = daprDefaultWindowsInstallPath
|
||||
} else {
|
||||
p = installLocation
|
||||
}
|
||||
} else {
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
p = path.Join(usr.HomeDir, ".dapr")
|
||||
}
|
||||
|
||||
err := os.MkdirAll(p, 0777)
|
||||
func prepareDaprInstallDir(daprBinDir string) error {
|
||||
err := os.MkdirAll(daprBinDir, 0777)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return err
|
||||
}
|
||||
|
||||
err = os.Chmod(p, 0777)
|
||||
err = os.Chmod(daprBinDir, 0777)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return err
|
||||
}
|
||||
|
||||
return p, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func runZipkin(wg *sync.WaitGroup, errorChan chan<- error, dir, version string, dockerNetwork string, _ string) {
|
||||
|
@ -460,7 +429,7 @@ func runPlacementService(wg *sync.WaitGroup, errorChan chan<- error, dir, versio
|
|||
errorChan <- nil
|
||||
}
|
||||
|
||||
func installBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version, binaryFilePrefix string, dockerNetwork string, installLocation string) {
|
||||
func installBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version, binaryFilePrefix string, dockerNetwork string) {
|
||||
defer wg.Done()
|
||||
|
||||
archiveExt := "tar.gz"
|
||||
|
@ -514,7 +483,7 @@ func installBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version, bin
|
|||
return
|
||||
}
|
||||
|
||||
binaryPath, err := moveFileToPath(extractedFilePath, installLocation)
|
||||
binaryPath, err := moveFileToPath(extractedFilePath, dir)
|
||||
if err != nil {
|
||||
errorChan <- fmt.Errorf("error moving %s binary to path: %s", binaryFilePrefix, err)
|
||||
return
|
||||
|
@ -681,20 +650,10 @@ func untar(filepath, targetDir, binaryFilePrefix string) (string, error) {
|
|||
}
|
||||
|
||||
func moveFileToPath(filepath string, installLocation string) (string, error) {
|
||||
destDir := daprDefaultLinuxAndMacInstallPath
|
||||
if runtime.GOOS == daprWindowsOS {
|
||||
destDir = daprDefaultWindowsInstallPath
|
||||
filepath = strings.Replace(filepath, "/", "\\", -1)
|
||||
}
|
||||
|
||||
fileName := path_filepath.Base(filepath)
|
||||
destFilePath := ""
|
||||
|
||||
// if user specified --install-path, use that
|
||||
if installLocation != "" {
|
||||
destDir = installLocation
|
||||
}
|
||||
|
||||
destDir := installLocation
|
||||
destFilePath = path.Join(destDir, fileName)
|
||||
|
||||
input, err := ioutil.ReadFile(filepath)
|
||||
|
@ -730,9 +689,8 @@ func moveFileToPath(filepath string, installLocation string) (string, error) {
|
|||
}
|
||||
|
||||
if !strings.HasPrefix(fileName, placementServiceFilePrefix) && installLocation != "" {
|
||||
// print only on daprd binary install in custom location
|
||||
color.Set(color.FgYellow)
|
||||
fmt.Printf("\nDapr installed to %s, please run the following to add it to your path:\n", destDir)
|
||||
fmt.Printf("\nDapr runtime installed to %s, you may run the following to add it to your path if you want to run daprd directly:\n", destDir)
|
||||
fmt.Printf(" export PATH=$PATH:%s\n", destDir)
|
||||
color.Unset()
|
||||
}
|
||||
|
|
|
@ -56,52 +56,32 @@ func removeDockerContainer(containerErrs []error, containerName, network string)
|
|||
return containerErrs
|
||||
}
|
||||
|
||||
func removeDefaultDaprDir(uninstallAll bool) (string, error) {
|
||||
if !uninstallAll {
|
||||
return "", nil
|
||||
}
|
||||
defaultDaprPath := defaultFolderPath(defaultDaprDirName)
|
||||
_, err := os.Stat(defaultDaprPath)
|
||||
func removeDir(dirPath string) error {
|
||||
_, err := os.Stat(dirPath)
|
||||
if os.IsNotExist(err) {
|
||||
print.WarningStatusEvent(os.Stdout, "WARNING: %s default Dapr folder does not exist", defaultDaprPath)
|
||||
return defaultDaprPath, nil
|
||||
print.WarningStatusEvent(os.Stdout, "WARNING: %s does not exist", dirPath)
|
||||
return nil
|
||||
}
|
||||
print.InfoStatusEvent(os.Stdout, "Removing folder: %s", defaultDaprPath)
|
||||
err = os.RemoveAll(defaultDaprPath)
|
||||
|
||||
return defaultDaprPath, err
|
||||
}
|
||||
|
||||
func removeInstalledBinaries(binaryFilePrefix, installLocation string) (string, error) {
|
||||
binaryPath := binaryFilePath(binaryFilePrefix, installLocation)
|
||||
_, err := os.Stat(binaryPath)
|
||||
if os.IsNotExist(err) {
|
||||
return binaryPath, nil
|
||||
}
|
||||
print.InfoStatusEvent(os.Stdout, "Removing binary: %s", binaryPath)
|
||||
err = os.Remove(binaryPath)
|
||||
|
||||
return binaryPath, err
|
||||
print.InfoStatusEvent(os.Stdout, "Removing directory: %s", dirPath)
|
||||
err = os.RemoveAll(dirPath)
|
||||
return err
|
||||
}
|
||||
|
||||
// Uninstall reverts all changes made by init. Deletes all installed containers, removes default dapr folder,
|
||||
// removes the installed binary and unsets env variables.
|
||||
func Uninstall(uninstallAll bool, installLocation, dockerNetwork string) error {
|
||||
func Uninstall(uninstallAll bool, dockerNetwork string) error {
|
||||
var containerErrs []error
|
||||
var err error
|
||||
var path string
|
||||
daprDefaultDir := defaultDaprDirPath()
|
||||
daprBinDir := defaultDaprBinPath()
|
||||
|
||||
path, err = removeInstalledBinaries(daprRuntimeFilePrefix, installLocation)
|
||||
if err != nil {
|
||||
print.WarningStatusEvent(os.Stdout, "WARNING: could not delete binary file: %s", path)
|
||||
}
|
||||
|
||||
placementFilePath := binaryFilePath(placementServiceFilePrefix, installLocation)
|
||||
placementFilePath := binaryFilePath(daprBinDir, placementServiceFilePrefix)
|
||||
_, placementErr := os.Stat(placementFilePath) // check if the placement binary exists
|
||||
uninstallPlacementContainer := os.IsNotExist(placementErr)
|
||||
path, err = removeInstalledBinaries(placementServiceFilePrefix, installLocation)
|
||||
|
||||
// Remove .dapr/bin
|
||||
err := removeDir(daprBinDir)
|
||||
if err != nil {
|
||||
print.WarningStatusEvent(os.Stdout, "WARNING: could not delete binary file: %s", path)
|
||||
print.WarningStatusEvent(os.Stdout, "WARNING: could not delete dapr bin dir: %s", daprBinDir)
|
||||
}
|
||||
|
||||
dockerInstalled := false
|
||||
|
@ -110,9 +90,11 @@ func Uninstall(uninstallAll bool, installLocation, dockerNetwork string) error {
|
|||
containerErrs = removeContainers(uninstallPlacementContainer, uninstallAll, dockerNetwork)
|
||||
}
|
||||
|
||||
path, err = removeDefaultDaprDir(uninstallAll)
|
||||
if err != nil {
|
||||
print.WarningStatusEvent(os.Stdout, "WARNING: could not delete default dapr folder: %s", path)
|
||||
if uninstallAll {
|
||||
err = removeDir(daprDefaultDir)
|
||||
if err != nil {
|
||||
print.WarningStatusEvent(os.Stdout, "WARNING: could not delete default dapr dir: %s", daprDefaultDir)
|
||||
}
|
||||
}
|
||||
|
||||
err = errors.New("uninstall failed")
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
// ------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
package standalone
|
||||
|
||||
import "os/exec"
|
||||
|
||||
// GetRuntimeVersion returns the version for the local Dapr runtime.
|
||||
func GetRuntimeVersion() string {
|
||||
daprBinDir := defaultDaprBinPath()
|
||||
daprCMD := binaryFilePath(daprBinDir, "daprd")
|
||||
|
||||
out, err := exec.Command(daprCMD, "--version").Output()
|
||||
if err != nil {
|
||||
return "n/a\n"
|
||||
}
|
||||
return string(out)
|
||||
}
|
|
@ -10,8 +10,6 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -22,22 +20,6 @@ const (
|
|||
DaprGitHubRepo = "dapr"
|
||||
)
|
||||
|
||||
// GetRuntimeVersion returns the version for the local Dapr runtime.
|
||||
func GetRuntimeVersion() string {
|
||||
runtimeName := ""
|
||||
if runtime.GOOS == "windows" {
|
||||
runtimeName = "daprd.exe"
|
||||
} else {
|
||||
runtimeName = "daprd"
|
||||
}
|
||||
|
||||
out, err := exec.Command(runtimeName, "--version").Output()
|
||||
if err != nil {
|
||||
return "n/a\n"
|
||||
}
|
||||
return string(out)
|
||||
}
|
||||
|
||||
type githubRepoReleaseItem struct {
|
||||
URL string `json:"url"`
|
||||
TagName string `json:"tag_name"`
|
||||
|
|
Loading…
Reference in New Issue