mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
feat: add deployable option to randomize and prevent colission in duplicate templates
This commit is contained in:
26
packages/server/src/utils/docker/collision/container-name.ts
Normal file
26
packages/server/src/utils/docker/collision/container-name.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { ComposeSpecification, DefinitionsService } from "../types";
|
||||
import _ from "lodash";
|
||||
|
||||
export const addAppNameToContainerNames = (
|
||||
services: { [key: string]: DefinitionsService },
|
||||
appName: string,
|
||||
): { [key: string]: DefinitionsService } => {
|
||||
return _.mapValues(services, (service, serviceName) => {
|
||||
service.container_name = `${appName}-${serviceName}`;
|
||||
return service;
|
||||
});
|
||||
};
|
||||
|
||||
export const addAppNameToAllContainerNames = (
|
||||
composeData: ComposeSpecification,
|
||||
appName: string,
|
||||
): ComposeSpecification => {
|
||||
const updatedComposeData = { ...composeData };
|
||||
if (updatedComposeData.services) {
|
||||
updatedComposeData.services = addAppNameToContainerNames(
|
||||
updatedComposeData.services,
|
||||
appName,
|
||||
);
|
||||
}
|
||||
return updatedComposeData;
|
||||
};
|
||||
62
packages/server/src/utils/docker/collision/root-network.ts
Normal file
62
packages/server/src/utils/docker/collision/root-network.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import type { ComposeSpecification, DefinitionsService } from "../types";
|
||||
import _ from "lodash";
|
||||
|
||||
export const addAppNameToRootNetwork = (
|
||||
composeData: ComposeSpecification,
|
||||
appName: string,
|
||||
): ComposeSpecification => {
|
||||
const updatedComposeData = { ...composeData };
|
||||
|
||||
// Initialize networks if it doesn't exist
|
||||
if (!updatedComposeData.networks) {
|
||||
updatedComposeData.networks = {};
|
||||
}
|
||||
|
||||
// Add the new network with the app name
|
||||
updatedComposeData.networks[appName] = {
|
||||
name: appName,
|
||||
external: true,
|
||||
};
|
||||
|
||||
return updatedComposeData;
|
||||
};
|
||||
|
||||
export const addAppNameToServiceNetworks = (
|
||||
services: { [key: string]: DefinitionsService },
|
||||
appName: string,
|
||||
): { [key: string]: DefinitionsService } => {
|
||||
return _.mapValues(services, (service) => {
|
||||
if (!service.networks) {
|
||||
service.networks = [appName];
|
||||
return service;
|
||||
}
|
||||
|
||||
if (Array.isArray(service.networks)) {
|
||||
if (!service.networks.includes(appName)) {
|
||||
service.networks.push(appName);
|
||||
}
|
||||
} else {
|
||||
service.networks[appName] = {};
|
||||
}
|
||||
|
||||
return service;
|
||||
});
|
||||
};
|
||||
|
||||
export const addAppNameToAllServiceNames = (
|
||||
composeData: ComposeSpecification,
|
||||
appName: string,
|
||||
): ComposeSpecification => {
|
||||
let updatedComposeData = { ...composeData };
|
||||
|
||||
updatedComposeData = addAppNameToRootNetwork(updatedComposeData, appName);
|
||||
|
||||
if (updatedComposeData.services) {
|
||||
updatedComposeData.services = addAppNameToServiceNetworks(
|
||||
updatedComposeData.services,
|
||||
appName,
|
||||
);
|
||||
}
|
||||
|
||||
return updatedComposeData;
|
||||
};
|
||||
Reference in New Issue
Block a user