From 3dd6b22c06a0d76e31178ff290d01030624ae662 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Sat, 14 Feb 2026 03:06:54 +0100 Subject: [PATCH] Prune after deployment --- src/core/deployment.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/core/deployment.ts b/src/core/deployment.ts index 99f6e7b..7ffea0d 100644 --- a/src/core/deployment.ts +++ b/src/core/deployment.ts @@ -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 { 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 { 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((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);