Skip to content

Commit d437c29

Browse files
feat(wanda): Add dependency graph with @name discovery
Add buildDepGraph() to parse wanda specs and resolve @name dependencies by scanning the repo for *.wanda.yaml files. The dependency graph is built in deterministic topological order using Kahn's algorithm with lexicographic tie-breaking. Key features: - @name syntax in froms references local specs by name - Automatic discovery by scanning repo from git root - Parallel spec parsing for performance - Cycle detection with helpful error messages - Variable expansion with unexpanded var detection Topic: wanda-deps Signed-off-by: andrew <andrew@anyscale.com>
1 parent 1f056c1 commit d437c29

14 files changed

+1142
-15
lines changed

wanda/deps.go

Lines changed: 457 additions & 0 deletions
Large diffs are not rendered by default.

wanda/deps_test.go

Lines changed: 654 additions & 0 deletions
Large diffs are not rendered by default.

wanda/forge_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func TestForge_withHints(t *testing.T) {
172172
t.Fatalf("build: %v", err)
173173
}
174174

175-
const tag = "cr.ray.io/rayproject/hello"
175+
const tag = "cr.ray.io/rayproject/hello-hint"
176176

177177
ref, err := name.ParseReference(tag)
178178
if err != nil {
@@ -214,11 +214,11 @@ func TestForge(t *testing.T) {
214214
NamePrefix: "cr.ray.io/rayproject/",
215215
}
216216

217-
if err := Build("testdata/hello.wanda.yaml", config); err != nil {
217+
if err := Build("testdata/hello-test.wanda.yaml", config); err != nil {
218218
t.Fatalf("build: %v", err)
219219
}
220220

221-
const tag = "cr.ray.io/rayproject/hello"
221+
const tag = "cr.ray.io/rayproject/hello-test"
222222

223223
ref, err := name.ParseReference(tag)
224224
if err != nil {
@@ -283,7 +283,7 @@ func TestForge_noCache(t *testing.T) {
283283
t.Fatalf("build: %v", err)
284284
}
285285

286-
const tag = "cr.ray.io/rayproject/hello"
286+
const tag = "cr.ray.io/rayproject/hello-nocache"
287287

288288
ref, err := name.ParseReference(tag)
289289
if err != nil {
@@ -362,7 +362,7 @@ func TestForgeWithRemoteWorkRepo(t *testing.T) {
362362
Epoch: "1",
363363
}
364364

365-
if err := Build("testdata/hello.wanda.yaml", config); err != nil {
365+
if err := Build("testdata/hello-test.wanda.yaml", config); err != nil {
366366
t.Fatalf("build hello: %v", err)
367367
}
368368

@@ -405,7 +405,7 @@ func TestForgeWithRemoteWorkRepo(t *testing.T) {
405405
t.Fatalf("make new forge: %v", err)
406406
}
407407

408-
helloSpec, err := parseSpecFile("testdata/hello.wanda.yaml")
408+
helloSpec, err := parseSpecFile("testdata/hello-test.wanda.yaml")
409409
if err != nil {
410410
t.Fatalf("parse hello spec: %v", err)
411411
}
@@ -420,7 +420,7 @@ func TestForgeWithRemoteWorkRepo(t *testing.T) {
420420
t.Errorf("got %d cache hits, want 1", hit)
421421
}
422422

423-
hello := fmt.Sprintf("%s/work:def456-hello", crAddr)
423+
hello := fmt.Sprintf("%s/work:def456-hello-test", crAddr)
424424
helloRef, err := name.ParseReference(hello)
425425
if err != nil {
426426
t.Fatalf("parse hello reference: %v", err)
@@ -475,7 +475,7 @@ func TestForgeLocal_withNamePrefix(t *testing.T) {
475475
Epoch: randomEpoch(),
476476
}
477477

478-
if err := Build("testdata/hello.wanda.yaml", config); err != nil {
478+
if err := Build("testdata/hello-test.wanda.yaml", config); err != nil {
479479
t.Fatalf("build hello: %v", err)
480480
}
481481

@@ -518,7 +518,7 @@ func TestForgeLocal_withNamePrefix(t *testing.T) {
518518
t.Fatalf("make new forge: %v", err)
519519
}
520520

521-
helloSpec, err := parseSpecFile("testdata/hello.wanda.yaml")
521+
helloSpec, err := parseSpecFile("testdata/hello-test.wanda.yaml")
522522
if err != nil {
523523
t.Fatalf("parse hello spec: %v", err)
524524
}
@@ -531,7 +531,7 @@ func TestForgeLocal_withNamePrefix(t *testing.T) {
531531
t.Errorf("got %d cache hits, want 1", hit)
532532
}
533533

534-
hello := "localhost:5000/rayci-work:abc123-hello"
534+
hello := "localhost:5000/rayci-work:abc123-hello-test"
535535
helloRef, err := name.ParseReference(hello)
536536
if err != nil {
537537
t.Fatalf("parse hello reference: %v", err)

wanda/testdata/Dockerfile.dep-base

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM scratch
2+
COPY Dockerfile.dep-base /opt/
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM dep-base
2+
COPY world.txt /opt/

wanda/testdata/Dockerfile.dep-top

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM dep-middle
2+
COPY Dockerfile.dep-top /opt/

wanda/testdata/Dockerfile.world

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
FROM cr.ray.io/rayproject/hello
1+
FROM cr.ray.io/rayproject/hello-test
22

33
COPY world.txt /opt/app/world.txt

wanda/testdata/dep-base.wanda.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name: dep-base
2+
dockerfile: Dockerfile.dep-base
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: dep-middle
2+
froms: ["cr.ray.io/rayproject/dep-base"]
3+
dockerfile: Dockerfile.dep-middle
4+
srcs:
5+
- world.txt

wanda/testdata/dep-top.wanda.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: dep-top
2+
froms: ["cr.ray.io/rayproject/dep-middle"]
3+
dockerfile: Dockerfile.dep-top

0 commit comments

Comments
 (0)