Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deploy delete implementation done #37

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { spawn } from 'child_process';
import colors from 'colors';
import { NextFunction, Request, Response } from 'express';
import * as fs from 'fs';
import { hostname } from 'os';
import * as path from 'path';

Expand All @@ -11,6 +12,7 @@ import {
childProcessResponse,
cps,
currentFile,
deleteBody,
deployBody,
fetchBranchListBody,
fetchFilesFromRepoBody,
Expand Down Expand Up @@ -253,6 +255,34 @@ export const showLogs = (req: Request, res: Response): Response => {
return res.send('Demo Logs...');
};

export const deployDelete = (
req: Omit<Request, 'body'> & { body: deleteBody },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

res: Response,
next: NextFunction
): void => {
const { suffix: appName } = req.body;

try {
if (cps[appName]) {
cps[appName].kill();
delete cps[appName];
}

const appPath = path.join(appsDir, appName);

if (fs.existsSync(appPath)) {
fs.rmdirSync(appPath, { recursive: true });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recursive: true will not work with higher node versions such as node:18x, it will be ignored as its deprecated, use the correct thing.

}
delete allApplications[appName];

res.send(`Deleting ${appName} deploy Succeed`);
} catch (error) {
next(
new AppError('error occurred in deleting repository directory', 500)
);
}
};

export const validateAndDeployEnabled = (
req: Request,
res: Response
Expand Down
2 changes: 2 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ app.post('/api/deploy/logs', api.showLogs);

app.post('/api/deploy/create', api.deploy);

app.post('/api/deploy/delete', api.deployDelete);

app.get('/api/inspect', (req, res) => {
res.send(Object.values(allApplications));
});
Expand Down
4 changes: 4 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,7 @@ export interface childProcessResponse {
type: keyof typeof protocol;
data: unknown;
}

export interface deleteBody {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incomplete schema of delete payload.

suffix: string;
}
Loading