mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor(domains): update labels
This commit is contained in:
@@ -91,6 +91,7 @@ export const findComposeById = async (composeId: string) => {
|
|||||||
project: true,
|
project: true,
|
||||||
deployments: true,
|
deployments: true,
|
||||||
mounts: true,
|
mounts: true,
|
||||||
|
domains: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
|||||||
@@ -8,20 +8,28 @@ import { dirname, join } from "node:path";
|
|||||||
import { COMPOSE_PATH } from "@/server/constants";
|
import { COMPOSE_PATH } from "@/server/constants";
|
||||||
import type { InferResultType } from "@/server/types/with";
|
import type { InferResultType } from "@/server/types/with";
|
||||||
import boxen from "boxen";
|
import boxen from "boxen";
|
||||||
|
import { writeDomainsToCompose } from "../docker/domain";
|
||||||
import { prepareEnvironmentVariables } from "../docker/utils";
|
import { prepareEnvironmentVariables } from "../docker/utils";
|
||||||
import { spawnAsync } from "../process/spawnAsync";
|
import { spawnAsync } from "../process/spawnAsync";
|
||||||
|
|
||||||
export type ComposeNested = InferResultType<
|
export type ComposeNested = InferResultType<
|
||||||
"compose",
|
"compose",
|
||||||
{ project: true; mounts: true }
|
{ project: true; mounts: true; domains: true }
|
||||||
>;
|
>;
|
||||||
export const buildCompose = async (compose: ComposeNested, logPath: string) => {
|
export const buildCompose = async (compose: ComposeNested, logPath: string) => {
|
||||||
const writeStream = createWriteStream(logPath, { flags: "a" });
|
const writeStream = createWriteStream(logPath, { flags: "a" });
|
||||||
const { sourceType, appName, mounts, composeType, env, composePath } =
|
const {
|
||||||
compose;
|
sourceType,
|
||||||
|
appName,
|
||||||
|
mounts,
|
||||||
|
composeType,
|
||||||
|
env,
|
||||||
|
composePath,
|
||||||
|
domains,
|
||||||
|
} = compose;
|
||||||
try {
|
try {
|
||||||
const command = createCommand(compose);
|
const command = createCommand(compose);
|
||||||
|
await writeDomainsToCompose(compose, domains);
|
||||||
createEnvFile(compose);
|
createEnvFile(compose);
|
||||||
|
|
||||||
const logContent = `
|
const logContent = `
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import fs, { existsSync, readFileSync } from "node:fs";
|
import fs, { existsSync, readFileSync, writeSync } from "node:fs";
|
||||||
|
import { writeFile } from "node:fs/promises";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import type { Compose } from "@/server/api/services/compose";
|
import type { Compose } from "@/server/api/services/compose";
|
||||||
import type { Domain } from "@/server/api/services/domain";
|
import type { Domain } from "@/server/api/services/domain";
|
||||||
@@ -8,6 +9,7 @@ import { cloneGitRawRepository } from "../providers/git";
|
|||||||
import { cloneRawGithubRepository } from "../providers/github";
|
import { cloneRawGithubRepository } from "../providers/github";
|
||||||
import { createComposeFileRaw } from "../providers/raw";
|
import { createComposeFileRaw } from "../providers/raw";
|
||||||
import type { ComposeSpecification } from "./types";
|
import type { ComposeSpecification } from "./types";
|
||||||
|
|
||||||
export const cloneCompose = async (compose: Compose) => {
|
export const cloneCompose = async (compose: Compose) => {
|
||||||
if (compose.sourceType === "github") {
|
if (compose.sourceType === "github") {
|
||||||
await cloneRawGithubRepository(compose);
|
await cloneRawGithubRepository(compose);
|
||||||
@@ -53,6 +55,24 @@ export const readComposeFile = async (compose: Compose) => {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const writeDomainsToCompose = async (
|
||||||
|
compose: Compose,
|
||||||
|
domains: Domain[],
|
||||||
|
) => {
|
||||||
|
if (!domains.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const composeConverted = await addDomainToCompose(compose, domains);
|
||||||
|
|
||||||
|
const path = getComposePath(compose);
|
||||||
|
const composeString = dump(composeConverted, { lineWidth: 1000 });
|
||||||
|
try {
|
||||||
|
await writeFile(path, composeString, "utf8");
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const addDomainToCompose = async (
|
export const addDomainToCompose = async (
|
||||||
compose: Compose,
|
compose: Compose,
|
||||||
domains: Domain[],
|
domains: Domain[],
|
||||||
@@ -125,7 +145,7 @@ export const createDomainLabels = async (
|
|||||||
const { host, port, https, uniqueConfigKey, certificateType } = domain;
|
const { host, port, https, uniqueConfigKey, certificateType } = domain;
|
||||||
|
|
||||||
const labels = [
|
const labels = [
|
||||||
`traefik.http.routers.${appName}-${uniqueConfigKey}-${entrypoint}.ruleHost(\`${host}\`)`,
|
`traefik.http.routers.${appName}-${uniqueConfigKey}-${entrypoint}.rule=Host(\`${host}\`)`,
|
||||||
`traefik.http.services.${appName}-${uniqueConfigKey}-${entrypoint}.loadbalancer.server.port=${port}`,
|
`traefik.http.services.${appName}-${uniqueConfigKey}-${entrypoint}.loadbalancer.server.port=${port}`,
|
||||||
`traefik.http.routers.${appName}-${uniqueConfigKey}-${entrypoint}.entrypoints=${entrypoint}`,
|
`traefik.http.routers.${appName}-${uniqueConfigKey}-${entrypoint}.entrypoints=${entrypoint}`,
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user