mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-05 03:32:16 +00:00
Refactor application and compose deployment logic: remove unused buildApplication function, streamline command logging for deployment, and enhance static command generation for improved maintainability and clarity in the codebase.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { createWriteStream } from "node:fs";
|
||||
import type { InferResultType } from "@dokploy/server/types/with";
|
||||
import type { CreateServiceOptions } from "dockerode";
|
||||
import { uploadImage, uploadImageRemoteCommand } from "../cluster/upload";
|
||||
import { uploadImageRemoteCommand } from "../cluster/upload";
|
||||
import {
|
||||
calculateResources,
|
||||
generateBindMounts,
|
||||
@@ -34,48 +33,6 @@ export type ApplicationNested = InferResultType<
|
||||
}
|
||||
>;
|
||||
|
||||
export const buildApplication = async (
|
||||
application: ApplicationNested,
|
||||
logPath: string,
|
||||
) => {
|
||||
const writeStream = createWriteStream(logPath, { flags: "a" });
|
||||
const { buildType, sourceType } = application;
|
||||
try {
|
||||
writeStream.write(
|
||||
`\nBuild ${buildType}: ✅\nSource Type: ${sourceType}: ✅\n`,
|
||||
);
|
||||
console.log(`Build ${buildType}: ✅`);
|
||||
// if (buildType === "nixpacks") {
|
||||
// await buildNixpacks(application, writeStream);
|
||||
// } else if (buildType === "heroku_buildpacks") {
|
||||
// await buildHeroku(application, writeStream);
|
||||
// } else if (buildType === "paketo_buildpacks") {
|
||||
// await buildPaketo(application, writeStream);
|
||||
// } else if (buildType === "dockerfile") {
|
||||
// await buildCustomDocker(application, writeStream);
|
||||
// } else if (buildType === "static") {
|
||||
// await buildStatic(application, writeStream);
|
||||
// } else if (buildType === "railpack") {
|
||||
// await buildRailpack(application, writeStream);
|
||||
// }
|
||||
|
||||
if (application.registryId) {
|
||||
await uploadImage(application, writeStream);
|
||||
}
|
||||
await mechanizeDockerContainer(application);
|
||||
writeStream.write("Docker Deployed: ✅");
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
writeStream.write(`Error ❌\n${error?.message}`);
|
||||
} else {
|
||||
writeStream.write("Error ❌");
|
||||
}
|
||||
throw error;
|
||||
} finally {
|
||||
writeStream.end();
|
||||
}
|
||||
};
|
||||
|
||||
export const getBuildCommand = (application: ApplicationNested) => {
|
||||
let command = "";
|
||||
const { buildType, registry } = application;
|
||||
|
||||
@@ -29,16 +29,32 @@ http {
|
||||
`;
|
||||
|
||||
export const getStaticCommand = (application: ApplicationNested) => {
|
||||
const { publishDirectory } = application;
|
||||
const { publishDirectory, isStaticSpa } = application;
|
||||
const buildAppDirectory = getBuildAppDirectory(application);
|
||||
let command = "";
|
||||
if (isStaticSpa) {
|
||||
command += getCreateFileCommand(
|
||||
buildAppDirectory,
|
||||
"nginx.conf",
|
||||
nginxSpaConfig,
|
||||
);
|
||||
}
|
||||
|
||||
let command = getCreateFileCommand(
|
||||
command += getCreateFileCommand(
|
||||
buildAppDirectory,
|
||||
".dockerignore",
|
||||
[".git", ".env", "Dockerfile", ".dockerignore"].join("\n"),
|
||||
);
|
||||
|
||||
command += getCreateFileCommand(
|
||||
buildAppDirectory,
|
||||
"Dockerfile",
|
||||
[
|
||||
"FROM nginx:alpine",
|
||||
"WORKDIR /usr/share/nginx/html/",
|
||||
isStaticSpa ? "COPY nginx.conf /etc/nginx/nginx.conf" : "",
|
||||
`COPY ${publishDirectory || "."} .`,
|
||||
'CMD ["nginx", "-g", "daemon off;"]',
|
||||
].join("\n"),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user