Skip to content

Commit 20f146b

Browse files
committed
Fix Dockerfile path resolution for TiUP Playground container
- Add filepath import for path operations - Find repo root by walking up directory tree to locate go.mod - Verify Dockerfile exists before attempting build - Support both local development and CI (GITHUB_WORKSPACE) environments
1 parent f0e18b6 commit 20f146b

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

mysql/testcontainers_helper.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"io"
1313
"log"
1414
"os"
15+
"path/filepath"
1516
"strings"
1617
"sync"
1718
"testing"
@@ -497,9 +498,41 @@ func startSharedTiDBClusterWithTiUP(version string) (*TiDBTestCluster, error) {
497498

498499
// Build TiUP Playground image from Dockerfile
499500
// 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
503+
moduleRoot := os.Getenv("GITHUB_WORKSPACE")
504+
if moduleRoot == "" {
505+
// For local development, find repo root by looking for go.mod
506+
cwd, err := os.Getwd()
507+
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
524+
}
525+
}
526+
527+
// Verify Dockerfile exists
528+
dockerfilePath := filepath.Join(moduleRoot, "Dockerfile.tiup-playground")
529+
if _, err := os.Stat(dockerfilePath); err != nil {
530+
return nil, fmt.Errorf("Dockerfile.tiup-playground not found at %s: %v", dockerfilePath, err)
531+
}
532+
500533
req := testcontainers.ContainerRequest{
501534
FromDockerfile: testcontainers.FromDockerfile{
502-
Context: ".",
535+
Context: moduleRoot,
503536
Dockerfile: "Dockerfile.tiup-playground",
504537
PrintBuildLog: true, // Helpful for debugging
505538
},

0 commit comments

Comments
 (0)