mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-16 11:25:24 +02:00
The randomize/isolated-deployment volume transform split mount strings on ':' and kept only the first two segments, so an access mode like :ro, :z or :Z was silently dropped and read-only mounts became read-write. Keep the full path+mode remainder when rebuilding the mount string. Fixes #4818
92 lines
2.4 KiB
TypeScript
92 lines
2.4 KiB
TypeScript
import _ from "lodash";
|
|
import type {
|
|
ComposeSpecification,
|
|
DefinitionsService,
|
|
DefinitionsVolume,
|
|
} from "../types";
|
|
|
|
// Función para agregar prefijo a volúmenes
|
|
export const addSuffixToVolumesRoot = (
|
|
volumes: { [key: string]: DefinitionsVolume },
|
|
suffix: string,
|
|
): { [key: string]: DefinitionsVolume } => {
|
|
return _.mapKeys(volumes, (_value, key) => `${key}-${suffix}`);
|
|
};
|
|
|
|
export const addSuffixToVolumesInServices = (
|
|
services: { [key: string]: DefinitionsService },
|
|
suffix: string,
|
|
): { [key: string]: DefinitionsService } => {
|
|
const newServices: { [key: string]: DefinitionsService } = {};
|
|
|
|
_.forEach(services, (serviceConfig, serviceName) => {
|
|
const newServiceConfig = _.cloneDeep(serviceConfig);
|
|
|
|
// Reemplazar nombres de volúmenes en volumes
|
|
if (_.has(newServiceConfig, "volumes")) {
|
|
newServiceConfig.volumes = _.map(newServiceConfig.volumes, (volume) => {
|
|
if (_.isString(volume)) {
|
|
// remainder is the container path plus optional access mode (:ro, :z, :Z)
|
|
const [volumeName, ...pathAndMode] = volume.split(":");
|
|
const remainder = pathAndMode.join(":");
|
|
|
|
// skip bind mounts and variables (e.g. $PWD)
|
|
if (
|
|
!volumeName ||
|
|
!remainder ||
|
|
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}:${remainder}`;
|
|
}
|
|
|
|
return `${volumeName}-${suffix}:${remainder}`;
|
|
}
|
|
if (_.isObject(volume) && volume.type === "volume" && volume.source) {
|
|
return {
|
|
...volume,
|
|
source: `${volume.source}-${suffix}`,
|
|
};
|
|
}
|
|
return volume;
|
|
});
|
|
}
|
|
|
|
newServices[serviceName] = newServiceConfig;
|
|
});
|
|
|
|
return newServices;
|
|
};
|
|
|
|
export const addSuffixToAllVolumes = (
|
|
composeData: ComposeSpecification,
|
|
suffix: string,
|
|
): ComposeSpecification => {
|
|
const updatedComposeData = { ...composeData };
|
|
|
|
if (updatedComposeData.volumes) {
|
|
updatedComposeData.volumes = addSuffixToVolumesRoot(
|
|
updatedComposeData.volumes,
|
|
suffix,
|
|
);
|
|
}
|
|
|
|
if (updatedComposeData.services) {
|
|
updatedComposeData.services = addSuffixToVolumesInServices(
|
|
updatedComposeData.services,
|
|
suffix,
|
|
);
|
|
}
|
|
|
|
return updatedComposeData;
|
|
};
|