mirror of https://github.com/dapr/cli.git
Initialize dapr without docker dependency (#386)
* Initialize dapr without docker dependency * Create default empty components dir * Remove --slim flag from uninstall command * Changed phrasing * Updated Readme * Clarify slim init use case * language corrections Co-authored-by: Mark Chmarny <mchmarny@users.noreply.github.com> Co-authored-by: Ori Zohar <orzohar@microsoft.com>
This commit is contained in:
parent
8b58e2cba3
commit
ff2d5dd482
67
README.md
67
README.md
|
@ -9,9 +9,13 @@ The Dapr CLI allows you to setup Dapr on your local dev machine or on a Kubernet
|
|||
|
||||
### Prerequisites
|
||||
|
||||
On default, during initialization the Dapr CLI will install the Dapr binaries as well as setup a developer environment to help you get started easily with Dapr. This environment uses Docker containers, therefore Docker needs to be installed. If you prefer to run Dapr without this environment and no dependency on Docker, after installation of the CLI make sure follow the instructions to initialize Dapr using [slim init](#slim-init).
|
||||
|
||||
Note, if you are a new user, it is strongly recommended to intall Docker and use the regular init command.
|
||||
|
||||
* Install [Docker](https://docs.docker.com/install/)
|
||||
|
||||
*__Note: On Windows, Docker must be running in Linux Containers mode__*
|
||||
>__Note: On Windows, Docker must be running in Linux Containers mode__
|
||||
|
||||
### Installing Dapr CLI
|
||||
|
||||
|
@ -51,11 +55,24 @@ Each release of Dapr CLI includes various OSes and architectures. These binary v
|
|||
* For Linux/MacOS - `/usr/local/bin`
|
||||
* For Windows, create a directory and add this to your System PATH. For example create a directory called `c:\dapr` and add this directory to your path, by editing your system environment variable.
|
||||
|
||||
### Install Dapr on your local machine (standalone)
|
||||
### Install Dapr on your local machine (self-hosted)
|
||||
|
||||
In self-hosted mode, dapr can be initialized using the CLI with the placement, redis and zipkin containers enabled by default(recommended) or without them which also does not require docker to be available in the environment.
|
||||
|
||||
#### 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.
|
||||
|
||||
```bash
|
||||
dapr init
|
||||
```
|
||||
|
||||
Output should look like so:
|
||||
|
||||
```
|
||||
$ dapr init
|
||||
⌛ Making the jump to hyperspace...
|
||||
creating default components folder: ~/.dapr/components
|
||||
↓ Downloading binaries and setting up components...
|
||||
removing archive ~/.dapr/daprd_darwin_amd64.tar.gz
|
||||
↙ Downloading binaries and setting up components...
|
||||
|
@ -83,6 +100,41 @@ This step creates the following defaults:
|
|||
2. component files in the components folder called `pubsub.yaml`, `statestore.yaml` and `zipkin.yaml`.
|
||||
3. default config file `$HOME/.dapr/config.yaml` for Linux/MacOS or for Windows at `%USERPROFILE%\.dapr\config.yaml` to enable tracing on `dapr init` call. Can be overridden with the `--config` flag on `dapr run`.
|
||||
|
||||
#### Slim Init
|
||||
|
||||
Alternatively to the above, to have the CLI not install any default configuration files or run Docker containers, use the `--slim` flag with the init command. Only Dapr binaries will be installed.
|
||||
|
||||
```bash
|
||||
dapr init --slim
|
||||
```
|
||||
|
||||
Output should look like so:
|
||||
|
||||
```bash
|
||||
⌛ Making the jump to hyperspace...
|
||||
creating default components folder: ~/.dapr/components
|
||||
↙ Downloading binaries and setting up components...
|
||||
removing archive ~/.dapr/placement_darwin_amd64.tar.gz
|
||||
|
||||
installing Dapr to /usr/local/bin
|
||||
|
||||
removing extracted binary ~/.dapr/placement
|
||||
↙ Downloading binaries and setting up components...
|
||||
removing archive ~/.dapr/daprd_darwin_amd64.tar.gz
|
||||
← Downloading binaries and setting up components...
|
||||
installing Dapr to /usr/local/bin
|
||||
|
||||
removing extracted binary ~/.dapr/daprd
|
||||
✅ Downloaded binaries and completed components set up.
|
||||
ℹ️ daprd binary has been installed.
|
||||
|
||||
ℹ️ placement binary has been installed.
|
||||
|
||||
✅ Success! Dapr is up and running. To get started, go here: https://aka.ms/dapr-getting-started
|
||||
```
|
||||
|
||||
>Note: When initializing Dapr with the `--slim` flag only the Dapr runtime binary and the placement service binary are installed. An empty default components folder is created with no default configuration files. During `dapr run` user should use `--components-path` to point to a components directory with custom configurations files or alternatively place these files in the default directory. For Linux/MacOS, the default components directory path is `$HOME/.dapr/components` and for Windows it is `%USERPROFILE%\.dapr\components`.
|
||||
|
||||
#### Install a specific runtime version
|
||||
|
||||
You can install or upgrade to a specific version of the Dapr runtime using `dapr init --runtime-version`. You can find the list of versions in [Dapr Release](https://github.com/dapr/dapr/releases).
|
||||
|
@ -119,8 +171,7 @@ $ dapr init --redis-host 10.0.0.1
|
|||
|
||||
### Uninstall Dapr in a standalone mode
|
||||
|
||||
|
||||
Uninstalling will remove the placement container 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 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.
|
||||
|
||||
|
||||
```bash
|
||||
|
@ -133,7 +184,11 @@ The command above won't remove the redis or zipkin containers by default in case
|
|||
$ dapr uninstall --all
|
||||
```
|
||||
|
||||
You should always run a `dapr uninstall` before running another `dapr init`.
|
||||
The above command can also be run when Dapr has been installed in a non-docker environment, it will only remove the installed binaries and the default dapr folder in that case.
|
||||
|
||||
> NB: The `dapr uninstall` command will always try to remove the placement binary/service and will throw an error is not able to.
|
||||
|
||||
**You should always run a `dapr uninstall` before running another `dapr init`.**
|
||||
|
||||
#### Uninstall Dapr from a specific install path
|
||||
|
||||
|
|
10
cmd/init.go
10
cmd/init.go
|
@ -16,6 +16,7 @@ import (
|
|||
)
|
||||
|
||||
var kubernetesMode bool
|
||||
var slimMode bool
|
||||
var runtimeVersion string
|
||||
|
||||
var InitCmd = &cobra.Command{
|
||||
|
@ -25,6 +26,7 @@ var InitCmd = &cobra.Command{
|
|||
viper.BindPFlag("network", cmd.Flags().Lookup("network"))
|
||||
viper.BindPFlag("install-path", cmd.Flags().Lookup("install-path"))
|
||||
viper.BindPFlag("redis-host", cmd.Flags().Lookup("redis-host"))
|
||||
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
print.PendingStatusEvent(os.Stdout, "Making the jump to hyperspace...")
|
||||
|
@ -39,9 +41,12 @@ var InitCmd = &cobra.Command{
|
|||
}
|
||||
print.SuccessStatusEvent(os.Stdout, "Success! Dapr has been installed. To verify, run 'kubectl get pods -w' or 'dapr status -k' in your terminal. To get started, go here: https://aka.ms/dapr-getting-started")
|
||||
} else {
|
||||
dockerNetwork := viper.GetString("network")
|
||||
dockerNetwork := ""
|
||||
if !slimMode {
|
||||
dockerNetwork = viper.GetString("network")
|
||||
}
|
||||
redisHost := viper.GetString("redis-host")
|
||||
err := standalone.Init(runtimeVersion, dockerNetwork, installLocation, redisHost)
|
||||
err := standalone.Init(runtimeVersion, dockerNetwork, installLocation, redisHost, slimMode)
|
||||
if err != nil {
|
||||
print.FailureStatusEvent(os.Stdout, err.Error())
|
||||
return
|
||||
|
@ -53,6 +58,7 @@ var InitCmd = &cobra.Command{
|
|||
|
||||
func init() {
|
||||
InitCmd.Flags().BoolVarP(&kubernetesMode, "kubernetes", "k", false, "Deploy Dapr to a Kubernetes cluster")
|
||||
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")
|
||||
|
|
|
@ -22,3 +22,4 @@ dapr init [flags]
|
|||
| `--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.|
|
||||
|
|
|
@ -85,7 +85,6 @@ func NewPortForward(
|
|||
StopCh: make(chan struct{}, 1),
|
||||
ReadyCh: make(chan struct{}),
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
// run creates port-forward connection and blocks
|
||||
|
|
|
@ -39,13 +39,13 @@ func binaryInstallationPath(installLocation string) string {
|
|||
return daprDefaultLinuxAndMacInstallPath
|
||||
}
|
||||
|
||||
func daprdBinaryFilePath(installLocation string) string {
|
||||
func binaryFilePath(binaryFilePrefix, installLocation string) string {
|
||||
destDir := binaryInstallationPath(installLocation)
|
||||
daprdBinaryPath := path_filepath.Join(destDir, daprRuntimeFilePrefix)
|
||||
binaryPath := path_filepath.Join(destDir, binaryFilePrefix)
|
||||
if runtime.GOOS == daprWindowsOS {
|
||||
daprdBinaryPath = path_filepath.Join(daprdBinaryPath, ".exe")
|
||||
binaryPath = path_filepath.Join(binaryPath, ".exe")
|
||||
}
|
||||
return daprdBinaryPath
|
||||
return binaryPath
|
||||
}
|
||||
|
||||
func DefaultComponentsDirPath() string {
|
||||
|
|
|
@ -36,6 +36,7 @@ import (
|
|||
const (
|
||||
daprDockerImageName = "daprio/dapr"
|
||||
daprRuntimeFilePrefix = "daprd"
|
||||
placementServiceFilePrefix = "placement"
|
||||
daprWindowsOS = "windows"
|
||||
daprLatestVersion = "latest"
|
||||
daprDefaultLinuxAndMacInstallPath = "/usr/local/bin"
|
||||
|
@ -86,22 +87,24 @@ type componentMetadataItem struct {
|
|||
}
|
||||
|
||||
// Check if the previous version is already installed.
|
||||
func isBinaryInstallationRequired(installLocation, requestedVersion string) (bool, error) {
|
||||
daprdBinaryPath := daprdBinaryFilePath(installLocation)
|
||||
func isBinaryInstallationRequired(binaryFilePrefix, installLocation, requestedVersion string) (bool, error) {
|
||||
binaryPath := binaryFilePath(binaryFilePrefix, installLocation)
|
||||
|
||||
// first time install?
|
||||
_, err := os.Stat(daprdBinaryPath)
|
||||
_, err := os.Stat(binaryPath)
|
||||
if !os.IsNotExist(err) {
|
||||
return false, fmt.Errorf("%s %w, %s", daprdBinaryPath, os.ErrExist, errInstallTemplate)
|
||||
return false, fmt.Errorf("%s %w, %s", binaryPath, os.ErrExist, errInstallTemplate)
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// Init installs Dapr on a local machine using the supplied runtimeVersion.
|
||||
func Init(runtimeVersion string, dockerNetwork string, installLocation string, redisHost string) error {
|
||||
dockerInstalled := utils.IsDockerInstalled()
|
||||
if !dockerInstalled {
|
||||
return errors.New("could not connect to Docker. Docker may not be installed or running")
|
||||
func Init(runtimeVersion string, dockerNetwork string, installLocation string, redisHost string, slimMode bool) error {
|
||||
if !slimMode {
|
||||
dockerInstalled := utils.IsDockerInstalled()
|
||||
if !dockerInstalled {
|
||||
return errors.New("could not connect to Docker. Docker may not be installed or running")
|
||||
}
|
||||
}
|
||||
|
||||
downloadDest, err := getDownloadDest(installLocation)
|
||||
|
@ -110,18 +113,27 @@ func Init(runtimeVersion string, dockerNetwork string, installLocation string, r
|
|||
}
|
||||
|
||||
// confirm if installation is required
|
||||
if ok, err := isBinaryInstallationRequired(installLocation, runtimeVersion); !ok {
|
||||
return err
|
||||
if ok, er := isBinaryInstallationRequired(daprRuntimeFilePrefix, installLocation, runtimeVersion); !ok {
|
||||
return er
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
errorChan := make(chan error)
|
||||
|
||||
initSteps := []func(*sync.WaitGroup, chan<- error, string, string, string, string, string){}
|
||||
initSteps = append(initSteps, installDaprBinary, createComponentsAndConfiguration, runPlacementService, runRedis, runZipkin)
|
||||
dockerContainerNames := []string{DaprPlacementContainerName, DaprRedisContainerName, DaprZipkinContainerName}
|
||||
|
||||
wg.Add(len(initSteps))
|
||||
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 {
|
||||
// Install only a single binary daprd
|
||||
wg.Add(1)
|
||||
initSteps = append(initSteps, createComponentsAndConfiguration, runPlacementService, runRedis, runZipkin)
|
||||
// Init other configurations, containers
|
||||
wg.Add(len(initSteps))
|
||||
}
|
||||
|
||||
msg := "Downloading binaries and setting up components..."
|
||||
var s *spinner.Spinner
|
||||
|
@ -135,8 +147,23 @@ func Init(runtimeVersion string, dockerNetwork string, installLocation string, r
|
|||
s.Start()
|
||||
}
|
||||
|
||||
for _, step := range initSteps {
|
||||
go step(&wg, errorChan, downloadDest, runtimeVersion, dockerNetwork, installLocation, redisHost)
|
||||
// Make default components directory
|
||||
err = makeDefaultComponentsDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Initialize daprd binary
|
||||
go installBinary(&wg, errorChan, downloadDest, runtimeVersion, daprRuntimeFilePrefix, dockerNetwork, installLocation)
|
||||
|
||||
if slimMode {
|
||||
// Initialize placement binary only on slim install
|
||||
go installBinary(&wg, errorChan, downloadDest, runtimeVersion, placementServiceFilePrefix, dockerNetwork, installLocation)
|
||||
} else {
|
||||
for _, step := range initSteps {
|
||||
// Run init on the configurations and containers
|
||||
go step(&wg, errorChan, downloadDest, runtimeVersion, dockerNetwork, redisHost)
|
||||
}
|
||||
}
|
||||
|
||||
go func() {
|
||||
|
@ -160,16 +187,22 @@ func Init(runtimeVersion string, dockerNetwork string, installLocation string, r
|
|||
msg = "Downloaded binaries and completed components set up."
|
||||
print.SuccessStatusEvent(os.Stdout, msg)
|
||||
print.InfoStatusEvent(os.Stdout, "%s binary has been installed.\n", daprRuntimeFilePrefix)
|
||||
for _, container := range dockerContainerNames {
|
||||
ok, err := confirmContainerIsRunningOrExists(utils.CreateContainerName(container, dockerNetwork), true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ok {
|
||||
print.InfoStatusEvent(os.Stdout, "%s container is running.\n", container)
|
||||
if slimMode {
|
||||
// Print info on placement binary only on slim install
|
||||
print.InfoStatusEvent(os.Stdout, "%s binary has been installed.\n", placementServiceFilePrefix)
|
||||
} else {
|
||||
dockerContainerNames := []string{DaprPlacementContainerName, DaprRedisContainerName, DaprZipkinContainerName}
|
||||
for _, container := range dockerContainerNames {
|
||||
ok, err := confirmContainerIsRunningOrExists(utils.CreateContainerName(container, dockerNetwork), true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ok {
|
||||
print.InfoStatusEvent(os.Stdout, "%s container is running.\n", container)
|
||||
}
|
||||
}
|
||||
print.InfoStatusEvent(os.Stdout, "Use `docker ps` to check running containers.\n")
|
||||
}
|
||||
print.InfoStatusEvent(os.Stdout, "Use `docker ps` to check running containers.\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -205,10 +238,7 @@ func getDownloadDest(installLocation string) (string, error) {
|
|||
return p, nil
|
||||
}
|
||||
|
||||
// installLocation is not used, but it is present because it's required to fit the initSteps func above.
|
||||
// If the number of args increases more, we may consider passing in a struct instead of individual args.
|
||||
|
||||
func runZipkin(wg *sync.WaitGroup, errorChan chan<- error, dir, version string, dockerNetwork string, installLocation string, redisHost string) {
|
||||
func runZipkin(wg *sync.WaitGroup, errorChan chan<- error, dir, version string, dockerNetwork string, _ string) {
|
||||
defer wg.Done()
|
||||
|
||||
var zipkinContainerName = utils.CreateContainerName(DaprZipkinContainerName, dockerNetwork)
|
||||
|
@ -259,7 +289,7 @@ func runZipkin(wg *sync.WaitGroup, errorChan chan<- error, dir, version string,
|
|||
errorChan <- nil
|
||||
}
|
||||
|
||||
func runRedis(wg *sync.WaitGroup, errorChan chan<- error, dir, version string, dockerNetwork string, installLocation string, redisHost string) {
|
||||
func runRedis(wg *sync.WaitGroup, errorChan chan<- error, dir, version string, dockerNetwork string, redisHost string) {
|
||||
defer wg.Done()
|
||||
|
||||
var redisContainerName = utils.CreateContainerName(DaprRedisContainerName, dockerNetwork)
|
||||
|
@ -366,7 +396,7 @@ func isContainerRunError(err error) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func runPlacementService(wg *sync.WaitGroup, errorChan chan<- error, dir, version string, dockerNetwork string, installLocation string, _ string) {
|
||||
func runPlacementService(wg *sync.WaitGroup, errorChan chan<- error, dir, version string, dockerNetwork string, _ string) {
|
||||
defer wg.Done()
|
||||
var placementContainerName = utils.CreateContainerName(DaprPlacementContainerName, dockerNetwork)
|
||||
|
||||
|
@ -426,7 +456,7 @@ func runPlacementService(wg *sync.WaitGroup, errorChan chan<- error, dir, versio
|
|||
errorChan <- nil
|
||||
}
|
||||
|
||||
func installDaprBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version string, dockerNetwork string, installLocation string, _ string) {
|
||||
func installBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version, binaryFilePrefix string, dockerNetwork string, installLocation string) {
|
||||
defer wg.Done()
|
||||
|
||||
archiveExt := "tar.gz"
|
||||
|
@ -443,20 +473,21 @@ func installDaprBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version
|
|||
}
|
||||
version = version[1:]
|
||||
}
|
||||
|
||||
daprURL := fmt.Sprintf(
|
||||
// https://github.com/dapr/dapr/releases/download/v0.8.0/daprd_darwin_amd64.tar.gz
|
||||
// https://github.com/dapr/dapr/releases/download/v0.8.0/placement_darwin_amd64.tar.gz
|
||||
fileURL := fmt.Sprintf(
|
||||
"https://github.com/%s/%s/releases/download/v%s/%s_%s_%s.%s",
|
||||
cli_ver.DaprGitHubOrg,
|
||||
cli_ver.DaprGitHubRepo,
|
||||
version,
|
||||
daprRuntimeFilePrefix,
|
||||
binaryFilePrefix,
|
||||
runtime.GOOS,
|
||||
runtime.GOARCH,
|
||||
archiveExt)
|
||||
|
||||
filepath, err := downloadFile(dir, daprURL)
|
||||
filepath, err := downloadFile(dir, fileURL)
|
||||
if err != nil {
|
||||
errorChan <- fmt.Errorf("error downloading Dapr binary: %s", err)
|
||||
errorChan <- fmt.Errorf("error downloading %s binary: %s", binaryFilePrefix, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -465,11 +496,11 @@ func installDaprBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version
|
|||
if archiveExt == "zip" {
|
||||
extractedFilePath, err = unzip(filepath, dir)
|
||||
} else {
|
||||
extractedFilePath, err = untar(filepath, dir)
|
||||
extractedFilePath, err = untar(filepath, dir, binaryFilePrefix)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
errorChan <- fmt.Errorf("error extracting Dapr binary: %s", err)
|
||||
errorChan <- fmt.Errorf("error extracting %s binary: %s", binaryFilePrefix, err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("\nremoving archive %s\n", filepath)
|
||||
|
@ -480,9 +511,9 @@ func installDaprBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version
|
|||
return
|
||||
}
|
||||
|
||||
daprPath, err := moveFileToPath(extractedFilePath, installLocation)
|
||||
binaryPath, err := moveFileToPath(extractedFilePath, installLocation)
|
||||
if err != nil {
|
||||
errorChan <- fmt.Errorf("error moving Dapr binary to path: %s", err)
|
||||
errorChan <- fmt.Errorf("error moving %s binary to path: %s", binaryFilePrefix, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -494,32 +525,22 @@ func installDaprBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version
|
|||
return
|
||||
}
|
||||
|
||||
err = makeExecutable(daprPath)
|
||||
err = makeExecutable(binaryPath)
|
||||
if err != nil {
|
||||
errorChan <- fmt.Errorf("error making Dapr binary executable: %s", err)
|
||||
errorChan <- fmt.Errorf("error making %s binary executable: %s", binaryFilePrefix, err)
|
||||
return
|
||||
}
|
||||
|
||||
errorChan <- nil
|
||||
}
|
||||
|
||||
func createComponentsAndConfiguration(wg *sync.WaitGroup, errorChan chan<- error, dir, version string, dockerNetwork string, installLocation string, redisHost string) {
|
||||
func createComponentsAndConfiguration(wg *sync.WaitGroup, errorChan chan<- error, dir, version string, dockerNetwork string, redisHost string) {
|
||||
defer wg.Done()
|
||||
|
||||
var err error
|
||||
|
||||
// Make default components directory
|
||||
componentsDir := DefaultComponentsDirPath()
|
||||
_, err = os.Stat(componentsDir)
|
||||
if os.IsNotExist(err) {
|
||||
errDir := os.MkdirAll(componentsDir, 0755)
|
||||
if errDir != nil {
|
||||
errorChan <- fmt.Errorf("error creating default components folder: %s", errDir)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
os.Chmod(componentsDir, 0777)
|
||||
|
||||
err = createRedisPubSub(redisHost, componentsDir)
|
||||
if err != nil {
|
||||
|
@ -543,6 +564,22 @@ func createComponentsAndConfiguration(wg *sync.WaitGroup, errorChan chan<- error
|
|||
}
|
||||
}
|
||||
|
||||
func makeDefaultComponentsDir() error {
|
||||
// Make default components directory
|
||||
componentsDir := DefaultComponentsDirPath()
|
||||
_, err := os.Stat(componentsDir)
|
||||
if os.IsNotExist(err) {
|
||||
fmt.Printf("creating default components folder: %s\n", componentsDir)
|
||||
errDir := os.MkdirAll(componentsDir, 0755)
|
||||
if errDir != nil {
|
||||
return fmt.Errorf("error creating default components folder: %s", errDir)
|
||||
}
|
||||
}
|
||||
|
||||
os.Chmod(componentsDir, 0777)
|
||||
return nil
|
||||
}
|
||||
|
||||
func makeExecutable(filepath string) error {
|
||||
if runtime.GOOS != daprWindowsOS {
|
||||
err := os.Chmod(filepath, 0777)
|
||||
|
@ -596,7 +633,7 @@ func unzip(filepath, targetDir string) (string, error) {
|
|||
return "", nil
|
||||
}
|
||||
|
||||
func untar(filepath, targetDir string) (string, error) {
|
||||
func untar(filepath, targetDir, binaryFilePrefix string) (string, error) {
|
||||
tarFile, err := os.Open(filepath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -627,8 +664,8 @@ func untar(filepath, targetDir string) (string, error) {
|
|||
|
||||
switch header.Typeflag {
|
||||
case tar.TypeReg:
|
||||
// Extract only daprd
|
||||
if header.Name != "daprd" {
|
||||
// Extract only the binaryFile
|
||||
if header.Name != binaryFilePrefix {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -9,21 +9,23 @@ import (
|
|||
"github.com/dapr/cli/utils"
|
||||
)
|
||||
|
||||
func removeContainers(uninstallAll bool, dockerNetwork string) []error {
|
||||
func removeContainers(uninstallPlacementContainer, uninstallAll bool, dockerNetwork string) []error {
|
||||
var containerErrs []error
|
||||
var err error
|
||||
|
||||
containerErrs = removeDockerContainer(containerErrs, DaprPlacementContainerName, dockerNetwork)
|
||||
if uninstallPlacementContainer {
|
||||
containerErrs = removeDockerContainer(containerErrs, DaprPlacementContainerName, dockerNetwork)
|
||||
|
||||
_, err = utils.RunCmdAndWait(
|
||||
"docker", "rmi",
|
||||
"--force",
|
||||
daprDockerImageName)
|
||||
_, err = utils.RunCmdAndWait(
|
||||
"docker", "rmi",
|
||||
"--force",
|
||||
daprDockerImageName)
|
||||
|
||||
if err != nil {
|
||||
containerErrs = append(
|
||||
containerErrs,
|
||||
fmt.Errorf("could not remove %s image: %s", daprDockerImageName, err))
|
||||
if err != nil {
|
||||
containerErrs = append(
|
||||
containerErrs,
|
||||
fmt.Errorf("could not remove %s image: %s", daprDockerImageName, err))
|
||||
}
|
||||
}
|
||||
|
||||
if uninstallAll {
|
||||
|
@ -35,6 +37,11 @@ func removeContainers(uninstallAll bool, dockerNetwork string) []error {
|
|||
}
|
||||
|
||||
func removeDockerContainer(containerErrs []error, containerName, network string) []error {
|
||||
exists, _ := confirmContainerIsRunningOrExists(containerName, false)
|
||||
if !exists {
|
||||
fmt.Printf("WARNING: %s container does not exist\n", containerName)
|
||||
return containerErrs
|
||||
}
|
||||
fmt.Println("removing container: ", containerName)
|
||||
_, err := utils.RunCmdAndWait(
|
||||
"docker", "rm",
|
||||
|
@ -60,27 +67,42 @@ func removeDefaultDaprDir(uninstallAll bool) (string, error) {
|
|||
return defaultDaprPath, err
|
||||
}
|
||||
|
||||
func removeInstalledBinaries(installLocation string) (string, error) {
|
||||
daprdBinaryPath := daprdBinaryFilePath(installLocation)
|
||||
fmt.Println("removing binary: ", daprdBinaryPath)
|
||||
err := os.Remove(daprdBinaryPath)
|
||||
func removeInstalledBinaries(binaryFilePrefix, installLocation string) (string, error) {
|
||||
binaryPath := binaryFilePath(binaryFilePrefix, installLocation)
|
||||
_, err := os.Stat(binaryPath)
|
||||
if os.IsNotExist(err) {
|
||||
return binaryPath, nil
|
||||
}
|
||||
fmt.Println("removing binary: ", binaryPath)
|
||||
err = os.Remove(binaryPath)
|
||||
|
||||
return daprdBinaryPath, err
|
||||
return binaryPath, 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 {
|
||||
var containerErrs []error
|
||||
var err error
|
||||
var path string
|
||||
|
||||
dockerInstalled := utils.IsDockerInstalled()
|
||||
if dockerInstalled {
|
||||
containerErrs = removeContainers(uninstallAll, dockerNetwork)
|
||||
path, err = removeInstalledBinaries(daprRuntimeFilePrefix, installLocation)
|
||||
if err != nil {
|
||||
fmt.Println("WARNING: could not delete binary file: ", path)
|
||||
}
|
||||
|
||||
daprdBinaryPath, err := removeInstalledBinaries(installLocation)
|
||||
placementFilePath := binaryFilePath(placementServiceFilePrefix, installLocation)
|
||||
_, placementErr := os.Stat(placementFilePath) // check if the placement binary exists
|
||||
uninstallPlacementContainer := os.IsNotExist(placementErr)
|
||||
path, err = removeInstalledBinaries(placementServiceFilePrefix, installLocation)
|
||||
if err != nil {
|
||||
fmt.Println("WARNING: could not delete binary file: ", daprdBinaryPath)
|
||||
fmt.Println("WARNING: could not delete binary file: ", path)
|
||||
}
|
||||
|
||||
dockerInstalled := false
|
||||
dockerInstalled = utils.IsDockerInstalled()
|
||||
if dockerInstalled {
|
||||
containerErrs = removeContainers(uninstallPlacementContainer, uninstallAll, dockerNetwork)
|
||||
}
|
||||
|
||||
err = rundata.DeleteRunDataFile()
|
||||
|
@ -88,14 +110,15 @@ func Uninstall(uninstallAll bool, installLocation, dockerNetwork string) error {
|
|||
fmt.Println("WARNING: could not delete run data file")
|
||||
}
|
||||
|
||||
daprPath, err := removeDefaultDaprDir(uninstallAll)
|
||||
path, err = removeDefaultDaprDir(uninstallAll)
|
||||
if err != nil {
|
||||
fmt.Println("WARNING: could not delete default dapr folder: ", daprPath)
|
||||
fmt.Println("WARNING: could not delete default dapr folder: ", path)
|
||||
}
|
||||
|
||||
err = errors.New("uninstall failed")
|
||||
if !dockerInstalled {
|
||||
return fmt.Errorf("%w \n could not connect to Docker. Docker may not be installed or running", err)
|
||||
if uninstallPlacementContainer && !dockerInstalled {
|
||||
// if placement binary did not exist before trying to delete it and not able to connect to docker.
|
||||
return fmt.Errorf("%w \ncould not delete placement service. Either the placement binary is not found, or Docker may not be installed or running", err)
|
||||
}
|
||||
|
||||
if len(containerErrs) == 0 {
|
||||
|
|
Loading…
Reference in New Issue