Compare commits

..

7 Commits

Author SHA1 Message Date
Mauricio Siu
0e136ffb8f Merge pull request #632 from Dokploy/canary
v10.7.0
2024-10-30 23:10:48 -06:00
Mauricio Siu
95e53169b1 chore(version): bump version 2024-10-30 23:07:05 -06:00
Mauricio Siu
6b4e52fb37 Merge pull request #631 from Dokploy/canary
v0.10.6
2024-10-30 23:00:45 -06:00
Mauricio Siu
52a19a325e chore(version): bump version 2024-10-30 22:52:31 -06:00
Mauricio Siu
9d891e87e0 Merge pull request #630 from Dokploy/fix/delete-old-deployments
fix(dokploy): remove old deployments
2024-10-30 22:52:08 -06:00
Mauricio Siu
41b274fbb3 refactor(dokploy): set condition to 10 2024-10-30 22:50:12 -06:00
Mauricio Siu
6417e13336 fix(dokploy): remove old deployments 2024-10-30 22:44:01 -06:00
3 changed files with 59 additions and 18 deletions

View File

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

View File

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

View File

@@ -43,7 +43,7 @@ export const generatePassword = (quantity = 16): string => {
Math.floor(Math.random() * characters.length),
);
}
return password;
return password.toLowerCase();
};
export const generateBase64 = (bytes = 32): string => {