fix: avoid duplicate volume binds during recreate
This commit is contained in:
1 parent
a1def17750
commit
7c123833b5
4 files changed
+73
-28
No files matched your search
@@ -0,0 +1,36 @@
|
||||
type HostConfigLike = {
|
||||
Binds?: string[] | null;
|
||||
Mounts?: Array<{ Target?: string | null }> | null;
|
||||
};
|
||||
|
||||
type InspectMountLike = {
|
||||
Type?: string | null;
|
||||
Name?: string | null;
|
||||
Destination?: string | null;
|
||||
};
|
||||
|
||||
/** Build extra bind strings for volume mounts missing from HostConfig. */
|
||||
export function getAdditionalVolumeBinds(
|
||||
hostConfig: HostConfigLike,
|
||||
mounts: InspectMountLike[]
|
||||
): string[] {
|
||||
const existingMountTargets = new Set((hostConfig.Binds || []).map((bind: string) => {
|
||||
const parts = bind.split(':');
|
||||
return parts.length >= 2 ? parts[1] : parts[0];
|
||||
}));
|
||||
|
||||
for (const mount of hostConfig.Mounts || []) {
|
||||
if (mount?.Target) existingMountTargets.add(mount.Target);
|
||||
}
|
||||
|
||||
const additionalBinds: string[] = [];
|
||||
for (const mount of mounts || []) {
|
||||
if (mount.Type === 'volume' && mount.Name && mount.Destination) {
|
||||
if (!existingMountTargets.has(mount.Destination)) {
|
||||
additionalBinds.push(`${mount.Name}:${mount.Destination}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return additionalBinds;
|
||||
}
|
||||
Reference in new issue
Block a user