Prune after deployment
This commit is contained in:
+11
-10
@@ -7,7 +7,6 @@ import path from "path";
|
||||
import fs from "fs";
|
||||
import pLimit from "p-limit";
|
||||
import { randomUUID } from "crypto";
|
||||
import simpleGit from "simple-git";
|
||||
import { cloneRepo } from "./git";
|
||||
|
||||
const docker = new Docker();
|
||||
@@ -35,7 +34,7 @@ function formatPorts(ports: Port[]) {
|
||||
}
|
||||
|
||||
export async function getDeployments(
|
||||
apps: Application[]
|
||||
apps: Application[],
|
||||
): Promise<Deployment[]> {
|
||||
const limit = pLimit(5);
|
||||
|
||||
@@ -91,27 +90,27 @@ export async function getDeployments(
|
||||
status: containerInfo.State?.Running ? "running" : "stopped",
|
||||
ports: [...ports.entries()].map(
|
||||
([publicPort, privatePort]) =>
|
||||
[publicPort, privatePort] as [number, number]
|
||||
[publicPort, privatePort] as [number, number],
|
||||
),
|
||||
};
|
||||
} catch {
|
||||
// Container may have stopped / been removed
|
||||
return null;
|
||||
}
|
||||
})
|
||||
)
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
// Remove failed containers
|
||||
return results.filter(
|
||||
(deployment: any): deployment is Deployment => deployment !== null
|
||||
(deployment: any): deployment is Deployment => deployment !== null,
|
||||
);
|
||||
}
|
||||
|
||||
export async function deployApp(
|
||||
name: string,
|
||||
app: Application,
|
||||
ports: Port[]
|
||||
ports: Port[],
|
||||
): Promise<string | undefined> {
|
||||
const deployId = randomUUID();
|
||||
const deployPath = path.join("data", "deploys", deployId);
|
||||
@@ -134,12 +133,12 @@ export async function deployApp(
|
||||
context: deployPath,
|
||||
src: ["Dockerfile", "."],
|
||||
},
|
||||
{ t: imageTag }
|
||||
{ t: imageTag },
|
||||
);
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
docker.modem.followProgress(stream, (err: Error | null) =>
|
||||
err ? reject(err) : resolve()
|
||||
err ? reject(err) : resolve(),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -152,12 +151,14 @@ export async function deployApp(
|
||||
PortBindings: formatPorts(ports),
|
||||
},
|
||||
Env: Object.entries(app.env).map(
|
||||
([key, { value }]) => `${key}="${value.replaceAll('"', '\\"')}"`
|
||||
([key, { value }]) => `${key}="${value.replaceAll('"', '\\"')}"`,
|
||||
),
|
||||
});
|
||||
|
||||
await container.start();
|
||||
|
||||
await docker.pruneImages();
|
||||
|
||||
return container.id;
|
||||
} catch (err) {
|
||||
console.error("Failed to deploy app:", err);
|
||||
|
||||
Reference in New Issue
Block a user