From 757db977c8eb43ebbf6a1bb25de0fbd4abe03ba0 Mon Sep 17 00:00:00 2001 From: wonholim Date: Tue, 21 Nov 2023 01:26:37 +0900 Subject: [PATCH 1/5] =?UTF-8?q?chore:=20self-hosted=EC=97=90=EC=84=9C=20ap?= =?UTF-8?q?pleboy=EA=B0=80=20=EC=9E=91=EB=8F=99=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EA=B8=B0=EC=97=90=20ssh=20=EC=A0=91=EC=86=8D=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/BackEnd_CD.yml | 55 +++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/.github/workflows/BackEnd_CD.yml b/.github/workflows/BackEnd_CD.yml index 2169da54..0ee9ddef 100644 --- a/.github/workflows/BackEnd_CD.yml +++ b/.github/workflows/BackEnd_CD.yml @@ -27,19 +27,52 @@ jobs: file: ./BackEnd/Dockerfile push: true tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/my-app:latest +name: BackEnd-CD - - name: SSH to Internal Server and Deploy - uses: appleboy/ssh-action@master +on: + push: + branches: + - develop + paths: + - 'BackEnd/**' + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: docker/setup-buildx-action@v2 + + - uses: docker/login-action@v2 + with: + registry: ${{ secrets.NCP_CONTAINER_REGISTRY }} + username: ${{ secrets.NCP_ACCESS_KEY }} + password: ${{ secrets.NCP_SECRET_KEY }} + + - uses: docker/build-push-action@v3 with: - host: ${{ secrets.BASTION_HOST }} - username: ${{ secrets.BASTION_USER }} - password: ${{ secrets.BASTION_PASSWORD }} - port: 22 - script: | - sshpass -p ${{ secrets.SERVER_PASSWORD }} ssh -o StrictHostKeyChecking=no ${{ secrets.SERVER_USER }}@${{ secrets.INTERNAL_SERVER_IP }} -p 22 ' - docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/my-app:latest + context: . + file: ./BackEnd/Dockerfile + push: true + tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/my-app:latest + + - name: SSH to Internal Server and Deploy + env: + BASTION_HOST: ${{ secrets.BASTION_HOST }} + BASTION_USER: ${{ secrets.BASTION_USER }} + BASTION_PASSWORD: ${{ secrets.BASTION_PASSWORD }} + SERVER_PASSWORD: ${{ secrets.SERVER_PASSWORD }} + SERVER_USER: ${{ secrets.SERVER_USER }} + INTERNAL_SERVER_IP: ${{ secrets.INTERNAL_SERVER_IP }} + CONTAINER_REGISTRY: ${{ secrets.NCP_CONTAINER_REGISTRY }} + run: | + sshpass -p $BASTION_PASSWORD ssh -o StrictHostKeyChecking=no $BASTION_USER@$BASTION_HOST -tt << EOF + sshpass -p $SERVER_PASSWORD ssh -o StrictHostKeyChecking=no $SERVER_USER@$INTERNAL_SERVER_IP -tt << 'ENDSSH' + docker pull $CONTAINER_REGISTRY/my-app:latest docker stop my-app || true docker rm my-app || true - docker run --name my-app -d -p 443:3000 -p 80:3000 ${{ secrets.NCP_CONTAINER_REGISTRY }}/my-app:latest + docker run --name my-app -d -p 443:3000 -p 80:3000 $CONTAINER_REGISTRY/my-app:latest docker cp /var/env/.env my-app:/app/.env - ' + ENDSSH + EOF \ No newline at end of file From cfd7adabb8130b0cf077958d6ed7cc29760efb0c Mon Sep 17 00:00:00 2001 From: wonholim Date: Tue, 21 Nov 2023 01:57:10 +0900 Subject: [PATCH 2/5] =?UTF-8?q?chore:=20app.service=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BackEnd/src/app.service.ts | 8 -------- 1 file changed, 8 deletions(-) delete mode 100755 BackEnd/src/app.service.ts diff --git a/BackEnd/src/app.service.ts b/BackEnd/src/app.service.ts deleted file mode 100755 index 927d7cca..00000000 --- a/BackEnd/src/app.service.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Injectable } from '@nestjs/common'; - -@Injectable() -export class AppService { - getHello(): string { - return 'Hello World!'; - } -} From d05ff19cb58000f0bc8de29f8ae93dad124c29fb Mon Sep 17 00:00:00 2001 From: wonholim Date: Tue, 21 Nov 2023 01:58:08 +0900 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20ipa=20=EC=A0=9C=EA=B3=B5=EC=9D=84?= =?UTF-8?q?=20=EC=9C=84=ED=95=9C=20index.html=20=EC=84=9C=EB=B9=99=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BackEnd/public/index.html | 90 +++++++++++++++++++++++++++++++++++ BackEnd/src/app.controller.ts | 11 ++--- BackEnd/src/app.module.ts | 2 - BackEnd/src/main.ts | 2 + 4 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 BackEnd/public/index.html diff --git a/BackEnd/public/index.html b/BackEnd/public/index.html new file mode 100644 index 00000000..2121d7b4 --- /dev/null +++ b/BackEnd/public/index.html @@ -0,0 +1,90 @@ + + + + + + We-Tri Triathlon App Download + + + +
+

