From 2d32b5600aa0b734b948c503a4c8d0f45c2d8c19 Mon Sep 17 00:00:00 2001 From: mjh000526 Date: Tue, 3 Dec 2024 18:38:35 +0900 Subject: [PATCH] fix(#151): log --- .github/workflows/be-cd.yml | 12 ++++++------ Dockerfile | 2 +- apps/backend/src/docker/docker.consumer.ts | 5 +++-- apps/backend/src/docker/docker.module.ts | 2 +- apps/backend/src/docker/docker.pool.ts | 8 ++++---- apps/backend/src/docker/docker.producer.ts | 4 ++-- apps/backend/src/main.ts | 2 +- 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/.github/workflows/be-cd.yml b/.github/workflows/be-cd.yml index fc431284..cb48febc 100644 --- a/.github/workflows/be-cd.yml +++ b/.github/workflows/be-cd.yml @@ -25,7 +25,7 @@ jobs: #이미지 이름 저장 - name: Set Docker image tag as a variable - run: echo "DOCKER_TAG=${{ secrets.DOCKER_USERNAME }}/froxy-server:latest" >> $GITHUB_ENV + run: echo "DOCKER_TAG=${{ secrets.DOCKER_USERNAME }}/froxy-server:always" >> $GITHUB_ENV - name: Create .env file run: | @@ -47,12 +47,12 @@ jobs: - name: Deploy run: | ssh -o StrictHostKeyChecking=no mun@211.188.48.24 " - if [ \$(docker ps -a -q -f name=froxy-container) ]; then - docker stop froxy-container - docker rm froxy-container + if [ \$(docker ps -a -q -f name=froxy-always) ]; then + docker stop froxy-always + docker rm froxy-always fi - docker pull ${{ secrets.DOCKER_USERNAME }}/froxy-server:latest && \ - docker run --network host -d --name froxy-container -v /var/run/docker.sock:/var/run/docker.sock ${{ secrets.DOCKER_USERNAME }}/froxy-server:latest + docker pull ${{ secrets.DOCKER_USERNAME }}/froxy-server:always && \ + docker run --network host -d --name froxy-always -v /var/run/docker.sock:/var/run/docker.sock ${{ secrets.DOCKER_USERNAME }}/froxy-server:always docker image prune -f " diff --git a/Dockerfile b/Dockerfile index 6a93de80..12c35e42 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,4 +15,4 @@ WORKDIR /app/apps/backend CMD ["pnpm", "run", "start:prod"] # 외부에서 접근할 수 있도록 포트 노출 -EXPOSE 3000 +EXPOSE 3001 diff --git a/apps/backend/src/docker/docker.consumer.ts b/apps/backend/src/docker/docker.consumer.ts index 99ec2b7e..52d37a0f 100644 --- a/apps/backend/src/docker/docker.consumer.ts +++ b/apps/backend/src/docker/docker.consumer.ts @@ -24,7 +24,7 @@ interface GistFile { attr: GistFileAttributes; } -@Processor('docker-queue') +@Processor('always-queue') @Injectable() export class DockerConsumer { queue_num = false; @@ -52,8 +52,9 @@ export class DockerConsumer { const { gitToken, gistId, commitId, mainFileName, inputs, c } = job.data; let container; try { - // console.log(`${c}번째 프로세스 시작`); + console.log(`${c}번째 프로세스 시작`); container = await this.dockerContainerPool.getContainer(); + console.log(`${c}번째 프로세스: ${container.id}`); const result = await this.runGistFiles(container, gitToken, gistId, commitId, mainFileName, inputs); await this.cleanWorkDir(container); this.dockerContainerPool.pool.push(container); diff --git a/apps/backend/src/docker/docker.module.ts b/apps/backend/src/docker/docker.module.ts index 3b877b3e..c4ca043b 100644 --- a/apps/backend/src/docker/docker.module.ts +++ b/apps/backend/src/docker/docker.module.ts @@ -10,7 +10,7 @@ import { GistModule } from '@/gist/gist.module'; imports: [ GistModule, BullModule.registerQueue({ - name: 'docker-queue' + name: 'always-queue' }) ], controllers: [DockerController], diff --git a/apps/backend/src/docker/docker.pool.ts b/apps/backend/src/docker/docker.pool.ts index 44891572..46796520 100644 --- a/apps/backend/src/docker/docker.pool.ts +++ b/apps/backend/src/docker/docker.pool.ts @@ -17,7 +17,7 @@ export class DockerContainerPool implements OnApplicationBootstrap { const containersToDelete = await this.docker.listContainers({ all: true }); await Promise.all( containersToDelete - .filter((container) => container.Names.some((name) => name.startsWith('/froxy-run'))) + .filter((container) => container.Names.some((name) => name.startsWith('/always'))) .map(async (container) => { const removeContainer = await this.docker.getContainer(container.Id); await removeContainer.remove({ force: true }); @@ -55,10 +55,10 @@ export class DockerContainerPool implements OnApplicationBootstrap { 'NODE_DISABLE_COLORS=true', // 색상 비활성화 'TERM=dumb' // dumb 터미널로 설정하여 색상 비활성화 ], - name: `froxy-run${i + 1}`, + name: `always${i + 1}`, HostConfig: { - // Memory: (1024 * 1024 * 1024) / 2, // 1GB 메모리 제한 - // MemorySwap: (1024 * 1024 * 1024) / 2, // swap 메모리도 1GB로 설정 + Memory: (1024 * 1024 * 1024) / 2, // 1GB 메모리 제한 + MemorySwap: (1024 * 1024 * 1024) / 2, // swap 메모리도 1GB로 설정 networkMode: 'host' } }); diff --git a/apps/backend/src/docker/docker.producer.ts b/apps/backend/src/docker/docker.producer.ts index c5cf74d0..b6028dcb 100644 --- a/apps/backend/src/docker/docker.producer.ts +++ b/apps/backend/src/docker/docker.producer.ts @@ -7,7 +7,7 @@ import { DockerContainerPool } from './docker.pool'; export class DockerProducer implements OnApplicationBootstrap { cnt = 0; constructor( - @InjectQueue('docker-queue') + @InjectQueue('always-queue') private readonly dockerQueue: Queue, private dockerContainerPool: DockerContainerPool ) {} @@ -41,7 +41,7 @@ export class DockerProducer implements OnApplicationBootstrap { removeOnFail: true } ); - // console.log('jobId추가 :', job.id); + console.log('jobId추가 :', job.id); return await job.finished(); } catch (error) { throw error; diff --git a/apps/backend/src/main.ts b/apps/backend/src/main.ts index 5479d20d..7c18fa6e 100644 --- a/apps/backend/src/main.ts +++ b/apps/backend/src/main.ts @@ -32,6 +32,6 @@ async function bootstrap() { const document = SwaggerModule.createDocument(app, config); SwaggerModule.setup('swagger', app, document, customOptions); - await app.listen(3000); + await app.listen(3001); } bootstrap();