Removed too much verbosity from utils.GetPath when no env file is available, added new argument (path) to Exec family of funcs
							parent
							
								
									d9f8b2375c
								
							
						
					
					
						commit
						d294948890
					
				| 
						 | 
				
			
			@ -239,14 +239,14 @@ func GetEdgeAppStatus(ID string) EdgeAppStatus {
 | 
			
		|||
func GetEdgeAppServices(ID string) []EdgeAppService {
 | 
			
		||||
 | 
			
		||||
	cmdArgs := []string{"-r", ".services | keys[]", utils.GetPath("edgeAppsPath") + ID + configFilename}
 | 
			
		||||
	servicesString := utils.Exec("yq", cmdArgs)
 | 
			
		||||
	servicesString := utils.Exec(utils.GetPath("wsPath"), "yq", cmdArgs)
 | 
			
		||||
	serviceSlices := strings.Split(servicesString, "\n")
 | 
			
		||||
	serviceSlices = utils.DeleteEmptySlices(serviceSlices)
 | 
			
		||||
	var edgeAppServices []EdgeAppService
 | 
			
		||||
 | 
			
		||||
	for _, serviceID := range serviceSlices {
 | 
			
		||||
		cmdArgs = []string{"-f", utils.GetPath("wsPath") + "/docker-compose.yml", "exec", "-T", serviceID, "echo", "'Service Check'"}
 | 
			
		||||
		cmdResult := utils.Exec("docker-compose", cmdArgs)
 | 
			
		||||
		cmdResult := utils.Exec(utils.GetPath("wsPath"), "docker-compose", cmdArgs)
 | 
			
		||||
		isRunning := false
 | 
			
		||||
		if cmdResult != "" {
 | 
			
		||||
			isRunning = true
 | 
			
		||||
| 
						 | 
				
			
			@ -268,7 +268,7 @@ func RunEdgeApp(ID string) EdgeAppStatus {
 | 
			
		|||
	for _, service := range services {
 | 
			
		||||
 | 
			
		||||
		cmdArgs = []string{"-f", utils.GetPath("wsPath") + "/docker-compose.yml", "start", service.ID}
 | 
			
		||||
		utils.Exec("docker-compose", cmdArgs)
 | 
			
		||||
		utils.Exec(utils.GetPath("wsPath"), "docker-compose", cmdArgs)
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -289,7 +289,7 @@ func StopEdgeApp(ID string) EdgeAppStatus {
 | 
			
		|||
	for _, service := range services {
 | 
			
		||||
 | 
			
		||||
		cmdArgs = []string{"-f", utils.GetPath("wsPath") + "/docker-compose.yml", "stop", service.ID}
 | 
			
		||||
		utils.Exec("docker-compose", cmdArgs)
 | 
			
		||||
		utils.Exec(utils.GetPath("wsPath"), "docker-compose", cmdArgs)
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -326,7 +326,7 @@ func DisableOnline(ID string) MaybeEdgeApp {
 | 
			
		|||
		log.Println("myedge.app environment file for " + ID + " not found. No need to delete.")
 | 
			
		||||
	} else {
 | 
			
		||||
		cmdArgs := []string{envFilePath}
 | 
			
		||||
		utils.Exec("rm", cmdArgs)
 | 
			
		||||
		utils.Exec(utils.GetPath("wsPath"), "rm", cmdArgs)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	buildFrameworkContainers()
 | 
			
		||||
| 
						 | 
				
			
			@ -338,7 +338,7 @@ func DisableOnline(ID string) MaybeEdgeApp {
 | 
			
		|||
func buildFrameworkContainers() {
 | 
			
		||||
 | 
			
		||||
	cmdArgs := []string{utils.GetPath("wsPath") + "ws", "--build"}
 | 
			
		||||
	utils.ExecAndStream("sh", cmdArgs)
 | 
			
		||||
	utils.ExecAndStream(utils.GetPath("wsPath"), "sh", cmdArgs)
 | 
			
		||||
 | 
			
		||||
	time.Sleep(defaultContainerOperationSleepTime)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -74,7 +74,7 @@ func GetDevices() []Device {
 | 
			
		|||
	var devices []Device
 | 
			
		||||
 | 
			
		||||
	cmdArgs := []string{"--raw", "--bytes", "--noheadings"}
 | 
			
		||||
	scanner := utils.ExecAndGetLines("lsblk", cmdArgs)
 | 
			
		||||
	scanner := utils.ExecAndGetLines("/", "lsblk", cmdArgs)
 | 
			
		||||
 | 
			
		||||
	var currentDevice Device
 | 
			
		||||
	var currentPartitions []Partition
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -284,13 +284,13 @@ func taskSetupTunnel(args taskSetupTunnelArgs) string {
 | 
			
		|||
	fmt.Println("Executing taskSetupTunnel")
 | 
			
		||||
 | 
			
		||||
	cmdargs := []string{"gen", "--name", args.NodeName, "--token", args.BootnodeToken, args.BootnodeAddress + ":8655", "--prefix", args.AssignedAddress}
 | 
			
		||||
	utils.Exec("tinc-boot", cmdargs)
 | 
			
		||||
	utils.Exec(utils.GetPath("wsPath"), "tinc-boot", cmdargs)
 | 
			
		||||
 | 
			
		||||
	cmdargs = []string{"start", "tinc@dnet"}
 | 
			
		||||
	utils.Exec("systemctl", cmdargs)
 | 
			
		||||
	utils.Exec(utils.GetPath("wsPath"), "systemctl", cmdargs)
 | 
			
		||||
 | 
			
		||||
	cmdargs = []string{"enable", "tinc@dnet"}
 | 
			
		||||
	utils.Exec("systemctl", cmdargs)
 | 
			
		||||
	utils.Exec(utils.GetPath("wsPath"), "systemctl", cmdargs)
 | 
			
		||||
 | 
			
		||||
	output := "OK" // Better check / logging of command execution result.
 | 
			
		||||
	return output
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,14 +15,14 @@ import (
 | 
			
		|||
)
 | 
			
		||||
 | 
			
		||||
// ExecAndStream : Runs a terminal command, but streams progress instead of outputting. Ideal for long lived process that need to be logged.
 | 
			
		||||
func ExecAndStream(command string, args []string) {
 | 
			
		||||
func ExecAndStream(path string, command string, args []string) {
 | 
			
		||||
 | 
			
		||||
	cmd := exec.Command(command, args...)
 | 
			
		||||
 | 
			
		||||
	var stdoutBuf, stderrBuf bytes.Buffer
 | 
			
		||||
	cmd.Stdout = io.MultiWriter(os.Stdout, &stdoutBuf)
 | 
			
		||||
	cmd.Stderr = io.MultiWriter(os.Stderr, &stderrBuf)
 | 
			
		||||
	cmd.Dir = GetPath("wsPath")
 | 
			
		||||
	cmd.Dir = path
 | 
			
		||||
 | 
			
		||||
	err := cmd.Run()
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -36,13 +36,13 @@ func ExecAndStream(command string, args []string) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
// Exec : Runs a terminal Command, catches and logs errors, returns the result.
 | 
			
		||||
func Exec(command string, args []string) string {
 | 
			
		||||
func Exec(path string, command string, args []string) string {
 | 
			
		||||
	cmd := exec.Command(command, args...)
 | 
			
		||||
	var out bytes.Buffer
 | 
			
		||||
	var stderr bytes.Buffer
 | 
			
		||||
	cmd.Stdout = &out
 | 
			
		||||
	cmd.Stderr = &stderr
 | 
			
		||||
	cmd.Dir = GetPath("wsPath")
 | 
			
		||||
	cmd.Dir = path
 | 
			
		||||
	err := cmd.Run()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		// TODO: Deal with possibility of error in command, allow explicit error handling and return proper formatted stderr
 | 
			
		||||
| 
						 | 
				
			
			@ -56,8 +56,8 @@ func Exec(command string, args []string) string {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
// Exec : Runs a terminal Command, returns the result as a *bufio.Scanner type, split in lines and ready to parse.
 | 
			
		||||
func ExecAndGetLines(command string, args []string) *bufio.Scanner {
 | 
			
		||||
	cmdOutput := Exec(command, args)
 | 
			
		||||
func ExecAndGetLines(path string, command string, args []string) *bufio.Scanner {
 | 
			
		||||
	cmdOutput := Exec(path, command, args)
 | 
			
		||||
	cmdOutputReader := strings.NewReader(cmdOutput)
 | 
			
		||||
	scanner := bufio.NewScanner(cmdOutputReader)
 | 
			
		||||
	scanner.Split(bufio.ScanLines)
 | 
			
		||||
| 
						 | 
				
			
			@ -105,10 +105,10 @@ func GetPath(pathKey string) string {
 | 
			
		|||
	// Read whole of .env file to map.
 | 
			
		||||
	var env map[string]string
 | 
			
		||||
	env, err := godotenv.Read()
 | 
			
		||||
	targetPath := ""
 | 
			
		||||
	var targetPath string
 | 
			
		||||
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		fmt.Println("Project .env file not found withing project root. Using only hardcoded path variables.")
 | 
			
		||||
		targetPath = ""
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	switch pathKey {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue