Enhance volume handling in Docker Compose: update addSuffixToVolumesInServices to correctly manage volume paths with subdirectories and improve test coverage for suffix changes in volume names.

This commit is contained in:
Mauricio Siu
2025-03-30 00:32:09 -06:00
parent e5e987fcf9
commit adee87b6da
2 changed files with 71 additions and 4 deletions

View File

@@ -30,12 +30,22 @@ export const addSuffixToVolumesInServices = (
// skip bind mounts and variables (e.g. $PWD)
if (
volumeName?.startsWith(".") ||
volumeName?.startsWith("/") ||
volumeName?.startsWith("$")
!volumeName ||
volumeName.startsWith(".") ||
volumeName.startsWith("/") ||
volumeName.startsWith("$")
) {
return volume;
}
// Handle volume paths with subdirectories
const parts = volumeName.split("/");
if (parts.length > 1) {
const baseName = parts[0];
const rest = parts.slice(1).join("/");
return `${baseName}-${suffix}/${rest}:${path}`;
}
return `${volumeName}-${suffix}:${path}`;
}
if (_.isObject(volume) && volume.type === "volume" && volume.source) {