Skip to content

Commit

Permalink
allow empty source
Browse files Browse the repository at this point in the history
  • Loading branch information
lionello committed Jun 24, 2024
1 parent 6392f34 commit 4e7e994
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/pkg/cli/compose/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,18 @@ func compare(actual []byte, goldenFile string) error {
func diff(actualRaw, goldenRaw string) error {
linesActual := strings.Split(actualRaw, "\n")
linesGolden := strings.Split(goldenRaw, "\n")
var prev string
for i, actual := range linesActual {
if i >= len(linesGolden) {
return fmt.Errorf("+ expected - actual\n+EOF\n-%s", actual)
return fmt.Errorf("+ expected - actual\n%s+EOF\n-%s", prev, actual)
}
if actual != linesGolden[i] {
return fmt.Errorf("+ expected - actual\n+%s\n-%s", linesGolden[i], actual)
return fmt.Errorf("+ expected - actual\n%s+%s\n-%s", prev, linesGolden[i], actual)
}
prev = " " + actual + "\n"
}
if len(linesActual) < len(linesGolden) {
return fmt.Errorf("+ expected - actual\n+%s\n-EOF", linesGolden[len(linesActual)])
return fmt.Errorf("+ expected - actual\n%s+%s\n-EOF", prev, linesGolden[len(linesActual)])
}
return nil
}
Expand Down
5 changes: 3 additions & 2 deletions src/pkg/cli/compose/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ func ValidateProject(project *compose.Project) error {
for _, v := range svccfg.Volumes {
if v.Type != "volume" {
warnf("service %q: unsupported volume type: %q", svccfg.Name, v.Type)
continue
continue // TODO: ignore or error?
}
if _, ok := project.Volumes[v.Source]; !ok {
// Source=="" is allowed for anonymous volumes (will generate a random name)
if _, ok := project.Volumes[v.Source]; !ok && v.Source != "" {
warnf("service %q: volume %q is not defined in the top-level volumes section", svccfg.Name, v.Source)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/protos/io/defang/v1/fabric.proto
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ message Service {
}

message Volume {
string source = 1; // name of the volume
string source = 1; // name of the volume; empty for anonymous volumes
string target = 2; // path in the container
bool read_only = 3;
}
Expand Down
14 changes: 14 additions & 0 deletions src/tests/volumes/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
volume1:
image: busybox
volumes:
- tmp:/tmp
volume2:
image: busybox
volumes:
- target: /tmp
read_only: true
type: volume

volumes:
tmp:
28 changes: 28 additions & 0 deletions src/tests/volumes/compose.yaml.convert
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[
{
"name": "volume1",
"image": "busybox",
"platform": 2,
"internal": true,
"networks": 1,
"volumes": [
{
"source": "tmp",
"target": "/tmp"
}
]
},
{
"name": "volume2",
"image": "busybox",
"platform": 2,
"internal": true,
"networks": 1,
"volumes": [
{
"target": "/tmp",
"read_only": true
}
]
}
]
25 changes: 25 additions & 0 deletions src/tests/volumes/compose.yaml.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: volumes
services:
volume1:
image: busybox
networks:
default: null
volumes:
- type: volume
source: tmp
target: /tmp
volume: {}
volume2:
image: busybox
networks:
default: null
volumes:
- type: volume
target: /tmp
read_only: true
networks:
default:
name: volumes_default
volumes:
tmp:
name: volumes_tmp
4 changes: 4 additions & 0 deletions src/tests/volumes/compose.yaml.warnings
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
level=warning msg="service \"volume1\": missing compose directive: restart; assuming 'unless-stopped' (add 'restart' to silence)"
level=warning msg="service \"volume1\": missing memory reservation; specify deploy.resources.reservations.memory to avoid out-of-memory errors"
level=warning msg="service \"volume2\": missing compose directive: restart; assuming 'unless-stopped' (add 'restart' to silence)"
level=warning msg="service \"volume2\": missing memory reservation; specify deploy.resources.reservations.memory to avoid out-of-memory errors"

0 comments on commit 4e7e994

Please sign in to comment.