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:
parent
dde799f510
commit
9379d4a31d
@ -91,6 +91,7 @@ export const findComposeById = async (composeId: string) => {
|
||||
project: true,
|
||||
deployments: true,
|
||||
mounts: true,
|
||||
domains: true,
|
||||
},
|
||||
});
|
||||
if (!result) {
|
||||
|
@ -8,20 +8,28 @@ import { dirname, join } from "node:path";
|
||||
import { COMPOSE_PATH } from "@/server/constants";
|
||||
import type { InferResultType } from "@/server/types/with";
|
||||
import boxen from "boxen";
|
||||
import { writeDomainsToCompose } from "../docker/domain";
|
||||
import { prepareEnvironmentVariables } from "../docker/utils";
|
||||
import { spawnAsync } from "../process/spawnAsync";
|
||||
|
||||
export type ComposeNested = InferResultType<
|
||||
"compose",
|
||||
{ project: true; mounts: true }
|
||||
{ project: true; mounts: true; domains: true }
|
||||
>;
|
||||
export const buildCompose = async (compose: ComposeNested, logPath: string) => {
|
||||
const writeStream = createWriteStream(logPath, { flags: "a" });
|
||||
const { sourceType, appName, mounts, composeType, env, composePath } =
|
||||
compose;
|
||||
const {
|
||||
sourceType,
|
||||
appName,
|
||||
mounts,
|
||||
composeType,
|
||||
env,
|
||||
composePath,
|
||||
domains,
|
||||
} = compose;
|
||||
try {
|
||||
const command = createCommand(compose);
|
||||
|
||||
await writeDomainsToCompose(compose, domains);
|
||||
createEnvFile(compose);
|
||||
|
||||
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 type { Compose } from "@/server/api/services/compose";
|
||||
import type { Domain } from "@/server/api/services/domain";
|
||||
@ -8,6 +9,7 @@ import { cloneGitRawRepository } from "../providers/git";
|
||||
import { cloneRawGithubRepository } from "../providers/github";
|
||||
import { createComposeFileRaw } from "../providers/raw";
|
||||
import type { ComposeSpecification } from "./types";
|
||||
|
||||
export const cloneCompose = async (compose: Compose) => {
|
||||
if (compose.sourceType === "github") {
|
||||
await cloneRawGithubRepository(compose);
|
||||
@ -53,6 +55,24 @@ export const readComposeFile = async (compose: Compose) => {
|
||||
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 (
|
||||
compose: Compose,
|
||||
domains: Domain[],
|
||||
@ -125,7 +145,7 @@ export const createDomainLabels = async (
|
||||
const { host, port, https, uniqueConfigKey, certificateType } = domain;
|
||||
|
||||
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.routers.${appName}-${uniqueConfigKey}-${entrypoint}.entrypoints=${entrypoint}`,
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user