mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
feat: added env support for dokploy
This commit is contained in:
@@ -185,18 +185,12 @@ const Service = (
|
|||||||
<div className="flex flex-row items-center justify-between w-full gap-4">
|
<div className="flex flex-row items-center justify-between w-full gap-4">
|
||||||
<TabsList
|
<TabsList
|
||||||
className={cn(
|
className={cn(
|
||||||
"md:grid md:w-fit max-md:overflow-y-scroll justify-start",
|
"md:grid md:w-fit max-md:overflow-y-scroll justify-start md:grid-cols-6",
|
||||||
data?.serverId ? "md:grid-cols-6" : "md:grid-cols-7",
|
data?.serverId ? "md:grid-cols-6" : "md:grid-cols-7",
|
||||||
data?.composeType === "docker-compose" ? "" : "md:grid-cols-6",
|
|
||||||
data?.serverId && data?.composeType === "stack"
|
|
||||||
? "md:grid-cols-5"
|
|
||||||
: "",
|
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<TabsTrigger value="general">General</TabsTrigger>
|
<TabsTrigger value="general">General</TabsTrigger>
|
||||||
{data?.composeType === "docker-compose" && (
|
<TabsTrigger value="environment">Environment</TabsTrigger>
|
||||||
<TabsTrigger value="environment">Environment</TabsTrigger>
|
|
||||||
)}
|
|
||||||
{!data?.serverId && (
|
{!data?.serverId && (
|
||||||
<TabsTrigger value="monitoring">Monitoring</TabsTrigger>
|
<TabsTrigger value="monitoring">Monitoring</TabsTrigger>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ import {
|
|||||||
createWriteStream,
|
createWriteStream,
|
||||||
existsSync,
|
existsSync,
|
||||||
mkdirSync,
|
mkdirSync,
|
||||||
|
readFileSync,
|
||||||
writeFileSync,
|
writeFileSync,
|
||||||
} from "node:fs";
|
} from "node:fs";
|
||||||
import { dirname, join } from "node:path";
|
import { dirname, join } from "node:path";
|
||||||
import { paths } from "@dokploy/server/constants";
|
import { paths } from "@dokploy/server/constants";
|
||||||
import type { InferResultType } from "@dokploy/server/types/with";
|
import type { InferResultType } from "@dokploy/server/types/with";
|
||||||
import boxen from "boxen";
|
import boxen from "boxen";
|
||||||
|
import dotenv from "dotenv";
|
||||||
import {
|
import {
|
||||||
writeDomainsToCompose,
|
writeDomainsToCompose,
|
||||||
writeDomainsToComposeRemote,
|
writeDomainsToComposeRemote,
|
||||||
@@ -28,6 +30,7 @@ export const buildCompose = async (compose: ComposeNested, logPath: string) => {
|
|||||||
const command = createCommand(compose);
|
const command = createCommand(compose);
|
||||||
await writeDomainsToCompose(compose, domains);
|
await writeDomainsToCompose(compose, domains);
|
||||||
createEnvFile(compose);
|
createEnvFile(compose);
|
||||||
|
processComposeFile(compose);
|
||||||
|
|
||||||
const logContent = `
|
const logContent = `
|
||||||
App Name: ${appName}
|
App Name: ${appName}
|
||||||
@@ -84,6 +87,7 @@ export const getBuildComposeCommand = async (
|
|||||||
const command = createCommand(compose);
|
const command = createCommand(compose);
|
||||||
const envCommand = getCreateEnvFileCommand(compose);
|
const envCommand = getCreateEnvFileCommand(compose);
|
||||||
const projectPath = join(COMPOSE_PATH, compose.appName, "code");
|
const projectPath = join(COMPOSE_PATH, compose.appName, "code");
|
||||||
|
const processComposeFileCommand = getProcessComposeFileCommand(compose);
|
||||||
|
|
||||||
const newCompose = await writeDomainsToComposeRemote(
|
const newCompose = await writeDomainsToComposeRemote(
|
||||||
compose,
|
compose,
|
||||||
@@ -119,6 +123,8 @@ Compose Type: ${composeType} ✅`;
|
|||||||
|
|
||||||
cd "${projectPath}";
|
cd "${projectPath}";
|
||||||
|
|
||||||
|
${processComposeFileCommand}
|
||||||
|
|
||||||
docker ${command.split(" ").join(" ")} >> "${logPath}" 2>&1 || { echo "Error: ❌ Docker command failed" >> "${logPath}"; exit 1; }
|
docker ${command.split(" ").join(" ")} >> "${logPath}" 2>&1 || { echo "Error: ❌ Docker command failed" >> "${logPath}"; exit 1; }
|
||||||
|
|
||||||
echo "Docker Compose Deployed: ✅" >> "${logPath}"
|
echo "Docker Compose Deployed: ✅" >> "${logPath}"
|
||||||
@@ -145,7 +151,7 @@ export const createCommand = (compose: ComposeNested) => {
|
|||||||
const { composeType, appName, sourceType } = compose;
|
const { composeType, appName, sourceType } = compose;
|
||||||
|
|
||||||
const path =
|
const path =
|
||||||
sourceType === "raw" ? "docker-compose.yml" : compose.composePath;
|
sourceType === "raw" ? "docker-compose.processed.yml" : compose.composePath;
|
||||||
let command = "";
|
let command = "";
|
||||||
|
|
||||||
if (composeType === "docker-compose") {
|
if (composeType === "docker-compose") {
|
||||||
@@ -188,6 +194,46 @@ const createEnvFile = (compose: ComposeNested) => {
|
|||||||
writeFileSync(envFilePath, envFileContent);
|
writeFileSync(envFilePath, envFileContent);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const processComposeFile = (compose: ComposeNested) => {
|
||||||
|
const { COMPOSE_PATH } = paths();
|
||||||
|
const { env, appName, sourceType, composeType } = compose;
|
||||||
|
|
||||||
|
if (composeType === "stack") {
|
||||||
|
const inputPath =
|
||||||
|
sourceType === "raw" ? "docker-compose.yml" : compose.composePath;
|
||||||
|
const composeInputFilePath =
|
||||||
|
join(COMPOSE_PATH, appName, "code", inputPath) ||
|
||||||
|
join(COMPOSE_PATH, appName, "code", "docker-compose.yml");
|
||||||
|
|
||||||
|
const outputPath = "docker-compose.processed.yml";
|
||||||
|
const composeOutputFilePath =
|
||||||
|
join(COMPOSE_PATH, appName, "code", outputPath) ||
|
||||||
|
join(COMPOSE_PATH, appName, "code", "docker-compose.processed.yml");
|
||||||
|
|
||||||
|
const envContent = prepareEnvironmentVariables(env || "").join("\n");
|
||||||
|
const envVariables = dotenv.parse(envContent);
|
||||||
|
|
||||||
|
let templateContent = readFileSync(composeInputFilePath, "utf8");
|
||||||
|
|
||||||
|
templateContent = templateContent.replace(
|
||||||
|
/\$\{([^}]+)\}/g,
|
||||||
|
(_, varName) => {
|
||||||
|
return envVariables[varName] || "";
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
writeFileSync(composeOutputFilePath, templateContent);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getProcessComposeFileCommand = (compose: ComposeNested) => {
|
||||||
|
const { composeType } = compose;
|
||||||
|
if (composeType === "stack") {
|
||||||
|
return "set -a; source .env; set +a; envsubst < docker-compose.yml > docker-compose.processed.yml";
|
||||||
|
}
|
||||||
|
return "cp docker-compose.yml docker-compose.processed.yml";
|
||||||
|
};
|
||||||
|
|
||||||
export const getCreateEnvFileCommand = (compose: ComposeNested) => {
|
export const getCreateEnvFileCommand = (compose: ComposeNested) => {
|
||||||
const { COMPOSE_PATH } = paths(true);
|
const { COMPOSE_PATH } = paths(true);
|
||||||
const { env, composePath, appName } = compose;
|
const { env, composePath, appName } = compose;
|
||||||
|
|||||||
Reference in New Issue
Block a user