Skip to content

Commit 55c8eae

Browse files
authored
Merge pull request #94 from flownative/feature/flow-in-subfolder
Add support for Flow in a subfolder
2 parents 41c3f7b + 8ef2055 commit 55c8eae

File tree

7 files changed

+37
-32
lines changed

7 files changed

+37
-32
lines changed

assets/project/.localbeach.dist.env

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ BEACH_VIRTUAL_HOSTS=${BEACH_PROJECT_NAME_LOWERCASE}.localbeach.net
77

88
# Change the PHP version to the branch you use in your Beach instances.
99
# Examples: 8.1 for PHP 8.1.x
10-
1110
BEACH_PHP_IMAGE_VERSION=8.3
1211

12+
# Change these if your Flow setup is not in the project root
13+
BEACH_FLOW_ROOTPATH=${BEACH_FLOW_ROOTPATH}
14+
BEACH_APPLICATION_PATH=${BEACH_APPLICATION_PATH}
15+
1316
# You may specify additional environment variables below, for example
1417
# a URL of a service you use. Make sure to add this variable to the
1518
# "environment" section of the "php" container in ".localbeach.docker-compose.yaml".
19+
# like so: MY_CUSTOM_VAR=${MY_CUSTOM_VAR}

assets/project/.localbeach.docker-compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ services:
2424
- BEACH_PERSISTENT_RESOURCES_FALLBACK_BASE_URI=${BEACH_PERSISTENT_RESOURCES_FALLBACK_BASE_URI:-}
2525
- FLOW_HTTP_TRUSTED_PROXIES=*
2626
- NGINX_CACHE_ENABLE=false
27+
- BEACH_APPLICATION_PATH=${BEACH_APPLICATION_PATH:-/application}
2728

2829
php:
2930
image: ${BEACH_PHP_IMAGE:-flownative/beach-php}:${BEACH_PHP_IMAGE_VERSION:-8.2}
@@ -54,6 +55,7 @@ services:
5455
- BEACH_PHP_TIMEZONE=${BEACH_PHP_TIMEZONE:-UTC}
5556
- BEACH_APPLICATION_USER_SERVICE_ENABLE=${BEACH_APPLICATION_USER_SERVICE_ENABLE:-false}
5657
- BEACH_APPLICATION_STARTUP_SCRIPTS_ENABLE=${BEACH_APPLICATION_STARTUP_SCRIPTS_ENABLE:-false}
58+
- BEACH_APPLICATION_PATH=${BEACH_APPLICATION_PATH:-/application}
5759

5860
redis:
5961
image: ${BEACH_REDIS_IMAGE:-flownative/redis}:${BEACH_REDIS_IMAGE_VERSION:-latest}

