@@ -388,36 +388,91 @@ func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby
388388 }
389389 if img .ContainerConfig != nil {
390390 for k := range img .ContainerConfig .Volumes {
391- mount , err := buildMount (p , types.ServiceVolumeConfig {
391+ m , err := buildMount (p , types.ServiceVolumeConfig {
392392 Type : types .VolumeTypeVolume ,
393393 Target : k ,
394394 })
395395 if err != nil {
396396 return nil , err
397397 }
398- mounts [k ] = mount
398+ mounts [k ] = m
399399
400400 }
401401 }
402+
403+ mounts , err := fillBindMounts (p , s , mounts )
404+ if err != nil {
405+ return nil , err
406+ }
407+
408+ values := make ([]mount.Mount , 0 , len (mounts ))
409+ for _ , v := range mounts {
410+ values = append (values , v )
411+ }
412+ return values , nil
413+ }
414+
415+ func fillBindMounts (p types.Project , s types.ServiceConfig , m map [string ]mount.Mount ) (map [string ]mount.Mount , error ) {
402416 for _ , v := range s .Volumes {
403- mount , err := buildMount (p , v )
417+ bindMount , err := buildMount (p , v )
404418 if err != nil {
405419 return nil , err
406420 }
407- mounts [ mount .Target ] = mount
421+ m [ bindMount .Target ] = bindMount
408422 }
409423
410424 secrets , err := buildContainerSecretMounts (p , s )
411425 if err != nil {
412426 return nil , err
413427 }
414428 for _ , s := range secrets {
415- if _ , found := mounts [s .Target ]; found {
429+ if _ , found := m [s .Target ]; found {
430+ continue
431+ }
432+ m [s .Target ] = s
433+ }
434+
435+ configs , err := buildContainerConfigMounts (p , s )
436+ if err != nil {
437+ return nil , err
438+ }
439+ for _ , c := range configs {
440+ if _ , found := m [c .Target ]; found {
416441 continue
417442 }
418- mounts [ s .Target ] = s
443+ m [ c .Target ] = c
419444 }
445+ return m , nil
446+ }
447+
448+ func buildContainerConfigMounts (p types.Project , s types.ServiceConfig ) ([]mount.Mount , error ) {
449+ var mounts = map [string ]mount.Mount {}
450+
451+ configsBaseDir := "/"
452+ for _ , config := range s .Configs {
453+ target := config .Target
454+ if config .Target == "" {
455+ target = filepath .Join (configsBaseDir , config .Source )
456+ } else if ! filepath .IsAbs (config .Target ) {
457+ target = filepath .Join (configsBaseDir , config .Target )
458+ }
459+
460+ definedConfig := p .Configs [config .Source ]
461+ if definedConfig .External .External {
462+ return nil , fmt .Errorf ("unsupported external config %s" , definedConfig .Name )
463+ }
420464
465+ bindMount , err := buildMount (p , types.ServiceVolumeConfig {
466+ Type : types .VolumeTypeBind ,
467+ Source : definedConfig .File ,
468+ Target : target ,
469+ ReadOnly : true ,
470+ })
471+ if err != nil {
472+ return nil , err
473+ }
474+ mounts [target ] = bindMount
475+ }
421476 values := make ([]mount.Mount , 0 , len (mounts ))
422477 for _ , v := range mounts {
423478 values = append (values , v )
0 commit comments