Skip to content

Commit 4b6419f

Browse files
ndeloofglours
authored andcommitted
introduce volume.type=image
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 583d2e1 commit 4b6419f

File tree

5 files changed

+85
-20
lines changed

5 files changed

+85
-20
lines changed

loader/loader_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3778,3 +3778,24 @@ services:
37783778
Options: map[string]string{"bar": "zot"},
37793779
})
37803780
}
3781+
3782+
func TestImageVolume(t *testing.T) {
3783+
p, err := loadYAML(`
3784+
name: imageVolume
3785+
services:
3786+
test:
3787+
volumes:
3788+
- type: image
3789+
source: app/image
3790+
target: /mnt/image
3791+
image:
3792+
subpath: /foo
3793+
`)
3794+
assert.NilError(t, err)
3795+
assert.DeepEqual(t, p.Services["test"].Volumes[0], types.ServiceVolumeConfig{
3796+
Type: "image",
3797+
Source: "app/image",
3798+
Target: "/mnt/image",
3799+
Image: &types.ServiceVolumeImage{SubPath: "/foo"},
3800+
})
3801+
}

override/merge.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func init() {
6161
mergeSpecials["services.*.extra_hosts"] = mergeExtraHosts
6262
mergeSpecials["services.*.healthcheck.test"] = override
6363
mergeSpecials["services.*.labels"] = mergeToSequence
64+
mergeSpecials["services.*.volumes.*.volume.labels"] = mergeToSequence
6465
mergeSpecials["services.*.logging"] = mergeLogging
6566
mergeSpecials["services.*.networks"] = mergeNetworks
6667
mergeSpecials["services.*.sysctls"] = mergeToSequence

schema/compose-spec.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,9 @@
418418
"type": "object",
419419
"required": ["type"],
420420
"properties": {
421-
"type": {"type": "string"},
421+
"type": {"type": "string",
422+
"enum": ["bind", "volume", "tmpfs", "cluster", "image"]
423+
},
422424
"source": {"type": "string"},
423425
"target": {"type": "string"},
424426
"read_only": {"type": ["boolean", "string"]},
@@ -437,6 +439,7 @@
437439
"volume": {
438440
"type": "object",
439441
"properties": {
442+
"labels": {"$ref": "#/definitions/list_or_dict"},
440443
"nocopy": {"type": ["boolean", "string"]},
441444
"subpath": {"type": "string"}
442445
},
@@ -456,6 +459,14 @@
456459
},
457460
"additionalProperties": false,
458461
"patternProperties": {"^x-": {}}
462+
},
463+
"image": {
464+
"type": "object",
465+
"properties": {
466+
"subpath": {"type": "string"}
467+
},
468+
"additionalProperties": false,
469+
"patternProperties": {"^x-": {}}
459470
}
460471
},
461472
"additionalProperties": false,

types/derived.gen.go

Lines changed: 40 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/types.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ type ServiceVolumeConfig struct {
541541
Bind *ServiceVolumeBind `yaml:"bind,omitempty" json:"bind,omitempty"`
542542
Volume *ServiceVolumeVolume `yaml:"volume,omitempty" json:"volume,omitempty"`
543543
Tmpfs *ServiceVolumeTmpfs `yaml:"tmpfs,omitempty" json:"tmpfs,omitempty"`
544+
Image *ServiceVolumeImage `yaml:"image,omitempty" json:"image,omitempty"`
544545

545546
Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
546547
}
@@ -575,6 +576,8 @@ const (
575576
VolumeTypeNamedPipe = "npipe"
576577
// VolumeTypeCluster is the type for mounting container storage interface (CSI) volumes
577578
VolumeTypeCluster = "cluster"
579+
// VolumeTypeImage is the tpe for mounting an image
580+
VolumeTypeImage = "image"
578581

579582
// SElinuxShared share the volume content
580583
SElinuxShared = "z"
@@ -618,8 +621,9 @@ const (
618621

619622
// ServiceVolumeVolume are options for a service volume of type volume
620623
type ServiceVolumeVolume struct {
621-
NoCopy bool `yaml:"nocopy,omitempty" json:"nocopy,omitempty"`
622-
Subpath string `yaml:"subpath,omitempty" json:"subpath,omitempty"`
624+
Labels Mapping `yaml:"labels,omitempty" json:"labels,omitempty"`
625+
NoCopy bool `yaml:"nocopy,omitempty" json:"nocopy,omitempty"`
626+
Subpath string `yaml:"subpath,omitempty" json:"subpath,omitempty"`
623627

624628
Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
625629
}
@@ -633,6 +637,11 @@ type ServiceVolumeTmpfs struct {
633637
Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
634638
}
635639

640+
type ServiceVolumeImage struct {
641+
SubPath string `yaml:"subpath,omitempty" json:"subpath,omitempty"`
642+
Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
643+
}
644+
636645
type FileMode int64
637646

638647
// FileReferenceConfig for a reference to a swarm file object

0 commit comments

Comments
 (0)