Merge pull request #631 from Dokploy/canary

v0.10.6
This commit is contained in:
Mauricio Siu
2024-10-30 23:00:45 -06:00
committed by GitHub
2 changed files with 58 additions and 17 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "dokploy", "name": "dokploy",
"version": "v0.10.5", "version": "v0.10.6",
"private": true, "private": true,
"license": "Apache-2.0", "license": "Apache-2.0",
"type": "module", "type": "module",

View File

@@ -49,7 +49,10 @@ export const createDeployment = async (
const application = await findApplicationById(deployment.applicationId); const application = await findApplicationById(deployment.applicationId);
try { try {
// await removeLastTenDeployments(deployment.applicationId); await removeLastTenDeployments(
deployment.applicationId,
application.serverId,
);
const { LOGS_PATH } = paths(!!application.serverId); const { LOGS_PATH } = paths(!!application.serverId);
const formattedDateTime = format(new Date(), "yyyy-MM-dd:HH:mm:ss"); const formattedDateTime = format(new Date(), "yyyy-MM-dd:HH:mm:ss");
const fileName = `${application.appName}-${formattedDateTime}.log`; const fileName = `${application.appName}-${formattedDateTime}.log`;
@@ -106,7 +109,10 @@ export const createDeploymentCompose = async (
) => { ) => {
const compose = await findComposeById(deployment.composeId); const compose = await findComposeById(deployment.composeId);
try { try {
// await removeLastTenComposeDeployments(deployment.composeId); await removeLastTenComposeDeployments(
deployment.composeId,
compose.serverId,
);
const { LOGS_PATH } = paths(!!compose.serverId); const { LOGS_PATH } = paths(!!compose.serverId);
const formattedDateTime = format(new Date(), "yyyy-MM-dd:HH:mm:ss"); const formattedDateTime = format(new Date(), "yyyy-MM-dd:HH:mm:ss");
const fileName = `${compose.appName}-${formattedDateTime}.log`; const fileName = `${compose.appName}-${formattedDateTime}.log`;
@@ -181,36 +187,72 @@ export const removeDeploymentsByApplicationId = async (
.returning(); .returning();
}; };
const removeLastTenDeployments = async (applicationId: string) => { const removeLastTenDeployments = async (
applicationId: string,
serverId: string | null,
) => {
const deploymentList = await db.query.deployments.findMany({ const deploymentList = await db.query.deployments.findMany({
where: eq(deployments.applicationId, applicationId), where: eq(deployments.applicationId, applicationId),
orderBy: desc(deployments.createdAt), orderBy: desc(deployments.createdAt),
}); });
if (deploymentList.length > 10) { if (deploymentList.length > 10) {
const deploymentsToDelete = deploymentList.slice(10); const deploymentsToDelete = deploymentList.slice(10);
for (const oldDeployment of deploymentsToDelete) { if (serverId) {
const logPath = path.join(oldDeployment.logPath); let command = "";
if (existsSync(logPath)) { for (const oldDeployment of deploymentsToDelete) {
await fsPromises.unlink(logPath); const logPath = path.join(oldDeployment.logPath);
command += `
rm -rf ${logPath};
`;
await removeDeployment(oldDeployment.deploymentId);
}
await execAsyncRemote(serverId, command);
} else {
for (const oldDeployment of deploymentsToDelete) {
const logPath = path.join(oldDeployment.logPath);
if (existsSync(logPath)) {
await fsPromises.unlink(logPath);
}
await removeDeployment(oldDeployment.deploymentId);
} }
await removeDeployment(oldDeployment.deploymentId);
} }
} }
}; };
const removeLastTenComposeDeployments = async (composeId: string) => { const removeLastTenComposeDeployments = async (
composeId: string,
serverId: string | null,
) => {
const deploymentList = await db.query.deployments.findMany({ const deploymentList = await db.query.deployments.findMany({
where: eq(deployments.composeId, composeId), where: eq(deployments.composeId, composeId),
orderBy: desc(deployments.createdAt), orderBy: desc(deployments.createdAt),
}); });
if (deploymentList.length > 10) { if (deploymentList.length > 10) {
const deploymentsToDelete = deploymentList.slice(10); if (serverId) {
for (const oldDeployment of deploymentsToDelete) { let command = "";
const logPath = path.join(oldDeployment.logPath); const deploymentsToDelete = deploymentList.slice(10);
if (existsSync(logPath)) { for (const oldDeployment of deploymentsToDelete) {
await fsPromises.unlink(logPath); const logPath = path.join(oldDeployment.logPath);
command += `
rm -rf ${logPath};
`;
await removeDeployment(oldDeployment.deploymentId);
}
await execAsyncRemote(serverId, command);
} else {
const deploymentsToDelete = deploymentList.slice(10);
for (const oldDeployment of deploymentsToDelete) {
const logPath = path.join(oldDeployment.logPath);
if (existsSync(logPath)) {
await fsPromises.unlink(logPath);
}
await removeDeployment(oldDeployment.deploymentId);
} }
await removeDeployment(oldDeployment.deploymentId);
} }
} }
}; };
@@ -327,7 +369,6 @@ export const createServerDeployment = async (
} }
return deploymentCreate[0]; return deploymentCreate[0];
} catch (error) { } catch (error) {
console.log(error);
throw new TRPCError({ throw new TRPCError({
code: "BAD_REQUEST", code: "BAD_REQUEST",
message: "Error to create the deployment", message: "Error to create the deployment",