Skip to content

introduce volume.type=image #769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3778,3 +3778,24 @@ services:
Options: map[string]string{"bar": "zot"},
})
}

func TestImageVolume(t *testing.T) {
p, err := loadYAML(`
name: imageVolume
services:
test:
volumes:
- type: image
source: app/image
target: /mnt/image
image:
subpath: /foo
`)
assert.NilError(t, err)
assert.DeepEqual(t, p.Services["test"].Volumes[0], types.ServiceVolumeConfig{
Type: "image",
Source: "app/image",
Target: "/mnt/image",
Image: &types.ServiceVolumeImage{SubPath: "/foo"},
})
}
1 change: 1 addition & 0 deletions override/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func init() {
mergeSpecials["services.*.extra_hosts"] = mergeExtraHosts
mergeSpecials["services.*.healthcheck.test"] = override
mergeSpecials["services.*.labels"] = mergeToSequence
mergeSpecials["services.*.volumes.*.volume.labels"] = mergeToSequence
mergeSpecials["services.*.logging"] = mergeLogging
mergeSpecials["services.*.networks"] = mergeNetworks
mergeSpecials["services.*.sysctls"] = mergeToSequence
Expand Down
13 changes: 12 additions & 1 deletion schema/compose-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,9 @@
"type": "object",
"required": ["type"],
"properties": {
"type": {"type": "string"},
"type": {"type": "string",
"enum": ["bind", "volume", "tmpfs", "cluster", "image"]
},
"source": {"type": "string"},
"target": {"type": "string"},
"read_only": {"type": ["boolean", "string"]},
Expand All @@ -437,6 +439,7 @@
"volume": {
"type": "object",
"properties": {
"labels": {"$ref": "#/definitions/list_or_dict"},
"nocopy": {"type": ["boolean", "string"]},
"subpath": {"type": "string"}
},
Expand All @@ -456,6 +459,14 @@
},
"additionalProperties": false,
"patternProperties": {"^x-": {}}
},
"image": {
"type": "object",
"properties": {
"subpath": {"type": "string"}
},
"additionalProperties": false,
"patternProperties": {"^x-": {}}
}
},
"additionalProperties": false,
Expand Down
57 changes: 40 additions & 17 deletions types/derived.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ type ServiceVolumeConfig struct {
Bind *ServiceVolumeBind `yaml:"bind,omitempty" json:"bind,omitempty"`
Volume *ServiceVolumeVolume `yaml:"volume,omitempty" json:"volume,omitempty"`
Tmpfs *ServiceVolumeTmpfs `yaml:"tmpfs,omitempty" json:"tmpfs,omitempty"`
Image *ServiceVolumeImage `yaml:"image,omitempty" json:"image,omitempty"`

Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
}
Expand Down Expand Up @@ -575,6 +576,8 @@ const (
VolumeTypeNamedPipe = "npipe"
// VolumeTypeCluster is the type for mounting container storage interface (CSI) volumes
VolumeTypeCluster = "cluster"
// VolumeTypeImage is the tpe for mounting an image
VolumeTypeImage = "image"

// SElinuxShared share the volume content
SElinuxShared = "z"
Expand Down Expand Up @@ -618,8 +621,9 @@ const (

// ServiceVolumeVolume are options for a service volume of type volume
type ServiceVolumeVolume struct {
NoCopy bool `yaml:"nocopy,omitempty" json:"nocopy,omitempty"`
Subpath string `yaml:"subpath,omitempty" json:"subpath,omitempty"`
Labels Mapping `yaml:"labels,omitempty" json:"labels,omitempty"`
NoCopy bool `yaml:"nocopy,omitempty" json:"nocopy,omitempty"`
Subpath string `yaml:"subpath,omitempty" json:"subpath,omitempty"`

Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
}
Expand All @@ -633,6 +637,11 @@ type ServiceVolumeTmpfs struct {
Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
}

type ServiceVolumeImage struct {
SubPath string `yaml:"subpath,omitempty" json:"subpath,omitempty"`
Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
}

type FileMode int64

// FileReferenceConfig for a reference to a swarm file object
Expand Down