Skip to content

Commit 50501d2

Browse files
vvolandndeloof
authored andcommitted
Add volume subpath option
Only supported in the long syntax. Signed-off-by: Paweł Gronowski <[email protected]>
1 parent be0297a commit 50501d2

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

format/volume_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ func TestParseVolumeWithVolumeOptions(t *testing.T) {
177177
assert.Check(t, is.DeepEqual(expected, volume))
178178
}
179179

180+
func TestParseVolumeWithVolumeOptionsSubpath(t *testing.T) {
181+
volume, err := ParseVolume("name:/target:nocopy,subpath=etc")
182+
assert.NilError(t, err)
183+
184+
// subpath option is not supported in the short syntax
185+
assert.Check(t, is.Equal(volume.Volume.Subpath, ""))
186+
}
187+
180188
func TestParseVolumeWithReadOnly(t *testing.T) {
181189
for _, path := range []string{"./foo", "/home/user"} {
182190
volume, err := ParseVolume(path + ":/target:ro")

loader/loader_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,23 @@ networks:
13901390
assert.Check(t, is.DeepEqual(expected, config.Networks))
13911391
}
13921392

1393+
func TestLoadVolumeSubpath(t *testing.T) {
1394+
config, err := loadYAML(`
1395+
name: load-volume-subpath
1396+
services:
1397+
test:
1398+
image: alpine:latest
1399+
volumes:
1400+
- type: volume
1401+
source: asdf
1402+
target: /app
1403+
volume:
1404+
subpath: etc/settings
1405+
`)
1406+
assert.Check(t, err)
1407+
assert.Check(t, is.Equal(config.Services["test"].Volumes[0].Volume.Subpath, "etc/settings"))
1408+
}
1409+
13931410
func TestLoadExpandedPortFormat(t *testing.T) {
13941411
config, err := loadYAML(`
13951412
name: load-expanded-port-format

schema/compose-spec.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@
389389
"volume": {
390390
"type": "object",
391391
"properties": {
392-
"nocopy": {"type": "boolean"}
392+
"nocopy": {"type": "boolean"},
393+
"subpath": {"type": "string"}
393394
},
394395
"additionalProperties": false,
395396
"patternProperties": {"^x-": {}}

types/types.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@ func (s ServiceVolumeConfig) String() string {
511511
if s.Volume != nil && s.Volume.NoCopy {
512512
options = append(options, "nocopy")
513513
}
514+
if s.Volume != nil && s.Volume.Subpath != "" {
515+
options = append(options, s.Volume.Subpath)
516+
}
514517
return fmt.Sprintf("%s:%s:%s", s.Source, s.Target, strings.Join(options, ","))
515518
}
516519

@@ -567,7 +570,8 @@ const (
567570

568571
// ServiceVolumeVolume are options for a service volume of type volume
569572
type ServiceVolumeVolume struct {
570-
NoCopy bool `yaml:"nocopy,omitempty" json:"nocopy,omitempty"`
573+
NoCopy bool `yaml:"nocopy,omitempty" json:"nocopy,omitempty"`
574+
Subpath string `yaml:"subpath,omitempty" json:"subpath,omitempty"`
571575

572576
Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
573577
}

0 commit comments

Comments
 (0)