mirror of https://github.com/dapr/cli.git
tested on mac
This commit is contained in:
parent
45b51a930b
commit
57e20ceb57
|
@ -25,7 +25,6 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
componentsDirName = "components"
|
||||
messageBusYamlFileName = "pubsub.yaml"
|
||||
stateStoreYamlFileName = "statestore.yaml"
|
||||
sentryDefaultAddress = "localhost:50001"
|
||||
|
@ -183,15 +182,6 @@ func getAppCommand(httpPort, grpcPort, metricsPort int, command string, args []s
|
|||
return cmd, nil
|
||||
}
|
||||
|
||||
func absoluteComponentsDir() (string, error) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return filepath.Join(wd, componentsDirName), nil
|
||||
}
|
||||
|
||||
func createRedisStateStore(redisHost string, componentsPath string) error {
|
||||
redisStore := component{
|
||||
APIVersion: "dapr.io/v1alpha1",
|
||||
|
@ -281,24 +271,9 @@ func Run(config *RunConfig) (*RunOutput, error) {
|
|||
}
|
||||
}
|
||||
|
||||
var componentsPath string
|
||||
|
||||
if config.ComponentsPath == "" {
|
||||
componentsPath, err = absoluteComponentsDir()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = utils.CreateDirectory(componentsPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
_, err = os.Stat(config.ComponentsPath)
|
||||
if os.IsNotExist(err) {
|
||||
return nil, err
|
||||
}
|
||||
componentsPath = config.ComponentsPath
|
||||
componentsPath, err := getComponentsPath(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
componentsLoader := components.NewStandaloneComponents(modes.StandaloneConfig{ComponentsPath: componentsPath})
|
||||
|
@ -369,3 +344,14 @@ func Run(config *RunConfig) (*RunOutput, error) {
|
|||
DaprGRPCPort: daprGRPCPort,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getComponentsPath(config *RunConfig) (string, error) {
|
||||
if config.ComponentsPath == "" {
|
||||
componentsPath, err := utils.GetDefaultComponentsFolder()
|
||||
fmt.Println("Read components env: ", componentsPath)
|
||||
return componentsPath, err
|
||||
}
|
||||
|
||||
_, err := os.Stat(config.ComponentsPath)
|
||||
return config.ComponentsPath, err
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"os/exec"
|
||||
"os/user"
|
||||
"path"
|
||||
"path/filepath"
|
||||
path_filepath "path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
@ -374,7 +375,10 @@ func installDaprBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version
|
|||
return
|
||||
}
|
||||
|
||||
daprPath, err := moveFileToPath(extractedFilePath, installLocation)
|
||||
destDir := getDestDir(installLocation)
|
||||
fmt.Println("destDir: ", destDir)
|
||||
|
||||
daprPath, err := moveFileToPath(extractedFilePath, installLocation, destDir)
|
||||
if err != nil {
|
||||
errorChan <- fmt.Errorf("error moving Dapr binary to path: %s", err)
|
||||
return
|
||||
|
@ -386,9 +390,39 @@ func installDaprBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version
|
|||
return
|
||||
}
|
||||
|
||||
fmt.Println("Trying to create components folder with input dir: ", destDir)
|
||||
err = createComponentsDir(destDir)
|
||||
if err != nil {
|
||||
errorChan <- fmt.Errorf("error creating default components folder: %s", err)
|
||||
return
|
||||
}
|
||||
errorChan <- nil
|
||||
}
|
||||
|
||||
func createComponentsDir(daprPath string) error {
|
||||
|
||||
// Make default components directory under install path
|
||||
componentsDir := filepath.Join(daprPath, utils.ComponentsDirName)
|
||||
fmt.Printf("default install location: %s\ncomponents folder location: %s\n", daprPath, componentsDir)
|
||||
fmt.Println("Creating default components dir: ", componentsDir)
|
||||
_, err := os.Stat(componentsDir)
|
||||
if os.IsNotExist(err) {
|
||||
errDir := os.MkdirAll(componentsDir, 0755)
|
||||
if errDir != nil {
|
||||
return errDir
|
||||
}
|
||||
|
||||
if runtime.GOOS == daprWindowsOS {
|
||||
_, err := utils.RunCmdAndWait("ATTRIB", "+s +h", componentsDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func makeExecutable(filepath string) error {
|
||||
if runtime.GOOS != daprWindowsOS {
|
||||
err := os.Chmod(filepath, 0777)
|
||||
|
@ -492,21 +526,24 @@ func untar(filepath, targetDir string) (string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func moveFileToPath(filepath string, installLocation string) (string, error) {
|
||||
func getDestDir(installLocation string) string {
|
||||
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
|
||||
}
|
||||
|
||||
return destDir
|
||||
}
|
||||
|
||||
func moveFileToPath(filepath string, installLocation string, destDir string) (string, error) {
|
||||
fileName := path_filepath.Base(filepath)
|
||||
destFilePath := ""
|
||||
|
||||
destFilePath = path.Join(destDir, fileName)
|
||||
|
||||
input, err := ioutil.ReadFile(filepath)
|
||||
|
|
|
@ -3,6 +3,7 @@ package standalone
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/dapr/cli/pkg/rundata"
|
||||
"github.com/dapr/cli/utils"
|
||||
|
@ -48,7 +49,15 @@ func removeContainers(uninstallAll bool, dockerNetwork string) []error {
|
|||
return containerErrs
|
||||
}
|
||||
|
||||
// Uninstall deletes all installed containers
|
||||
func removeDefaultComponentsFolder() error {
|
||||
defaultComponentsPath, err := utils.GetDefaultComponentsFolder()
|
||||
fmt.Println("Cleaning up default Components folder: ", defaultComponentsPath)
|
||||
err = os.RemoveAll(defaultComponentsPath)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Uninstall reverts all changes made by init. Deletes all installed containers, removes default components folder, unsets env variables
|
||||
func Uninstall(uninstallAll bool, dockerNetwork string) error {
|
||||
var containerErrs []error
|
||||
|
||||
|
@ -62,6 +71,12 @@ func Uninstall(uninstallAll bool, dockerNetwork string) error {
|
|||
fmt.Println("WARNING: could not delete run data file")
|
||||
}
|
||||
|
||||
fmt.Println("Removing default components folder")
|
||||
err = removeDefaultComponentsFolder()
|
||||
if err != nil {
|
||||
fmt.Println("WARNING: could not delete default components folder")
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -11,8 +11,9 @@ import (
|
|||
"io/ioutil"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/dapr/cli/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -24,12 +25,7 @@ const (
|
|||
|
||||
// GetRuntimeVersion returns the version for the local Dapr runtime.
|
||||
func GetRuntimeVersion() string {
|
||||
runtimeName := ""
|
||||
if runtime.GOOS == "windows" {
|
||||
runtimeName = "daprd.exe"
|
||||
} else {
|
||||
runtimeName = "daprd"
|
||||
}
|
||||
runtimeName := utils.GetDaprRuntimeName()
|
||||
|
||||
out, err := exec.Command(runtimeName, "--version").Output()
|
||||
if err != nil {
|
||||
|
|
|
@ -13,12 +13,17 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
path_filepath "path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
)
|
||||
|
||||
// ComponentsDirName is the default hidden components folder name created at init time
|
||||
const ComponentsDirName = ".components"
|
||||
|
||||
// PrintTable to print in the table format
|
||||
func PrintTable(csvContent string) {
|
||||
table := tablewriter.NewWriter(os.Stdout)
|
||||
|
@ -118,3 +123,27 @@ func IsDockerInstalled() bool {
|
|||
_, err = cli.Ping(context.Background())
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// GetDaprRuntimeName returns the name of the dapr runtime binary
|
||||
func GetDaprRuntimeName() string {
|
||||
runtimeName := ""
|
||||
if runtime.GOOS == "windows" {
|
||||
runtimeName = "daprd.exe"
|
||||
} else {
|
||||
runtimeName = "daprd"
|
||||
}
|
||||
|
||||
return runtimeName
|
||||
}
|
||||
|
||||
// GetDefaultComponentsFolder returns the hidden .components folder created under install directory at init time
|
||||
func GetDefaultComponentsFolder() (string, error) {
|
||||
daprBinaryName := GetDaprRuntimeName()
|
||||
daprRuntimePath, err := RunCmdAndWait("which", daprBinaryName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
defaultComponentsPath := path_filepath.Join(daprRuntimePath[0:len(daprRuntimePath)-len(daprBinaryName)-1], ComponentsDirName)
|
||||
return defaultComponentsPath, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue