Skip to content

Commit

Permalink
Merge pull request #100 from flownative/task/cleanup-path-building
Browse files Browse the repository at this point in the history
Further clean up path building
  • Loading branch information
kdambekalns authored Oct 10, 2024
2 parents d1ee022 + e0f493c commit a19e097
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion cmd/beach/cmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func startLocalBeach() error {
_ = destination.Close()

log.Info("Starting reverse proxy and database server ...")
commandArgs := []string{"compose", "-f", path.Base + "docker-compose.yml", "up", "--remove-orphans", "-d"}
commandArgs := []string{"compose", "-f", filepath.Join(path.Base, "docker-compose.yml"), "up", "--remove-orphans", "-d"}
err = exec.RunInteractiveCommand("docker", commandArgs)
if err != nil {
return errors.New("container startup failed")
Expand Down
5 changes: 3 additions & 2 deletions cmd/beach/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package cmd
import (
"os"
"path"
"path/filepath"
"regexp"
"strings"

Expand Down Expand Up @@ -80,11 +79,13 @@ func handleInitRun(cmd *cobra.Command, args []string) {
}
log.Info("Created 'Configuration/Development/Beach/Settings.yaml'.")

flowRootPath = strings.Trim(flowRootPath, "/")

environmentContent := readFileFromAssets("project/.localbeach.dist.env")
environmentContent = strings.ReplaceAll(environmentContent, "${BEACH_PROJECT_NAME}", projectName)
environmentContent = strings.ReplaceAll(environmentContent, "${BEACH_PROJECT_NAME_LOWERCASE}", strings.ToLower(projectName))
environmentContent = strings.ReplaceAll(environmentContent, "${BEACH_FLOW_ROOTPATH}", flowRootPath)
environmentContent = strings.ReplaceAll(environmentContent, "${BEACH_APPLICATION_PATH}", filepath.Join("/application", flowRootPath))
environmentContent = strings.ReplaceAll(environmentContent, "${BEACH_APPLICATION_PATH}", "/application/"+flowRootPath)

destination, err := os.Create(".localbeach.dist.env")
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions cmd/beach/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package cmd

import (
"path/filepath"
"strconv"

"github.com/flownative/localbeach/pkg/beachsandbox"
Expand Down Expand Up @@ -55,9 +54,9 @@ Docker containers (--containers).`,
} else {
commandArgs := []string{"exec", "-ti", sandbox.ProjectName + "_php", "bash", "-c"}
if follow {
commandArgs = append(commandArgs, "tail -n -"+strconv.Itoa(tail)+" -f "+filepath.Join("/application", sandbox.FlowRootPath, "Data/Logs/*.log"))
commandArgs = append(commandArgs, "tail -n -"+strconv.Itoa(tail)+" -f "+"/application/"+sandbox.FlowRootPath+"/Data/Logs/*.log")
} else {
commandArgs = append(commandArgs, "tail -n -"+strconv.Itoa(tail)+" "+filepath.Join("/application", sandbox.FlowRootPath, "Data/Logs/*.log"))
commandArgs = append(commandArgs, "tail -n -"+strconv.Itoa(tail)+" "+"/application/"+sandbox.FlowRootPath+"/Data/Logs/*.log")
}

err = exec.RunInteractiveCommand("docker", commandArgs)
Expand Down
3 changes: 2 additions & 1 deletion cmd/beach/cmd/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/flownative/localbeach/pkg/path"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"path/filepath"
)

// pauseCmd represents the pause command
Expand All @@ -36,7 +37,7 @@ func init() {

func handlePauseRun(cmd *cobra.Command, args []string) {
log.Info("Pausing reverse proxy and database server ...")
commandArgs := []string{"compose", "-f", path.Base + "docker-compose.yml", "stop", "webserver", "database"}
commandArgs := []string{"compose", "-f", filepath.Join(path.Base, "docker-compose.yml"), "stop", "webserver", "database"}
output, err := exec.RunCommand("docker", commandArgs)
if err != nil {
log.Fatal(output)
Expand Down
3 changes: 2 additions & 1 deletion cmd/beach/cmd/resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/flownative/localbeach/pkg/path"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"path/filepath"
)

// resumeCmd represents the resume command
Expand All @@ -36,7 +37,7 @@ func init() {

func handleResumeRun(cmd *cobra.Command, args []string) {
log.Info("Starting reverse proxy and database server ...")
commandArgs := []string{"compose", "-f", path.Base + "docker-compose.yml", "start", "webserver", "database"}
commandArgs := []string{"compose", "-f", filepath.Join(path.Base, "docker-compose.yml"), "start", "webserver", "database"}
output, err := exec.RunCommand("docker", commandArgs)
if err != nil {
log.Fatal(output)
Expand Down
5 changes: 3 additions & 2 deletions cmd/beach/cmd/setup-https.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cmd

import (
"errors"
"path/filepath"

"github.com/flownative/localbeach/pkg/exec"
"github.com/flownative/localbeach/pkg/path"
Expand Down Expand Up @@ -51,7 +52,7 @@ func handleSetupHttpsRun(cmd *cobra.Command, args []string) {
return
}

commandArgs = []string{"-cert-file", path.Certificates + "default.crt", "-key-file", path.Certificates + "default.key"}
commandArgs = []string{"-cert-file", filepath.Join(path.Certificates, "default.crt"), "-key-file", filepath.Join(path.Certificates, "default.key")}
for _, hostname := range strings.Split(host, ",") {
commandArgs = append(commandArgs, strings.Trim(hostname, " "))
}
Expand All @@ -68,7 +69,7 @@ func handleSetupHttpsRun(cmd *cobra.Command, args []string) {

if len(nginxStatusOutput) != 0 {
log.Info("Restarting reverse proxy ...")
commandArgs = []string{"compose", "-f", path.Base + "docker-compose.yml", "restart"}
commandArgs = []string{"compose", "-f", filepath.Join(path.Base, "docker-compose.yml"), "restart"}
output, err := exec.RunCommand("docker", commandArgs)
if err != nil {
log.Fatal(output)
Expand Down
2 changes: 1 addition & 1 deletion cmd/beach/cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func migrateOldBase() error {
log.Info("migrating old data from " + path.OldBase + " to " + path.Base)

log.Info("stopping reverse proxy and database server")
commandArgs := []string{"compose", "-f", path.OldBase + "docker-compose.yml", "rm", "--force", "--stop", "-v"}
commandArgs := []string{"compose", "-f", filepath.Join(path.OldBase, "docker-compose.yml"), "rm", "--force", "--stop", "-v"}
output, err := exec.RunCommand("docker", commandArgs)
if err != nil {
log.Error(output)
Expand Down
5 changes: 3 additions & 2 deletions pkg/beachsandbox/beachsandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package beachsandbox
import (
"os"
"path/filepath"
"strings"
)

type BeachSandbox struct {
Expand All @@ -36,8 +37,8 @@ func (sandbox *BeachSandbox) Init(rootPath string) error {

sandbox.DockerComposeFilePath = filepath.Join(sandbox.ProjectRootPath, ".localbeach.docker-compose.yaml")
sandbox.ProjectName = os.Getenv("BEACH_PROJECT_NAME")
sandbox.FlowRootPath = os.Getenv("BEACH_FLOW_ROOTPATH")
sandbox.ProjectDataPersistentResourcesPath = filepath.Join(rootPath, sandbox.FlowRootPath, "/Data/Persistent/Resources")
sandbox.FlowRootPath = strings.Trim(os.Getenv("BEACH_FLOW_ROOTPATH"), "/")
sandbox.ProjectDataPersistentResourcesPath = filepath.Join(sandbox.ProjectRootPath, sandbox.FlowRootPath, "Data/Persistent/Resources")

if info, err := os.Stat(filepath.Join(sandbox.ProjectRootPath, sandbox.FlowRootPath, "flow")); err == nil && !info.IsDir() {
return nil
Expand Down
9 changes: 5 additions & 4 deletions pkg/path/path_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package path
import (
"log"
"os"
"path/filepath"
)

var OldBase = ""
Expand All @@ -36,8 +37,8 @@ func init() {
return
}

OldBase = homeDir + "/Library/Application Support/Flownative/Local Beach/"
Base = homeDir + "/.LocalBeach/"
Certificates = Base + "Certificates/"
Database = Base + "MariaDB"
OldBase = filepath.Join(homeDir, "Library", "Application Support", "Flownative", "Local Beach")
Base = filepath.Join(homeDir, ".LocalBeach")
Certificates = filepath.Join(Base, "Certificates")
Database = filepath.Join(Base, "MariaDB")
}
9 changes: 5 additions & 4 deletions pkg/path/path_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package path
import (
"log"
"os"
"path/filepath"
)

var OldBase = ""
Expand All @@ -36,8 +37,8 @@ func init() {
return
}

OldBase = homeDir + "/.Flownative/Local Beach/"
Base = homeDir + "/.LocalBeach/"
Certificates = Base + "Certificates/"
Database = Base + "MariaDB/"
OldBase = filepath.Join(homeDir, ".Flownative", "Local Beach")
Base = filepath.Join(homeDir, ".LocalBeach")
Certificates = filepath.Join(Base, "Certificates")
Database = filepath.Join(Base, "MariaDB")
}

0 comments on commit a19e097

Please sign in to comment.