mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Enhance environment variable handling in processTemplate: support boolean and number types in env configuration, with tests for both array and object formats.
This commit is contained in:
@@ -233,6 +233,49 @@ describe("processTemplate", () => {
|
|||||||
expect(base64Value.length).toBeGreaterThanOrEqual(42);
|
expect(base64Value.length).toBeGreaterThanOrEqual(42);
|
||||||
expect(base64Value.length).toBeLessThanOrEqual(44);
|
expect(base64Value.length).toBeLessThanOrEqual(44);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should handle boolean values in env vars when provided as an array", () => {
|
||||||
|
const template: CompleteTemplate = {
|
||||||
|
metadata: {} as any,
|
||||||
|
variables: {},
|
||||||
|
config: {
|
||||||
|
domains: [],
|
||||||
|
env: [
|
||||||
|
"ENABLE_USER_SIGN_UP=false",
|
||||||
|
"DEBUG_MODE=true",
|
||||||
|
"SOME_NUMBER=42",
|
||||||
|
],
|
||||||
|
mounts: [],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = processTemplate(template, mockSchema);
|
||||||
|
expect(result.envs).toHaveLength(3);
|
||||||
|
expect(result.envs).toContain("ENABLE_USER_SIGN_UP=false");
|
||||||
|
expect(result.envs).toContain("DEBUG_MODE=true");
|
||||||
|
expect(result.envs).toContain("SOME_NUMBER=42");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle boolean values in env vars when provided as an object", () => {
|
||||||
|
const template: CompleteTemplate = {
|
||||||
|
metadata: {} as any,
|
||||||
|
variables: {},
|
||||||
|
config: {
|
||||||
|
domains: [],
|
||||||
|
env: {
|
||||||
|
ENABLE_USER_SIGN_UP: false,
|
||||||
|
DEBUG_MODE: true,
|
||||||
|
SOME_NUMBER: 42,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = processTemplate(template, mockSchema);
|
||||||
|
expect(result.envs).toHaveLength(3);
|
||||||
|
expect(result.envs).toContain("ENABLE_USER_SIGN_UP=false");
|
||||||
|
expect(result.envs).toContain("DEBUG_MODE=true");
|
||||||
|
expect(result.envs).toContain("SOME_NUMBER=42");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("mounts processing", () => {
|
describe("mounts processing", () => {
|
||||||
|
|||||||
@@ -45,7 +45,9 @@ export interface CompleteTemplate {
|
|||||||
variables: Record<string, string>;
|
variables: Record<string, string>;
|
||||||
config: {
|
config: {
|
||||||
domains: DomainConfig[];
|
domains: DomainConfig[];
|
||||||
env: Record<string, string> | string[];
|
env:
|
||||||
|
| Record<string, string | boolean | number>
|
||||||
|
| (string | Record<string, string | boolean | number>)[];
|
||||||
mounts?: MountConfig[];
|
mounts?: MountConfig[];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -200,7 +202,16 @@ export function processEnvVars(
|
|||||||
if (typeof env === "string") {
|
if (typeof env === "string") {
|
||||||
return processValue(env, variables, schema);
|
return processValue(env, variables, schema);
|
||||||
}
|
}
|
||||||
return env;
|
// Si es un objeto, asumimos que es un par clave-valor
|
||||||
|
if (typeof env === "object" && env !== null) {
|
||||||
|
const keys = Object.keys(env);
|
||||||
|
if (keys.length > 0) {
|
||||||
|
const key = keys[0];
|
||||||
|
return `${key}=${env[key as keyof typeof env]}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Para valores primitivos (boolean, number)
|
||||||
|
return String(env);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user