MCPcopy
hub / github.com/docker/compose / buildMount

Function buildMount

pkg/compose/create.go:1202–1240  ·  view source on GitHub ↗
(project types.Project, volume types.ServiceVolumeConfig)

Source from the content-addressed store, hash-verified

1200}
1201
1202func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.Mount, error) {
1203 source := volume.Source
1204 switch volume.Type {
1205 case types.VolumeTypeBind:
1206 if !filepath.IsAbs(source) && !isUnixAbs(source) && !isWindowsAbs(source) {
1207 // volume source has already been prefixed with workdir if required, by compose-go project loader
1208 var err error
1209 source, err = filepath.Abs(source)
1210 if err != nil {
1211 return mount.Mount{}, err
1212 }
1213 }
1214 case types.VolumeTypeVolume:
1215 if volume.Source != "" {
1216 pVolume, ok := project.Volumes[volume.Source]
1217 if ok {
1218 source = pVolume.Name
1219 }
1220 }
1221 }
1222
1223 bind, vol, tmpfs, img := buildMountOptions(volume)
1224
1225 if bind != nil {
1226 volume.Type = types.VolumeTypeBind
1227 }
1228
1229 return mount.Mount{
1230 Type: mount.Type(volume.Type),
1231 Source: source,
1232 Target: volume.Target,
1233 ReadOnly: volume.ReadOnly,
1234 Consistency: mount.Consistency(volume.Consistency),
1235 BindOptions: bind,
1236 VolumeOptions: vol,
1237 TmpfsOptions: tmpfs,
1238 ImageOptions: img,
1239 }, nil
1240}
1241
1242func buildMountOptions(volume types.ServiceVolumeConfig) (*mount.BindOptions, *mount.VolumeOptions, *mount.TmpfsOptions, *mount.ImageOptions) {
1243 if volume.Type != types.VolumeTypeBind && volume.Bind != nil {

Callers 6

TestBuildBindMountFunction · 0.85
TestBuildNamedPipeMountFunction · 0.85
TestBuildVolumeMountFunction · 0.85
fillBindMountsFunction · 0.85

Calls 3

isUnixAbsFunction · 0.85
isWindowsAbsFunction · 0.85
buildMountOptionsFunction · 0.85

Tested by 3

TestBuildBindMountFunction · 0.68
TestBuildNamedPipeMountFunction · 0.68
TestBuildVolumeMountFunction · 0.68