cmd/beach/cmd/down.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func handleDownRun(cmd *cobra.Command, args []string) {
5050
for _, instanceRoot := range instanceRoots {
5151
log.Info("Stopping instance in " + instanceRoot + "...")
5252
sandbox, err := beachsandbox.GetSandbox(instanceRoot)
53-
if err != nil {
53+
if err != nil && !errors.Is(err, beachsandbox.ErrNoFlowFound) {
5454
log.Fatal(err)
5555
return
5656
}

cmd/beach/cmd/init.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ package cmd
1717
import (
1818
"os"
1919
"path"
20+
"path/filepath"
2021
"regexp"
2122
"strings"
2223

23-
"github.com/flownative/localbeach/pkg/beachsandbox"
2424
log "github.com/sirupsen/logrus"
2525
"github.com/spf13/cobra"
2626
)
2727

2828
var projectName string
29+
var flowRootPath string
2930

3031
// initCmd represents the init command
3132
var initCmd = &cobra.Command{
@@ -38,20 +39,22 @@ var initCmd = &cobra.Command{
3839

3940
func init() {
4041
initCmd.Flags().StringVar(&projectName, "project-name", "", "Defines the project name, defaults to folder name.")
42+
initCmd.Flags().StringVar(&flowRootPath, "flow-path", "", "Defines the Flow project root, defaults to current folder.")
4143
rootCmd.AddCommand(initCmd)
4244
}
4345

4446
func handleInitRun(cmd *cobra.Command, args []string) {
45-
sandbox, err := beachsandbox.GetRawSandbox()
46-
if err != nil {
47-
log.Fatal(err)
48-
return
49-
}
47+
var err error
5048

5149
projectNameFilter := regexp.MustCompile(`[^a-zA-Z0-9-]`)
5250
projectName := strings.Trim(projectName, " ")
5351
if len(projectName) == 0 {
54-
projectName = path.Base(sandbox.ProjectRootPath)
52+
workingDirPath, err := os.Getwd()
53+
if err != nil {
54+
log.Fatal(err)
55+
return
56+
}
57+
projectName = path.Base(workingDirPath)
5558
}
5659

5760
projectName = projectNameFilter.ReplaceAllLiteralString(projectName, "")
@@ -80,6 +83,8 @@ func handleInitRun(cmd *cobra.Command, args []string) {
8083
environmentContent := readFileFromAssets("project/.localbeach.dist.env")
8184
environmentContent = strings.ReplaceAll(environmentContent, "${BEACH_PROJECT_NAME}", projectName)
8285
environmentContent = strings.ReplaceAll(environmentContent, "${BEACH_PROJECT_NAME_LOWERCASE}", strings.ToLower(projectName))
86+
environmentContent = strings.ReplaceAll(environmentContent, "${BEACH_FLOW_ROOTPATH}", flowRootPath)
87+
environmentContent = strings.ReplaceAll(environmentContent, "${BEACH_APPLICATION_PATH}", filepath.Join("/application", flowRootPath))
8388

8489
destination, err := os.Create(".localbeach.dist.env")
8590
if err != nil {

cmd/beach/cmd/logs.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package cmd
1616

1717
import (
18+
"path/filepath"
1819
"strconv"
1920

2021
"github.com/flownative/localbeach/pkg/beachsandbox"
@@ -52,11 +53,11 @@ Docker containers (--containers).`,
5253
return
5354
}
5455
} else {
55-
commandArgs := []string{"exec", "-ti", sandbox.ProjectName + "_php"}
56+
commandArgs := []string{"exec", "-ti", sandbox.ProjectName + "_php", "bash", "-c"}
5657
if follow {
57-
commandArgs = append(commandArgs, "bash", "-c", "tail -n -"+strconv.Itoa(tail)+" -f /application/Data/Logs/*.log")
58+
commandArgs = append(commandArgs, "tail -n -"+strconv.Itoa(tail)+" -f "+filepath.Join("/application", sandbox.FlowRootPath, "Data/Logs/*.log"))
5859
} else {
59-
commandArgs = append(commandArgs, "bash", "-c", "tail -n -"+strconv.Itoa(tail)+" /application/Data/Logs/*.log")
60+
commandArgs = append(commandArgs, "tail -n -"+strconv.Itoa(tail)+" "+filepath.Join("/application", sandbox.FlowRootPath, "Data/Logs/*.log"))
6061
}
6162

6263
err = exec.RunInteractiveCommand("docker", commandArgs)

pkg/beachsandbox/beachsandbox.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,26 @@ type BeachSandbox struct {
2525
ProjectRootPath string ``
2626
ProjectDataPersistentResourcesPath string ``
2727
DockerComposeFilePath string ``
28+
FlowRootPath string ``
2829
}
2930

3031
func (sandbox *BeachSandbox) Init(rootPath string) error {
3132
sandbox.ProjectRootPath = rootPath
32-
sandbox.ProjectDataPersistentResourcesPath = rootPath + "/Data/Persistent/Resources"
3333

3434
if err := loadLocalBeachEnvironment(rootPath); err != nil {
3535
return err
3636
}
3737

3838
sandbox.DockerComposeFilePath = filepath.Join(sandbox.ProjectRootPath, ".localbeach.docker-compose.yaml")
3939
sandbox.ProjectName = os.Getenv("BEACH_PROJECT_NAME")
40+
sandbox.FlowRootPath = os.Getenv("BEACH_FLOW_ROOTPATH")
41+
sandbox.ProjectDataPersistentResourcesPath = filepath.Join(rootPath, sandbox.FlowRootPath, "/Data/Persistent/Resources")
4042

41-
return nil
43+
if info, err := os.Stat(filepath.Join(sandbox.ProjectRootPath, sandbox.FlowRootPath, "flow")); err == nil && !info.IsDir() {
44+
return nil
45+
}
46+
47+
return ErrNoFlowFound
4248
}
4349

4450
// GetActiveSandbox returns the active sandbox based on the current working dir
@@ -51,16 +57,6 @@ func GetActiveSandbox() (*BeachSandbox, error) {
5157
return GetSandbox(rootPath)
5258
}
5359

54-
// GetRawSandbox returns the (unconfigured) sandbox based on the current working dir
55-
func GetRawSandbox() (*BeachSandbox, error) {
56-
rootPath, err := detectProjectRootPathFromWorkingDir()
57-
if errors.Is(err, ErrNoFlowFound) {
58-
return nil, err
59-
}
60-
61-
return GetSandbox(rootPath)
62-
}
63-
6460
// GetSandbox returns the sandbox based on the given dir
6561
func GetSandbox(rootPath string) (*BeachSandbox, error) {
6662
sandbox := &BeachSandbox{}

pkg/beachsandbox/helpers.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
log "github.com/sirupsen/logrus"
2525
)
2626

27-
var ErrNoLocalBeachConfigurationFound = errors.New("found a Flow or Neos installation but no Local Beach configuration – run \"beach init\" to create some")
28-
var ErrNoFlowFound = errors.New("could not find Flow or Neos installation in your current path - try running \"composer install\" to fix that")
27+
var ErrNoLocalBeachConfigurationFound = errors.New("could not find a Local Beach configuration – run \"beach init\" to create some")
28+
var ErrNoFlowFound = errors.New("could not find Flow or Neos installation - try running \"composer install\" to fix that")
2929

3030
func detectProjectRootPathFromWorkingDir() (rootPath string, err error) {
3131
workingDirPath, err := os.Getwd()
@@ -40,13 +40,10 @@ func detectProjectRootPathFromWorkingDir() (rootPath string, err error) {
4040
func detectProjectRootPath(currentPath string) (projectRootPath string, err error) {
4141
projectRootPath = path.Clean(currentPath)
4242

43-
if info, err := os.Stat(filepath.Join(projectRootPath, "flow")); err == nil && !info.IsDir() {
44-
if _, err := os.Stat(filepath.Join(projectRootPath, ".localbeach.docker-compose.yaml")); err == nil {
45-
return projectRootPath, err
46-
}
47-
return projectRootPath, ErrNoLocalBeachConfigurationFound
43+
if _, err := os.Stat(filepath.Join(projectRootPath, ".localbeach.docker-compose.yaml")); err == nil {
44+
return projectRootPath, err
4845
} else if projectRootPath == "/" {
49-
return "", ErrNoFlowFound
46+
return "", ErrNoLocalBeachConfigurationFound
5047
}
5148

5249
return detectProjectRootPath(path.Dir(projectRootPath))

0 commit comments

Comments
 (0)