Skip to content

Commit 14e97c5

Browse files
committed
Use git root to find Dockerfile path
- Replace go.mod search with git rev-parse --show-toplevel - More reliable and standard approach for finding repo root - Still supports GITHUB_WORKSPACE for CI environments
1 parent 20f146b commit 14e97c5

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

mysql/testcontainers_helper.go

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"io"
1313
"log"
1414
"os"
15+
"os/exec"
1516
"path/filepath"
1617
"strings"
1718
"sync"
@@ -498,30 +499,16 @@ func startSharedTiDBClusterWithTiUP(version string) (*TiDBTestCluster, error) {
498499

499500
// Build TiUP Playground image from Dockerfile
500501
// This builds a container with TiUP installed that can run playground
501-
// Get the module root directory (where Dockerfile.tiup-playground is located)
502-
// Try multiple strategies to find the repo root
502+
// Get the git root directory (where Dockerfile.tiup-playground is located)
503503
moduleRoot := os.Getenv("GITHUB_WORKSPACE")
504504
if moduleRoot == "" {
505-
// For local development, find repo root by looking for go.mod
506-
cwd, err := os.Getwd()
505+
// For local development, find git root using git rev-parse
506+
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
507+
output, err := cmd.Output()
507508
if err != nil {
508-
return nil, fmt.Errorf("failed to get current working directory: %v", err)
509-
}
510-
511-
// Walk up the directory tree to find go.mod
512-
dir := cwd
513-
for {
514-
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
515-
moduleRoot = dir
516-
break
517-
}
518-
parent := filepath.Dir(dir)
519-
if parent == dir {
520-
// Reached filesystem root without finding go.mod
521-
return nil, fmt.Errorf("could not find go.mod in parent directories of %s", cwd)
522-
}
523-
dir = parent
509+
return nil, fmt.Errorf("failed to find git root: %v", err)
524510
}
511+
moduleRoot = strings.TrimSpace(string(output))
525512
}
526513

527514
// Verify Dockerfile exists

0 commit comments

Comments
 (0)