Adding self-hosted integration to Dashboard command (#427)

* added function to install dashboard binaries

* added to waitgroup

* updated installBinary method to support non-dapr repositories

* adding dashboard binaries

* binary install working for daprd and dashboard on linux

* added dashboard command for standalone

* updated dashboard documentation

* changed linux home directory to be outside of root

* fixing version issue

* moved location of extracted web folder

* fixing path issues on linux

* changed dashboard to take latest version

* updated documentation for dashboard standalone

* fixed issue where binary name was unknown in non-default path dapr install

* added user error message for dashboard not found error

* fixing linting issues

* adding dashboard compatibility changes

* mark dashboard flag as required

* syncing compatibility branch and master

* fixing uninstall error

* removing unnecessary check

* removing unused constants

* changed standalone untar method openfile mode

* added missing error message

* removed windows binary check in untar method

* updating unzip method to support multiple files in archive

* adding sanitizeExtractPath method and limiting archive copy bytes

* changed max file size to 100MB

* removing max file size limit

* removing debug statement

* Adding dashboard command to allow for standalone dashboard launch

* removed -rc tag downloads for dashboard

* removing extra alias

* adding function moveDashboardFiles to simplify installBinary function

* moving dashboard command logic to standalone/dashboard.go

* removing error channel from moveDashboardFiles

* removing error channel from moveDashboardFiles

Co-authored-by: Shalabh Mohan Shrivastava <shalabhs@microsoft.com>
This commit is contained in:
Will Smith 2020-08-06 16:11:55 -05:00 committed by GitHub
parent 12b0651c94
commit 5c3eb03030
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 87 additions and 5 deletions

View File

@ -12,6 +12,7 @@ import (
"github.com/dapr/cli/pkg/kubernetes"
"github.com/dapr/cli/pkg/print"
"github.com/dapr/cli/pkg/standalone"
"github.com/pkg/browser"
"github.com/spf13/cobra"
)
@ -134,6 +135,9 @@ var DashboardCmd = &cobra.Command{
}
<-portForward.GetStop()
} else {
// Standalone mode
standalone.RunDashboard()
}
},
}
@ -142,6 +146,5 @@ func init() {
DashboardCmd.Flags().BoolVarP(&kubernetesMode, "kubernetes", "k", false, "Start Dapr dashboard in local browser")
DashboardCmd.Flags().IntVarP(&port, "port", "p", defaultLocalPort, "The local port on which to serve dashboard")
DashboardCmd.Flags().StringVarP(&dashboardNamespace, "namespace", "n", daprSystemNamespace, "The namespace where Dapr dashboard is running")
DashboardCmd.MarkFlagRequired("kubernetes")
RootCmd.AddCommand(DashboardCmd)
}

View File

@ -0,0 +1,34 @@
package standalone
import (
"os"
"os/exec"
"path/filepath"
"runtime"
"github.com/dapr/cli/pkg/print"
)
// RunDashboard finds the dashboard binary and runs it
func RunDashboard() {
// Use the default binary install location
dashboardPath := defaultDaprBinPath()
binaryName := "dashboard"
if runtime.GOOS == "windows" {
binaryName = "dashboard.exe"
}
// Construct command to run dashboard
cmdDashboardStandalone := &exec.Cmd{
Path: filepath.Join(dashboardPath, binaryName),
Dir: dashboardPath,
Stdout: os.Stdout,
}
err := cmdDashboardStandalone.Run()
if err != nil {
print.FailureStatusEvent(os.Stdout, "Dapr dashboard not found. Is Dapr installed?")
} else {
print.SuccessStatusEvent(os.Stdout, "hi")
}
}

View File

