Skip to content

Commit 892cf19

Browse files
committed
add: CONTAINER_BASE_PATH_MAX_DEPTH
1 parent 0729eba commit 892cf19

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ Running `docker-compose-exec` will:
8484
```bash
8585
CONTAINER_EXEC_COMMAND="echo %COMPOSE %SERVICE" docker-compose-exec
8686
```
87+
- You can set the maximum depth of the recursive search for Docker Compose files (default depth is 2).
88+
```bash
89+
CONTAINER_BASE_PATH_MAX_DEPTH="5" docker-compose-exec
90+
```
8791

8892

8993
## Contributing

main.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import (
1111
"path/filepath"
1212
"slices"
1313
"strings"
14+
"strconv"
1415
)
1516

1617
var defaultContainerBasePath = "/var/container:/srv/container"
1718
var defaultContainerExecCommand = "docker compose -f %COMPOSE exec --user root %SERVICE /bin/sh"
19+
var defaultMaxDepth = 2
1820

1921
//go:embed HELP.md
2022
var help string
@@ -29,8 +31,7 @@ func isDirectory(path string) (bool, error) {
2931
return info.IsDir(), nil
3032
}
3133

32-
func getComposeFilesInDir(basePath string) ([]string, error) {
33-
maxDepth := 3
34+
func getComposeFilesInDir(basePath string, maxDepth int) ([]string, error) {
3435
isDir, err := isDirectory(basePath)
3536
if err != nil {
3637
return nil, err
@@ -103,8 +104,20 @@ func getAllComposeFiles() ([]string, string, error) {
103104
var composeFilePaths []string
104105
paths := getAllComposeSearchPaths()
105106

107+
maxDepthString := os.Getenv("CONTAINER_BASE_PATH_MAX_DEPTH")
108+
maxDepth, err := strconv.Atoi(maxDepthString)
109+
if err != nil {
110+
if maxDepthString != "" {
111+
fmt.Printf("Invalid value for CONTAINER_BASE_PATH_MAX_DEPTH: %s. Using default: %d\n", maxDepthString, defaultMaxDepth)
112+
}
113+
maxDepth = defaultMaxDepth
114+
}
115+
if maxDepth < 1 {
116+
maxDepth = 1
117+
}
118+
106119
for _, path := range paths {
107-
currentComposeFilePaths, _ := getComposeFilesInDir(path)
120+
currentComposeFilePaths, _ := getComposeFilesInDir(path, maxDepth)
108121
composeFilePaths = append(composeFilePaths, currentComposeFilePaths...)
109122
}
110123

0 commit comments

Comments
 (0)