|
8 | 8 |
|
9 | 9 | "github.com/containerd/platforms" |
10 | 10 | "go.flipt.io/build/internal/dagger" |
11 | | - "golang.org/x/mod/modfile" |
12 | 11 | ) |
13 | 12 |
|
14 | 13 | func Base(ctx context.Context, dag *dagger.Client, source, uiDist *dagger.Directory, platform platforms.Platform, registryCache ...string) (*dagger.Container, error) { |
@@ -48,25 +47,26 @@ func Base(ctx context.Context, dag *dagger.Client, source, uiDist *dagger.Direct |
48 | 47 | } |
49 | 48 | } |
50 | 49 |
|
51 | | - goWork := source.File("go.work") |
52 | | - work, err := goWork.Contents(ctx) |
53 | | - if err != nil { |
54 | | - return nil, err |
55 | | - } |
| 50 | + // Mount the main module's go.mod and go.sum |
| 51 | + src := dag.Directory(). |
| 52 | + WithFile("go.mod", source.File("go.mod")). |
| 53 | + WithFile("go.sum", source.File("go.sum")) |
56 | 54 |
|
57 | | - workFile, err := modfile.ParseWork("go.work", []byte(work), nil) |
58 | | - if err != nil { |
59 | | - return nil, err |
| 55 | + // Mount submodule dependency files for all modules with replace directives |
| 56 | + submodules := []string{ |
| 57 | + "build", |
| 58 | + "core", |
| 59 | + "errors", |
| 60 | + "rpc/flipt", |
| 61 | + "rpc/v2/environments", |
| 62 | + "rpc/v2/evaluation", |
| 63 | + "sdk/go", |
| 64 | + "sdk/go/v2", |
60 | 65 | } |
61 | 66 |
|
62 | | - // infer mod and sum files from the contents of the work file. |
63 | | - src := dag.Directory(). |
64 | | - WithFile("go.work", goWork). |
65 | | - WithFile("go.work.sum", source.File("go.work.sum")) |
66 | | - |
67 | | - for _, use := range workFile.Use { |
68 | | - mod := path.Join(use.Path, "go.mod") |
69 | | - sum := path.Join(use.Path, "go.sum") |
| 67 | + for _, submodule := range submodules { |
| 68 | + mod := path.Join(submodule, "go.mod") |
| 69 | + sum := path.Join(submodule, "go.sum") |
70 | 70 | src = src. |
71 | 71 | WithFile(mod, source.File(mod)). |
72 | 72 | WithFile(sum, source.File(sum)) |
@@ -98,6 +98,39 @@ func Base(ctx context.Context, dag *dagger.Client, source, uiDist *dagger.Direct |
98 | 98 |
|
99 | 99 | golang = golang.WithMountedDirectory(".", project) |
100 | 100 |
|
| 101 | + // Create go.work file to enable multi-module support for tests |
| 102 | + // that run commands in submodules (e.g., go run ./build/internal/cmd/gitea/...) |
| 103 | + // |
| 104 | + // Note: We inline the content here rather than copying from build/go.work.container |
| 105 | + // to ensure it's always available regardless of mount ordering issues |
| 106 | + goWorkContent := `go 1.25.0 |
| 107 | +
|
| 108 | +use ( |
| 109 | + . |
| 110 | + ./build |
| 111 | + ./core |
| 112 | + ./errors |
| 113 | + ./rpc/flipt |
| 114 | + ./rpc/v2/environments |
| 115 | + ./rpc/v2/evaluation |
| 116 | + ./sdk/go |
| 117 | + ./sdk/go/v2 |
| 118 | +) |
| 119 | +` |
| 120 | + golang = golang.WithNewFile("/src/go.work", goWorkContent, dagger.ContainerWithNewFileOpts{ |
| 121 | + Permissions: 0644, |
| 122 | + }) |
| 123 | + |
| 124 | + // Sync the workspace to generate go.work.sum and validate the configuration |
| 125 | + golang = golang.WithExec([]string{"go", "work", "sync"}) |
| 126 | + |
| 127 | + // Download dependencies for ALL workspace modules (now that workspace is configured) |
| 128 | + // This ensures modules like 'build' have their dependencies available |
| 129 | + golang = golang.WithExec([]string{"go", "mod", "download"}) |
| 130 | + if _, err := golang.Sync(ctx); err != nil { |
| 131 | + return nil, fmt.Errorf("downloading workspace dependencies: %w", err) |
| 132 | + } |
| 133 | + |
101 | 134 | // fetch and add ui/embed.go on its own |
102 | 135 | embed := dag.Directory().WithFiles("./ui", []*dagger.File{ |
103 | 136 | source.File("./ui/dev.go"), |
|
0 commit comments