@ -35,9 +35,11 @@ import (
const (
daprDockerImageName = "daprio/dapr"
daprRuntimeFilePrefix = "daprd"
dashboardFilePrefix = "dashboard"
placementServiceFilePrefix = "placement"
daprWindowsOS = "windows"
daprLatestVersion = "latest"
dashboardLatestVersion = "latest"
daprDefaultHost = "localhost"
pubSubYamlFileName = "pubsub.yaml"
stateStoreYamlFileName = "statestore.yaml"
@ -119,11 +121,11 @@ func Init(runtimeVersion string, dockerNetwork string, redisHost string, slimMod
errorChan := make(chan error)
initSteps := []func(*sync.WaitGroup, chan<- error, string, string, string, string){}
if slimMode {
// Install 2 binaries in slim mode, daprd, placement
wg.Add(2)
// Install 3 binaries in slim mode: daprd, dashboard, placement
wg.Add(3)
} else {
// Install only a single binary daprd
wg.Add(1)
// Install 2 binaries: daprd, dashboard
wg.Add(2)
initSteps = append(initSteps, createComponentsAndConfiguration, runPlacementService, runRedis, runZipkin)
// Init other configurations, containers
wg.Add(len(initSteps))
@ -150,6 +152,9 @@ func Init(runtimeVersion string, dockerNetwork string, redisHost string, slimMod
// Initialize daprd binary
go installBinary(&wg, errorChan, daprBinDir, runtimeVersion, daprRuntimeFilePrefix, dockerNetwork, cli_ver.DaprGitHubRepo)
// Initialize dashboard binary
go installBinary(&wg, errorChan, daprBinDir, dashboardLatestVersion, dashboardFilePrefix, dockerNetwork, cli_ver.DashboardGitHubRepo)
if slimMode {
// Initialize placement binary only on slim install
go installBinary(&wg, errorChan, daprBinDir, runtimeVersion, placementServiceFilePrefix, dockerNetwork, cli_ver.DaprGitHubRepo)
@ -429,6 +434,36 @@ func runPlacementService(wg *sync.WaitGroup, errorChan chan<- error, dir, versio
errorChan <- nil
}
func moveDashboardFiles(extractedFilePath string, dir string) (string, error) {
// Move /release/os/web directory to /web
oldPath := path_filepath.Join(path_filepath.Dir(extractedFilePath), "web")
newPath := path_filepath.Join(dir, "web")
err := os.Rename(oldPath, newPath)
if err != nil {
err = fmt.Errorf("failed to move dashboard files: %s", err)
return "", err
}
// Move binary from /release/<os>/web/dashboard(.exe) to /dashboard(.exe)
err = os.Rename(extractedFilePath, path_filepath.Join(dir, path_filepath.Base(extractedFilePath)))
if err != nil {
err = fmt.Errorf("error moving %s binary to path: %s", path_filepath.Base(extractedFilePath), err)
return "", err
}
// Change the extracted binary file path to reflect the move above
extractedFilePath = path_filepath.Join(dir, path_filepath.Base(extractedFilePath))
// Remove the now-empty 'release' directory
err = os.RemoveAll(path_filepath.Join(dir, "release"))
if err != nil {
err = fmt.Errorf("error moving dashboard files: %s", err)
return "", err
}
return extractedFilePath, nil
}
func installBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version, binaryFilePrefix string, dockerNetwork string, githubRepo string) {
defer wg.Done()
@ -483,6 +518,14 @@ func installBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version, bin
return
}
if binaryFilePrefix == "dashboard" {
extractedFilePath, err = moveDashboardFiles(extractedFilePath, dir)
if err != nil {
errorChan <- err
return
}
}
binaryPath, err := moveFileToPath(extractedFilePath, dir)
if err != nil {
errorChan <- fmt.Errorf("error moving %s binary to path: %s", binaryFilePrefix, err)

View File

@ -18,6 +18,8 @@ const (
DaprGitHubOrg = "dapr"
// DaprGitHubRepo is the repo name of dapr runtime on GitHub
DaprGitHubRepo = "dapr"
// DashboardGitHubRepo is the repo name of dapr dashboard on GitHub
DashboardGitHubRepo = "dashboard"
)
type githubRepoReleaseItem struct {