From 55e1b386df8edba63ba8ea4f0fb55c6e65fad524 Mon Sep 17 00:00:00 2001 From: flydog98 Date: Mon, 18 Dec 2023 23:30:38 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=BB=A8=ED=85=8C=EC=9D=B4=EB=84=88=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EC=99=84=EB=A3=8C=20=ED=9B=84=20=EA=B8=B0?= =?UTF-8?q?=EC=A1=B4=20=EC=BB=A8=ED=85=8C=EC=9D=B4=EB=84=88=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#300] --- .../src/containers/containers.service.ts | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/packages/backend/src/containers/containers.service.ts b/packages/backend/src/containers/containers.service.ts index ef3d1c0..cb6d282 100644 --- a/packages/backend/src/containers/containers.service.ts +++ b/packages/backend/src/containers/containers.service.ts @@ -29,6 +29,12 @@ export class ContainersService { } async initializeContainers() { + const { stdoutData: existingContainers } = + await this.commandService.executeCommand('docker ps -aq'); + const existingContainersSet = new Set( + existingContainers.split('\n').filter((id) => id), + ); + for (let i: number = 1; i < 20; i++) { const maxContainers = this.configService.get('CONTAINER_POOL_MAX') || 1; @@ -42,22 +48,8 @@ export class ContainersService { this.availableContainers.set(i, containers); } - this.removeUnusedContainers(); - } - - async removeUnusedContainers() { - const { stdoutData: allContainers } = - await this.commandService.executeCommand('docker ps -aq'); - - const usedContainers = new Set(); - this.availableContainers.forEach((containers) => { - containers.forEach((containerId) => usedContainers.add(containerId)); - }); - - allContainers.split('\n').forEach((containerId) => { - if (!usedContainers.has(containerId)) { - this.commandService.executeCommand(`docker rm -f ${containerId}`); - } + existingContainersSet.forEach((containerId) => { + this.commandService.executeCommand(`docker rm -f ${containerId}`); }); }