mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-16 19:35:25 +02:00
refactor: rename builders to server
This commit is contained in:
78
packages/server/src/utils/docker/compose/volume.ts
Normal file
78
packages/server/src/utils/docker/compose/volume.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
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)) {
|
||||
const [volumeName, path] = volume.split(":");
|
||||
|
||||
// skip bind mounts and variables (e.g. $PWD)
|
||||
if (
|
||||
volumeName?.startsWith(".") ||
|
||||
volumeName?.startsWith("/") ||
|
||||
volumeName?.startsWith("$")
|
||||
) {
|
||||
return volume;
|
||||
}
|
||||
return `${volumeName}-${suffix}:${path}`;
|
||||
}
|
||||
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;
|
||||
};
|
||||
Reference in New Issue
Block a user