A few fixes to containers and apps, also added remove app
This commit is contained in:
@@ -72,3 +72,14 @@ export async function setEnv(appId: string, variables: EnvVariable[]) {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export async function removeApp(appId: string) {
|
||||
const nodes = await getNodes();
|
||||
|
||||
nodes.forEach(async (n) => {
|
||||
await axios.delete(`http://${n.ip}:3000/api/applications`, {
|
||||
params: { appId },
|
||||
headers: { Authorization: `ApiKey ${n.key}` },
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ export async function getContainerStats(
|
||||
headers: { Authorization: `ApiKey ${n.key}` },
|
||||
params: { containerId },
|
||||
})
|
||||
).data
|
||||
).data?.stats
|
||||
)
|
||||
)
|
||||
).find((s) => s);
|
||||
|
||||
@@ -164,3 +164,11 @@ export async function setEnv(appId: string, variables: EnvVariable[]) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export async function removeApp(appId: string) {
|
||||
const imageTag = `dockship/${appId}:latest`;
|
||||
const image = docker.getImage(imageTag);
|
||||
await image.remove();
|
||||
const appPath = path.join(DATA_DIR, appId);
|
||||
fs.rmSync(appPath, { recursive: true });
|
||||
}
|
||||
|
||||
@@ -15,7 +15,15 @@ export async function getDocker() {
|
||||
export async function getContainerStats(
|
||||
containerId: string
|
||||
): Promise<SimpleStats | undefined> {
|
||||
const stats = await docker.getContainer(containerId).stats({ stream: false });
|
||||
const container = docker.getContainer(containerId);
|
||||
|
||||
const data = await container.inspect();
|
||||
|
||||
if (!data.State.Running) {
|
||||
return;
|
||||
}
|
||||
|
||||
const stats = await container.stats({ stream: false });
|
||||
|
||||
return {
|
||||
cpu: CPUusage(stats),
|
||||
|
||||
Reference in New Issue
Block a user