From 65a618886efc48562e5b9ff99ca630c83622419b Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Mon, 26 Oct 2020 11:35:02 +0100 Subject: new "image" mount type Add a new "image" mount type to `--mount`. The source of the mount is the name or ID of an image. The destination is the path inside the container. Image mounts further support an optional `rw,readwrite` parameter which if set to "true" will yield the mount writable inside the container. Note that no changes are propagated to the image mount on the host (which in any case is read only). Mounts are overlay mounts. To support read-only overlay mounts, vendor a non-release version of Buildah. Signed-off-by: Valentin Rothberg --- pkg/specgen/generate/container_create.go | 15 +++++++++++++++ pkg/specgen/specgen.go | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'pkg') diff --git a/pkg/specgen/generate/container_create.go b/pkg/specgen/generate/container_create.go index f051537de..53dc35df1 100644 --- a/pkg/specgen/generate/container_create.go +++ b/pkg/specgen/generate/container_create.go @@ -223,6 +223,9 @@ func createContainerOptions(ctx context.Context, rt *libpod.Runtime, s *specgen. for _, overlayVolume := range s.OverlayVolumes { destinations = append(destinations, overlayVolume.Destination) } + for _, imageVolume := range s.ImageVolumes { + destinations = append(destinations, imageVolume.Destination) + } options = append(options, libpod.WithUserVolumes(destinations)) if len(volumes) != 0 { @@ -248,6 +251,18 @@ func createContainerOptions(ctx context.Context, rt *libpod.Runtime, s *specgen. options = append(options, libpod.WithOverlayVolumes(vols)) } + if len(s.ImageVolumes) != 0 { + var vols []*libpod.ContainerImageVolume + for _, v := range s.ImageVolumes { + vols = append(vols, &libpod.ContainerImageVolume{ + Dest: v.Destination, + Source: v.Source, + ReadWrite: v.ReadWrite, + }) + } + options = append(options, libpod.WithImageVolumes(vols)) + } + if s.Command != nil { options = append(options, libpod.WithCommand(s.Command)) } diff --git a/pkg/specgen/specgen.go b/pkg/specgen/specgen.go index fa4af7b2b..d68f55402 100644 --- a/pkg/specgen/specgen.go +++ b/pkg/specgen/specgen.go @@ -214,6 +214,9 @@ type ContainerStorageConfig struct { // Overlay volumes are named volumes that will be added to the container. // Optional. OverlayVolumes []*OverlayVolume `json:"overlay_volumes,omitempty"` + // Image volumes bind-mount a container-image mount into the container. + // Optional. + ImageVolumes []*ImageVolume `json:"image_volumes,omitempty"` // Devices are devices that will be added to the container. // Optional. Devices []spec.LinuxDevice `json:"devices,omitempty"` @@ -476,6 +479,19 @@ type OverlayVolume struct { Source string `json:"source,omitempty"` } +// ImageVolume is a volume based on a container image. The container image is +// first mounted on the host and is then bind-mounted into the container. An +// ImageVolume is always mounted read only. +type ImageVolume struct { + // Source is the source of the image volume. The image can be referred + // to by name and by ID. + Source string + // Destination is the absolute path of the mount in the container. + Destination string + // ReadWrite sets the volume writable. + ReadWrite bool +} + // PortMapping is one or more ports that will be mapped into the container. type PortMapping struct { // HostIP is the IP that we will bind to on the host. -- cgit v1.2.3-54-g00ecf