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 (
|
const (
|
||||||
componentsDirName = "components"
|
|
||||||
messageBusYamlFileName = "pubsub.yaml"
|
messageBusYamlFileName = "pubsub.yaml"
|
||||||
stateStoreYamlFileName = "statestore.yaml"
|
stateStoreYamlFileName = "statestore.yaml"
|
||||||
sentryDefaultAddress = "localhost:50001"
|
sentryDefaultAddress = "localhost:50001"
|
||||||
|
@ -183,15 +182,6 @@ func getAppCommand(httpPort, grpcPort, metricsPort int, command string, args []s
|
||||||
return cmd, nil
|
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 {
|
func createRedisStateStore(redisHost string, componentsPath string) error {
|
||||||
redisStore := component{
|
redisStore := component{
|
||||||
APIVersion: "dapr.io/v1alpha1",
|
APIVersion: "dapr.io/v1alpha1",
|
||||||
|
@ -281,26 +271,11 @@ func Run(config *RunConfig) (*RunOutput, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var componentsPath string
|
componentsPath, err := getComponentsPath(config)
|
||||||
|
|
||||||
if config.ComponentsPath == "" {
|
|
||||||
componentsPath, err = absoluteComponentsDir()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
componentsLoader := components.NewStandaloneComponents(modes.StandaloneConfig{ComponentsPath: componentsPath})
|
componentsLoader := components.NewStandaloneComponents(modes.StandaloneConfig{ComponentsPath: componentsPath})
|
||||||
components, err := componentsLoader.LoadComponents()
|
components, err := componentsLoader.LoadComponents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -369,3 +344,14 @@ func Run(config *RunConfig) (*RunOutput, error) {
|
||||||
DaprGRPCPort: daprGRPCPort,
|
DaprGRPCPort: daprGRPCPort,
|
||||||
}, nil
|
}, 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/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
path_filepath "path/filepath"
|
path_filepath "path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -374,7 +375,10 @@ func installDaprBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
daprPath, err := moveFileToPath(extractedFilePath, installLocation)
|
destDir := getDestDir(installLocation)
|
||||||
|
fmt.Println("destDir: ", destDir)
|
||||||
|
|
||||||
|
daprPath, err := moveFileToPath(extractedFilePath, installLocation, destDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorChan <- fmt.Errorf("error moving Dapr binary to path: %s", err)
|
errorChan <- fmt.Errorf("error moving Dapr binary to path: %s", err)
|
||||||
return
|
return
|
||||||
|
@ -386,9 +390,39 @@ func installDaprBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version
|
||||||
return
|
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
|
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 {
|
func makeExecutable(filepath string) error {
|
||||||
if runtime.GOOS != daprWindowsOS {
|
if runtime.GOOS != daprWindowsOS {
|
||||||
err := os.Chmod(filepath, 0777)
|
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
|
destDir := daprDefaultLinuxAndMacInstallPath
|
||||||
if runtime.GOOS == daprWindowsOS {
|
if runtime.GOOS == daprWindowsOS {
|
||||||
destDir = daprDefaultWindowsInstallPath
|
destDir = daprDefaultWindowsInstallPath
|
||||||
filepath = strings.Replace(filepath, "/", "\\", -1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fileName := path_filepath.Base(filepath)
|
|
||||||
destFilePath := ""
|
|
||||||
|
|
||||||
// if user specified --install-path, use that
|
// if user specified --install-path, use that
|
||||||
if installLocation != "" {
|
if installLocation != "" {
|
||||||
destDir = 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)
|
destFilePath = path.Join(destDir, fileName)
|
||||||
|
|
||||||
input, err := ioutil.ReadFile(filepath)
|
input, err := ioutil.ReadFile(filepath)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package standalone
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/dapr/cli/pkg/rundata"
|
"github.com/dapr/cli/pkg/rundata"
|
||||||
"github.com/dapr/cli/utils"
|
"github.com/dapr/cli/utils"
|
||||||
|
@ -48,7 +49,15 @@ func removeContainers(uninstallAll bool, dockerNetwork string) []error {
|
||||||
return containerErrs
|
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 {
|
func Uninstall(uninstallAll bool, dockerNetwork string) error {
|
||||||
var containerErrs []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("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")
|
err = errors.New("uninstall failed")
|
||||||
if !dockerInstalled {
|
if !dockerInstalled {
|
||||||
return fmt.Errorf("%w \n could not connect to Docker. Docker may not be installed or running", err)
|
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"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/dapr/cli/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -24,12 +25,7 @@ const (
|
||||||
|
|
||||||
// GetRuntimeVersion returns the version for the local Dapr runtime.
|
// GetRuntimeVersion returns the version for the local Dapr runtime.
|
||||||
func GetRuntimeVersion() string {
|
func GetRuntimeVersion() string {
|
||||||
runtimeName := ""
|
runtimeName := utils.GetDaprRuntimeName()
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
runtimeName = "daprd.exe"
|
|
||||||
} else {
|
|
||||||
runtimeName = "daprd"
|
|
||||||
}
|
|
||||||
|
|
||||||
out, err := exec.Command(runtimeName, "--version").Output()
|
out, err := exec.Command(runtimeName, "--version").Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -13,12 +13,17 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
path_filepath "path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/olekukonko/tablewriter"
|
"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
|
// PrintTable to print in the table format
|
||||||
func PrintTable(csvContent string) {
|
func PrintTable(csvContent string) {
|
||||||
table := tablewriter.NewWriter(os.Stdout)
|
table := tablewriter.NewWriter(os.Stdout)
|
||||||
|
@ -118,3 +123,27 @@ func IsDockerInstalled() bool {
|
||||||
_, err = cli.Ping(context.Background())
|
_, err = cli.Ping(context.Background())
|
||||||
return err == nil
|
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