github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/api/types/mount/mount.go (about)

     1  package mount
     2  
     3  import (
     4  	"os"
     5  )
     6  
     7  // Type represents the type of a mount.
     8  type Type string
     9  
    10  // Type constants
    11  const (
    12  	// TypeBind is the type for mounting host dir
    13  	TypeBind Type = "bind"
    14  	// TypeVolume is the type for remote storage volumes
    15  	TypeVolume Type = "volume"
    16  	// TypeTmpfs is the type for mounting tmpfs
    17  	TypeTmpfs Type = "tmpfs"
    18  )
    19  
    20  // Mount represents a mount (volume).
    21  type Mount struct {
    22  	Type Type `json:",omitempty"`
    23  	// Source specifies the name of the mount. Depending on mount type, this
    24  	// may be a volume name or a host path, or even ignored.
    25  	// Source is not supported for tmpfs (must be an empty value)
    26  	Source   string `json:",omitempty"`
    27  	Target   string `json:",omitempty"`
    28  	ReadOnly bool   `json:",omitempty"`
    29  
    30  	BindOptions   *BindOptions   `json:",omitempty"`
    31  	VolumeOptions *VolumeOptions `json:",omitempty"`
    32  	TmpfsOptions  *TmpfsOptions  `json:",omitempty"`
    33  }
    34  
    35  // Propagation represents the propagation of a mount.
    36  type Propagation string
    37  
    38  const (
    39  	// PropagationRPrivate RPRIVATE
    40  	PropagationRPrivate Propagation = "rprivate"
    41  	// PropagationPrivate PRIVATE
    42  	PropagationPrivate Propagation = "private"
    43  	// PropagationRShared RSHARED
    44  	PropagationRShared Propagation = "rshared"
    45  	// PropagationShared SHARED
    46  	PropagationShared Propagation = "shared"
    47  	// PropagationRSlave RSLAVE
    48  	PropagationRSlave Propagation = "rslave"
    49  	// PropagationSlave SLAVE
    50  	PropagationSlave Propagation = "slave"
    51  )
    52  
    53  // BindOptions defines options specific to mounts of type "bind".
    54  type BindOptions struct {
    55  	Propagation Propagation `json:",omitempty"`
    56  }
    57  
    58  // VolumeOptions represents the options for a mount of type volume.
    59  type VolumeOptions struct {
    60  	NoCopy       bool              `json:",omitempty"`
    61  	Labels       map[string]string `json:",omitempty"`
    62  	DriverConfig *Driver           `json:",omitempty"`
    63  }
    64  
    65  // Driver represents a volume driver.
    66  type Driver struct {
    67  	Name    string            `json:",omitempty"`
    68  	Options map[string]string `json:",omitempty"`
    69  }
    70  
    71  // TmpfsOptions defines options specific to mounts of type "tmpfs".
    72  type TmpfsOptions struct {
    73  	// Size sets the size of the tmpfs, in bytes.
    74  	//
    75  	// This will be converted to an operating system specific value
    76  	// depending on the host. For example, on linux, it will be convered to
    77  	// use a 'k', 'm' or 'g' syntax. BSD, though not widely supported with
    78  	// docker, uses a straight byte value.
    79  	//
    80  	// Percentages are not supported.
    81  	SizeBytes int64 `json:",omitempty"`
    82  	// Mode of the tmpfs upon creation
    83  	Mode os.FileMode `json:",omitempty"`
    84  
    85  	// TODO(stevvooe): There are several more tmpfs flags, specified in the
    86  	// daemon, that are accepted. Only the most basic are added for now.
    87  	//
    88  	// From docker/docker/pkg/mount/flags.go:
    89  	//
    90  	// var validFlags = map[string]bool{
    91  	// 	"":          true,
    92  	// 	"size":      true, X
    93  	// 	"mode":      true, X
    94  	// 	"uid":       true,
    95  	// 	"gid":       true,
    96  	// 	"nr_inodes": true,
    97  	// 	"nr_blocks": true,
    98  	// 	"mpol":      true,
    99  	// }
   100  	//
   101  	// Some of these may be straightforward to add, but others, such as
   102  	// uid/gid have implications in a clustered system.
   103  }