MCPcopy
hub / github.com/Dokploy/dokploy / prepareEnvironmentVariables

Function prepareEnvironmentVariables

packages/server/src/utils/docker/utils.ts:399–451  ·  view source on GitHub ↗
(
	serviceEnv: string | null,
	projectEnv?: string | null,
	environmentEnv?: string | null,
)

Source from the content-addressed store, hash-verified

397};
398
399export const prepareEnvironmentVariables = (
400 serviceEnv: string | null,
401 projectEnv?: string | null,
402 environmentEnv?: string | null,
403) => {
404 const projectVars = parse(projectEnv ?? "");
405 const environmentVars = parse(environmentEnv ?? "");
406 const serviceVars = parse(serviceEnv ?? "");
407
408 const resolvedVars = Object.entries(serviceVars).map(([key, value]) => {
409 let resolvedValue = value;
410
411 // Replace project variables
412 if (projectVars) {
413 resolvedValue = resolvedValue.replace(
414 /\$\{\{project\.(.*?)\}\}/g,
415 (_, ref) => {
416 if (projectVars[ref] !== undefined) {
417 return projectVars[ref];
418 }
419 throw new Error(
420 `Invalid project environment variable: project.${ref}`,
421 );
422 },
423 );
424 }
425
426 // Replace environment variables
427 if (environmentVars) {
428 resolvedValue = resolvedValue.replace(
429 /\$\{\{environment\.(.*?)\}\}/g,
430 (_, ref) => {
431 if (environmentVars[ref] !== undefined) {
432 return environmentVars[ref];
433 }
434 throw new Error(`Invalid environment variable: environment.${ref}`);
435 },
436 );
437 }
438
439 // Replace self-references (service variables)
440 resolvedValue = resolvedValue.replace(/\$\{\{(.*?)\}\}/g, (_, ref) => {
441 if (serviceVars[ref] !== undefined) {
442 return serviceVars[ref];
443 }
444 throw new Error(`Invalid service environment variable: ${ref}`);
445 });
446
447 return `${key}=${resolvedValue}`;
448 });
449
450 return resolvedVars;
451};
452
453export const prepareEnvironmentVariablesForShell = (
454 serviceEnv: string | null,

Callers 15

mechanizeDockerContainerFunction · 0.90
getRailpackCommandFunction · 0.90
getCreateEnvFileCommandFunction · 0.90
createEnvFileCommandFunction · 0.90
buildMysqlFunction · 0.90
buildMongoFunction · 0.90
buildRedisFunction · 0.90
buildLibsqlFunction · 0.90
buildPostgresFunction · 0.90
buildMariadbFunction · 0.90
rollbackApplicationFunction · 0.90
settings.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected