mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-19 06:05:25 +02:00
Merge branch 'canary' into feature/stop-grace-period-2227-alt
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
import { findComposeById } from "@dokploy/server/services/compose";
|
||||
import { dump, load } from "js-yaml";
|
||||
import { dump } from "js-yaml";
|
||||
import { addAppNameToAllServiceNames } from "./collision/root-network";
|
||||
import { generateRandomHash } from "./compose";
|
||||
import { addSuffixToAllVolumes } from "./compose/volume";
|
||||
import {
|
||||
cloneCompose,
|
||||
cloneComposeRemote,
|
||||
loadDockerCompose,
|
||||
loadDockerComposeRemote,
|
||||
} from "./domain";
|
||||
import type { ComposeSpecification } from "./types";
|
||||
|
||||
export const addAppNameToPreventCollision = (
|
||||
@@ -24,16 +30,34 @@ export const randomizeIsolatedDeploymentComposeFile = async (
|
||||
suffix?: string,
|
||||
) => {
|
||||
const compose = await findComposeById(composeId);
|
||||
const composeFile = compose.composeFile;
|
||||
const composeData = load(composeFile) as ComposeSpecification;
|
||||
|
||||
if (compose.serverId) {
|
||||
await cloneComposeRemote(compose);
|
||||
} else {
|
||||
await cloneCompose(compose);
|
||||
}
|
||||
|
||||
let composeData: ComposeSpecification | null;
|
||||
|
||||
if (compose.serverId) {
|
||||
composeData = await loadDockerComposeRemote(compose);
|
||||
} else {
|
||||
composeData = await loadDockerCompose(compose);
|
||||
}
|
||||
|
||||
if (!composeData) {
|
||||
throw new Error("Compose data not found");
|
||||
}
|
||||
|
||||
const randomSuffix = suffix || compose.appName || generateRandomHash();
|
||||
|
||||
const newComposeFile = addAppNameToPreventCollision(
|
||||
composeData,
|
||||
randomSuffix,
|
||||
compose.isolatedDeploymentsVolume,
|
||||
);
|
||||
const newComposeFile = compose.isolatedDeployment
|
||||
? addAppNameToPreventCollision(
|
||||
composeData,
|
||||
randomSuffix,
|
||||
compose.isolatedDeploymentsVolume,
|
||||
)
|
||||
: composeData;
|
||||
|
||||
return dump(newComposeFile);
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
import _ from "lodash";
|
||||
import type { ComposeSpecification, DefinitionsService } from "../types";
|
||||
|
||||
type DependsOnObject = NonNullable<
|
||||
Exclude<DefinitionsService["depends_on"], string[]> extends infer T
|
||||
? { [K in keyof T]: T[K] }
|
||||
|
||||
@@ -254,6 +254,9 @@ export const addDomainToCompose = async (
|
||||
if (!labels.includes("traefik.docker.network=dokploy-network")) {
|
||||
labels.unshift("traefik.docker.network=dokploy-network");
|
||||
}
|
||||
if (!labels.includes("traefik.swarm.network=dokploy-network")) {
|
||||
labels.unshift("traefik.swarm.network=dokploy-network");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -259,20 +259,51 @@ export const removeService = async (
|
||||
export const prepareEnvironmentVariables = (
|
||||
serviceEnv: string | null,
|
||||
projectEnv?: string | null,
|
||||
environmentEnv?: string | null,
|
||||
) => {
|
||||
const projectVars = parse(projectEnv ?? "");
|
||||
const environmentVars = parse(environmentEnv ?? "");
|
||||
const serviceVars = parse(serviceEnv ?? "");
|
||||
|
||||
const resolvedVars = Object.entries(serviceVars).map(([key, value]) => {
|
||||
let resolvedValue = value;
|
||||
|
||||
// Replace project variables
|
||||
if (projectVars) {
|
||||
resolvedValue = value.replace(/\$\{\{project\.(.*?)\}\}/g, (_, ref) => {
|
||||
if (projectVars[ref] !== undefined) {
|
||||
return projectVars[ref];
|
||||
}
|
||||
throw new Error(`Invalid project environment variable: project.${ref}`);
|
||||
});
|
||||
resolvedValue = resolvedValue.replace(
|
||||
/\$\{\{project\.(.*?)\}\}/g,
|
||||
(_, ref) => {
|
||||
if (projectVars[ref] !== undefined) {
|
||||
return projectVars[ref];
|
||||
}
|
||||
throw new Error(
|
||||
`Invalid project environment variable: project.${ref}`,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Replace environment variables
|
||||
if (environmentVars) {
|
||||
resolvedValue = resolvedValue.replace(
|
||||
/\$\{\{environment\.(.*?)\}\}/g,
|
||||
(_, ref) => {
|
||||
if (environmentVars[ref] !== undefined) {
|
||||
return environmentVars[ref];
|
||||
}
|
||||
throw new Error(`Invalid environment variable: environment.${ref}`);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Replace self-references (service variables)
|
||||
resolvedValue = resolvedValue.replace(/\$\{\{(.*?)\}\}/g, (_, ref) => {
|
||||
if (serviceVars[ref] !== undefined) {
|
||||
return serviceVars[ref];
|
||||
}
|
||||
throw new Error(`Invalid service environment variable: ${ref}`);
|
||||
});
|
||||
|
||||
return `${key}=${resolvedValue}`;
|
||||
});
|
||||
|
||||
@@ -293,8 +324,9 @@ export const parseEnvironmentKeyValuePair = (
|
||||
export const getEnviromentVariablesObject = (
|
||||
input: string | null,
|
||||
projectEnv?: string | null,
|
||||
environmentEnv?: string | null,
|
||||
) => {
|
||||
const envs = prepareEnvironmentVariables(input, projectEnv);
|
||||
const envs = prepareEnvironmentVariables(input, projectEnv, environmentEnv);
|
||||
|
||||
const jsonObject: Record<string, string> = {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user