mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
feat(templates): support array-based environment variable configuration
Add support for processing environment variables defined as an array in template configurations, allowing more flexible env var definitions with direct string values and variable interpolation
This commit is contained in:
@@ -169,6 +169,32 @@ describe("processTemplate", () => {
|
|||||||
expect(secretKey.split("=")[1]).toHaveLength(64);
|
expect(secretKey.split("=")[1]).toHaveLength(64);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should process env vars when provided as an array", () => {
|
||||||
|
const template: CompleteTemplate = {
|
||||||
|
metadata: {} as any,
|
||||||
|
variables: {},
|
||||||
|
config: {
|
||||||
|
domains: [],
|
||||||
|
env: [
|
||||||
|
'CLOUDFLARE_TUNNEL_TOKEN="<INSERT TOKEN>"',
|
||||||
|
'ANOTHER_VAR="some value"',
|
||||||
|
"DOMAIN=${domain}",
|
||||||
|
],
|
||||||
|
mounts: [],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = processTemplate(template, mockSchema);
|
||||||
|
expect(result.envs).toHaveLength(3);
|
||||||
|
|
||||||
|
// Should preserve exact format for static values
|
||||||
|
expect(result.envs[0]).toBe('CLOUDFLARE_TUNNEL_TOKEN="<INSERT TOKEN>"');
|
||||||
|
expect(result.envs[1]).toBe('ANOTHER_VAR="some value"');
|
||||||
|
|
||||||
|
// Should process variables in array items
|
||||||
|
expect(result.envs[2]).toContain(mockSchema.projectName);
|
||||||
|
});
|
||||||
|
|
||||||
it("should allow using utility functions directly in env vars", () => {
|
it("should allow using utility functions directly in env vars", () => {
|
||||||
const template: CompleteTemplate = {
|
const template: CompleteTemplate = {
|
||||||
metadata: {} as any,
|
metadata: {} as any,
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export interface CompleteTemplate {
|
|||||||
variables: Record<string, string>;
|
variables: Record<string, string>;
|
||||||
config: {
|
config: {
|
||||||
domains: DomainConfig[];
|
domains: DomainConfig[];
|
||||||
env: Record<string, string>;
|
env: Record<string, string> | string[];
|
||||||
mounts?: MountConfig[];
|
mounts?: MountConfig[];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -175,7 +175,8 @@ export function processDomains(
|
|||||||
variables: Record<string, string>,
|
variables: Record<string, string>,
|
||||||
schema: Schema,
|
schema: Schema,
|
||||||
): Template["domains"] {
|
): Template["domains"] {
|
||||||
return template.config.domains.map((domain: DomainConfig) => ({
|
if (!template?.config?.domains) return [];
|
||||||
|
return template?.config?.domains?.map((domain: DomainConfig) => ({
|
||||||
...domain,
|
...domain,
|
||||||
host: domain.host
|
host: domain.host
|
||||||
? processValue(domain.host, variables, schema)
|
? processValue(domain.host, variables, schema)
|
||||||
@@ -191,6 +192,19 @@ export function processEnvVars(
|
|||||||
variables: Record<string, string>,
|
variables: Record<string, string>,
|
||||||
schema: Schema,
|
schema: Schema,
|
||||||
): Template["envs"] {
|
): Template["envs"] {
|
||||||
|
if (!template?.config?.env) return [];
|
||||||
|
|
||||||
|
// Handle array of env vars
|
||||||
|
if (Array.isArray(template.config.env)) {
|
||||||
|
return template.config.env.map((env) => {
|
||||||
|
if (typeof env === "string") {
|
||||||
|
return processValue(env, variables, schema);
|
||||||
|
}
|
||||||
|
return env;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle object of env vars
|
||||||
return Object.entries(template.config.env).map(
|
return Object.entries(template.config.env).map(
|
||||||
([key, value]: [string, string]) => {
|
([key, value]: [string, string]) => {
|
||||||
const processedValue = processValue(value, variables, schema);
|
const processedValue = processValue(value, variables, schema);
|
||||||
@@ -207,7 +221,7 @@ export function processMounts(
|
|||||||
variables: Record<string, string>,
|
variables: Record<string, string>,
|
||||||
schema: Schema,
|
schema: Schema,
|
||||||
): Template["mounts"] {
|
): Template["mounts"] {
|
||||||
if (!template.config.mounts) return [];
|
if (!template?.config?.mounts) return [];
|
||||||
|
|
||||||
return template.config.mounts.map((mount: MountConfig) => ({
|
return template.config.mounts.map((mount: MountConfig) => ({
|
||||||
filePath: processValue(mount.filePath, variables, schema),
|
filePath: processValue(mount.filePath, variables, schema),
|
||||||
|
|||||||
Reference in New Issue
Block a user