don't use filepath to process remote bind paths

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2021-04-06 12:25:08 +02:00
parent d625f08a70
commit dc036c2686
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E

View File

@ -618,9 +618,9 @@ func buildContainerConfigMounts(p types.Project, s types.ServiceConfig) ([]mount
for _, config := range s.Configs { for _, config := range s.Configs {
target := config.Target target := config.Target
if config.Target == "" { if config.Target == "" {
target = filepath.Join(configsBaseDir, config.Source) target = configsBaseDir + config.Source
} else if !filepath.IsAbs(config.Target) { } else if !isUnixAbs(config.Target) {
target = filepath.Join(configsBaseDir, config.Target) target = configsBaseDir + config.Target
} }
definedConfig := p.Configs[config.Source] definedConfig := p.Configs[config.Source]
@ -649,13 +649,13 @@ func buildContainerConfigMounts(p types.Project, s types.ServiceConfig) ([]mount
func buildContainerSecretMounts(p types.Project, s types.ServiceConfig) ([]mount.Mount, error) { func buildContainerSecretMounts(p types.Project, s types.ServiceConfig) ([]mount.Mount, error) {
var mounts = map[string]mount.Mount{} var mounts = map[string]mount.Mount{}
secretsDir := "/run/secrets" secretsDir := "/run/secrets/"
for _, secret := range s.Secrets { for _, secret := range s.Secrets {
target := secret.Target target := secret.Target
if secret.Target == "" { if secret.Target == "" {
target = filepath.Join(secretsDir, secret.Source) target = secretsDir + secret.Source
} else if !filepath.IsAbs(secret.Target) { } else if !isUnixAbs(secret.Target) {
target = filepath.Join(secretsDir, secret.Target) target = secretsDir + secret.Target
} }
definedSecret := p.Secrets[secret.Source] definedSecret := p.Secrets[secret.Source]
@ -681,6 +681,10 @@ func buildContainerSecretMounts(p types.Project, s types.ServiceConfig) ([]mount
return values, nil return values, nil
} }
func isUnixAbs(path string) bool {
return strings.HasPrefix(path, "/")
}
func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.Mount, error) { func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.Mount, error) {
source := volume.Source source := volume.Source
if volume.Type == types.VolumeTypeBind && !filepath.IsAbs(source) { if volume.Type == types.VolumeTypeBind && !filepath.IsAbs(source) {
@ -699,7 +703,6 @@ func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.
source = pVolume.Name source = pVolume.Name
} }
} }
} }
return mount.Mount{ return mount.Mount{