We-Tri: 트라이 애슬론을 우리와 함께해요

+
+
+
+

+ 이 곳은 데모 앱 설치 화면이에요. 등록되지 않은 분들은 설치할 수 + 없어요. +

+
+
+ Download Week 2 App + Download Week 3 App +
+
+
+

© 2023 We-Tri. All rights reserved.

+
+ + diff --git a/BackEnd/src/app.controller.ts b/BackEnd/src/app.controller.ts index cce879ee..e92da980 100755 --- a/BackEnd/src/app.controller.ts +++ b/BackEnd/src/app.controller.ts @@ -1,12 +1,11 @@ -import { Controller, Get } from '@nestjs/common'; -import { AppService } from './app.service'; +import { Controller, Get, Res } from '@nestjs/common'; +import { Response } from 'express'; +import { join } from 'path'; @Controller() export class AppController { - constructor(private readonly appService: AppService) {} - @Get() - getHello(): string { - return this.appService.getHello(); + indexHTML(@Res() response: Response): void { + response.sendFile(join(__dirname, '..', 'public', 'index.html')); } } diff --git a/BackEnd/src/app.module.ts b/BackEnd/src/app.module.ts index 5c3c7863..5e43b58d 100755 --- a/BackEnd/src/app.module.ts +++ b/BackEnd/src/app.module.ts @@ -1,6 +1,5 @@ import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common'; import { AppController } from './app.controller'; -import { AppService } from './app.service'; import { typeOrmConfig } from './config/typeorm.config'; import { TypeOrmModule } from '@nestjs/typeorm'; import { LoggerMiddleware } from './middlewares/logger.middleware'; @@ -16,7 +15,6 @@ import { ProfilesModule } from './profiles/profiles.module'; ProfilesModule, ], controllers: [AppController], - providers: [AppService], }) export class AppModule implements NestModule { configure(consumer: MiddlewareConsumer): void { diff --git a/BackEnd/src/main.ts b/BackEnd/src/main.ts index 5f2cb273..cfec1c88 100755 --- a/BackEnd/src/main.ts +++ b/BackEnd/src/main.ts @@ -5,6 +5,7 @@ import { winstonLogger } from './config/winston.config'; import { ValidationPipe } from '@nestjs/common'; import { ResponseTransformInterceptor } from './common/Interceptors/responseTransform. Interceptor'; import { HttpExceptionFilter } from './common/exceptionFilters/httpException.filter'; +import * as express from 'express'; async function bootstrap() { const app = await NestFactory.create(AppModule, { @@ -13,6 +14,7 @@ async function bootstrap() { app.useGlobalPipes(new ValidationPipe()); app.useGlobalFilters(new HttpExceptionFilter()); app.useGlobalInterceptors(new ResponseTransformInterceptor()); + app.use('/static', express.static('public')); SwaggerSetting(app); await app.listen(3000); } From 688e2b82f219e26c56d5fb1728f59fcc31bb0d53 Mon Sep 17 00:00:00 2001 From: wonholim Date: Tue, 21 Nov 2023 10:03:57 +0900 Subject: [PATCH 4/5] =?UTF-8?q?chore:=20app.controller.spec.ts=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BackEnd/src/app.controller.spec.ts | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100755 BackEnd/src/app.controller.spec.ts diff --git a/BackEnd/src/app.controller.spec.ts b/BackEnd/src/app.controller.spec.ts deleted file mode 100755 index d22f3890..00000000 --- a/BackEnd/src/app.controller.spec.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { AppController } from './app.controller'; -import { AppService } from './app.service'; - -describe('AppController', () => { - let appController: AppController; - - beforeEach(async () => { - const app: TestingModule = await Test.createTestingModule({ - controllers: [AppController], - providers: [AppService], - }).compile(); - - appController = app.get(AppController); - }); - - describe('root', () => { - it('should return "Hello World!"', () => { - expect(appController.getHello()).toBe('Hello World!'); - }); - }); -}); From 2dcb3ce9e9c441fcac6710e1639a5864acefa2d4 Mon Sep 17 00:00:00 2001 From: wonholim Date: Tue, 21 Nov 2023 10:09:42 +0900 Subject: [PATCH 5/5] =?UTF-8?q?chore:=20sendFile=EC=9D=84=20=EC=A3=BC?= =?UTF-8?q?=EB=8A=94=EC=A7=80=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BackEnd/src/app.controller.spec.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 BackEnd/src/app.controller.spec.ts diff --git a/BackEnd/src/app.controller.spec.ts b/BackEnd/src/app.controller.spec.ts new file mode 100644 index 00000000..9bb2d61b --- /dev/null +++ b/BackEnd/src/app.controller.spec.ts @@ -0,0 +1,27 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { AppController } from './app.controller'; +import { Response } from 'express'; + +describe('AppController', () => { + let appController: AppController; + let mockResponse: Response; + + beforeEach(async () => { + const app: TestingModule = await Test.createTestingModule({ + controllers: [AppController], + }).compile(); + + appController = app.get(AppController); + mockResponse = { + sendFile: jest.fn(), + } as unknown as Response; + }); + + describe('indexHTML', () => { + it('should call sendFile', () => { + appController.indexHTML(mockResponse); + expect(mockResponse.sendFile).toHaveBeenCalled(); + }); + }); +}); +