Merge pull request #1113 from docker/local_inline_secrets

This commit is contained in:
Nicolas De loof 2021-01-11 10:31:32 +01:00 committed by GitHub
commit 947009d772
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

View File

@ -296,6 +296,41 @@ func buildContainerMountOptions(p types.Project, s types.ServiceConfig, inherit
} }
mounts = append(mounts, mount) mounts = append(mounts, mount)
} }
secretsDir := "/run/secrets"
for _, secret := range s.Secrets {
target := secret.Target
if secret.Target == "" {
target = filepath.Join(secretsDir, secret.Source)
} else if !filepath.IsAbs(secret.Target) {
target = filepath.Join(secretsDir, secret.Target)
}
definedSecret := p.Secrets[secret.Source]
if definedSecret.External.External {
return nil, fmt.Errorf("unsupported external secret %s", definedSecret.Name)
}
if contains(inherited, target) {
// remove inherited mount
pos := indexOf(inherited, target)
if pos >= 0 {
mounts = append(mounts[:pos], mounts[pos+1])
inherited = append(inherited[:pos], inherited[pos+1])
}
}
mount, err := buildMount(p, types.ServiceVolumeConfig{
Type: types.VolumeTypeBind,
Source: definedSecret.File,
Target: target,
})
if err != nil {
return nil, err
}
mounts = append(mounts, mount)
}
return mounts, nil return mounts, nil
} }

View File

@ -38,3 +38,12 @@ func contains(slice []string, item string) bool {
} }
return false return false
} }
func indexOf(slice []string, item string) int {
for i, v := range slice {
if v == item {
return i
}
}
return -1
}