diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..10e188f --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,93 @@ +name: Deploy to EC2 + +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: ubuntu-latest + permissions: + id-token: write + contents: read + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Set Up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20.18.0' + + - name: Install Dependencies + run: npm install + + - name: Run E2E Tests + env: + ENV: ${{ secrets.ENV }} + ACCESS_TOKEN_EXPIRY: ${{ secrets.ACCESS_TOKEN_EXPIRY }} + BUCKET_NAME: ${{ secrets.BUCKET_NAME }} + CHAT_ID: ${{ secrets.CHAT_ID }} + CHAT_ROOM_ID: ${{ secrets.CHAT_ROOM_ID }} + CLIENT_REDIRECT: ${{ secrets.CLIENT_REDIRECT }} + COMPLETED_PLAN_ID: ${{ secrets.COMPLETED_PLAN_ID }} + CONFIRMED_PLAN_ID: ${{ secrets.CONFIRMED_PLAN_ID }} + DATABASE_URL: ${{ secrets.DATABASE_URL }} + DE_ACTIVE_CHAT_ROOM_ID: ${{ secrets.DE_ACTIVE_CHAT_ROOM_ID }} + DREAMER1_EMAIL: ${{ secrets.DREAMER1_EMAIL }} + DREAMER1_ID: ${{ secrets.DREAMER1_ID }} + DREAMER1_NICKNAME: ${{ secrets.DREAMER1_NICKNAME }} + DREAMER1_PASSWORD: ${{ secrets.DREAMER1_PASSWORD }} + DREAMER2_ID: ${{ secrets.DREAMER2_ID }} + GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} + GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} + GOOGLE_REDIRECT: ${{ secrets.GOOGLE_REDIRECT }} + JWT_SECRET: ${{ secrets.JWT_SECRET }} + KAKAO_CLIENT_ID: ${{ secrets.KAKAO_CLIENT_ID }} + KAKAO_CLIENT_SECRET: ${{ secrets.KAKAO_CLIENT_SECRET }} + KAKAO_REDIRECT: ${{ secrets.KAKAO_REDIRECT }} + MAKER1_ID: ${{ secrets.MAKER1_ID }} + MONGO_AUTH_SOURCE: ${{ secrets.MONGO_AUTH_SOURCE }} + MONGO_DB_NAME: ${{ secrets.MONGO_DB_NAME }} + MONGO_PASS: ${{ secrets.MONGO_PASS }} + MONGO_URI: ${{ secrets.MONGO_URI }} + MONGO_USER: ${{ secrets.MONGO_USER }} + NAVER_CLIENT_ID: ${{ secrets.NAVER_CLIENT_ID }} + NAVER_CLIENT_SECRET: ${{ secrets.NAVER_CLIENT_SECRET }} + NAVER_REDIRECT: ${{ secrets.NAVER_REDIRECT }} + NOTIFICATION_ID: ${{ secrets.NOTIFICATION_ID }} + OAUTH_GOOGLE_PROVIDER_ID: ${{ secrets.OAUTH_GOOGLE_PROVIDER_ID }} + OVERDUE_PLAN_ID: ${{ secrets.OVERDUE_PLAN_ID }} + PAYMENT_ID: ${{ secrets.PAYMENT_ID }} + PENDING_PLAN_ID: ${{ secrets.PENDING_PLAN_ID }} + PORT: ${{ secrets.PORT }} + QUOTE1_ID: ${{ secrets.QUOTE1_ID }} + QUOTE2_ID: ${{ secrets.QUOTE2_ID }} + REDIS_HOST: ${{ secrets.REDIS_HOST }} + REDIS_PORT: ${{ secrets.REDIS_PORT }} + REFRESH_TOKEN_EXPIRY: ${{ secrets.REFRESH_TOKEN_EXPIRY }} + S3_ACCESSKEY: ${{ secrets.S3_ACCESSKEY }} + S3_REGION: ${{ secrets.S3_REGION }} + S3_SECRET_ACCESSKEY: ${{ secrets.S3_SECRET_ACCESSKEY }} + TOKEN_NAME: ${{ secrets.TOKEN_NAME }} + TO_BE_COMPLETED_PLAN_ID: ${{ secrets.TO_BE_COMPLETED_PLAN_ID }} + TO_BE_DELETE_QUOTE_ID: ${{ secrets.TO_BE_DELETE_QUOTE_ID }} + V2_API_SECRET: ${{ secrets.V2_API_SECRET }} + run: npm run test:e2e + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v3 + with: + role-to-assume: arn:aws:iam::${{ AWS_USER_ID }}:role/${{ AWS_IAM_ROLE }} + aws-region: ap-northeast-2 + + - name: Set Up SSH + uses: webfactory/ssh-agent@v0.7.0 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Deploy to EC2 via SSH + run: | + ssh -o StrictHostKeyChecking=no ubuntu@${{ secrets.EC2_PUBLIC_IP }} "cd /var/www/app && git pull origin main && npm install && npm run build && pm2 start ecosystem.json" diff --git a/package.json b/package.json index 62455a9..f0b9131 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "test:watch": "jest --watch", "test:cov": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", - "test:e2e": "jest --config ./jest-e2e.json", + "test:e2e": "jest src/modules/plan/plan.e2e.spec.ts src/modules/quote/quote.e2e.spec.ts src/modules/auth/auth.e2e.spec.ts src/modules/user/user.e2e.spec.ts src/modules/follow/follow.e2e.spec.ts src/modules/notification/notification.e2e.spec.ts src/modules/payment/payment.e2e.spec.ts src/modules/chatRoom/chatRoom.e2e.spec.ts src/modules/chat/chat.e2e.spec.ts src/modules/review/review.e2e.spec.ts --detectOpenHandles --coverage", "test:e2e:plan": "jest src/modules/plan/plan.e2e.spec.ts --detectOpenHandles --coverage", "test:e2e:quote": "jest src/modules/quote/quote.e2e.spec.ts --detectOpenHandles --coverage", "test:e2e:auth": "jest src/modules/auth/auth.e2e.spec.ts --detectOpenHandles --coverage", diff --git a/src/modules/notification/notification.controller.ts b/src/modules/notification/notification.controller.ts index fe1d378..111dd72 100644 --- a/src/modules/notification/notification.controller.ts +++ b/src/modules/notification/notification.controller.ts @@ -1,32 +1,13 @@ -import { Controller, Get, Param, Patch, Post, Sse } from '@nestjs/common'; +import { Controller, Get, Param, Patch, Sse } from '@nestjs/common'; import NotificationService from './notification.service'; import { UserId } from 'src/common/decorators/user.decorator'; import { interval, merge, Observable } from 'rxjs'; import { map } from 'rxjs/operators'; -import { NotificationEventName, NotificationProperties } from './types/notification.types'; +import { NotificationProperties } from './types/notification.types'; @Controller('notifications') export default class NotificationController { constructor(private readonly service: NotificationService) {} - - @Post() - async createNotification(@UserId() userId: string) { - return await this.service.create({ - userId, - event: NotificationEventName.CONFIRM_QUOTE, - payload: { nickName: '테스트' } - }); - } - - @Post('2') - async createNotification2(@UserId() userId: string) { - return await this.service.create({ - userId, - event: NotificationEventName.SCHEDULE, - payload: { planTitle: '가현님이 좋아하는 플랜' } - }); - } - @Get() async getNotifications(@UserId() userId: string): Promise { return await this.service.get(userId); diff --git a/src/modules/notification/notification.e2e.spec.ts b/src/modules/notification/notification.e2e.spec.ts index a0227ea..5ea3715 100644 --- a/src/modules/notification/notification.e2e.spec.ts +++ b/src/modules/notification/notification.e2e.spec.ts @@ -5,7 +5,7 @@ import AppModule from 'src/app.module'; import GlobalExceptionFilter from 'src/common/filters/globalExceptionFilter'; import { RoleValues } from 'src/common/constants/role.type'; import AuthService from '../auth/auth.service'; -import { seed } from 'src/providers/database/mongoose/mongoose.seed'; +import { mongooseSeed } from 'src/providers/database/mongoose/mongoose.seed'; describe('Notification Test (e2e)', () => { let app: INestApplication; @@ -27,7 +27,7 @@ describe('Notification Test (e2e)', () => { await app.init(); const authService = app.get(AuthService); - await seed(); + await mongooseSeed(); dreamerToken = authService.createTokens({ userId: dreamerId, role: RoleValues.DREAMER }).accessToken; }); diff --git a/src/modules/payment/payment.e2e.spec.ts b/src/modules/payment/payment.e2e.spec.ts index 41e606e..30e9af9 100644 --- a/src/modules/payment/payment.e2e.spec.ts +++ b/src/modules/payment/payment.e2e.spec.ts @@ -7,7 +7,7 @@ import { RoleValues } from 'src/common/constants/role.type'; import AuthService from '../auth/auth.service'; import { mongooseSeed } from 'src/providers/database/mongoose/mongoose.seed'; import PaymentService from './payment.service'; -import { PaymentStatusEnum } from 'src/common/types/payment/payment.type'; +import { PaymentStatusEnum } from './types/payment.type'; describe('Payment Test (e2e)', () => { let app: INestApplication; diff --git a/test.json b/test.json deleted file mode 100644 index 3be50e6..0000000 --- a/test.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Principal": { - "AWS": "arn:aws:iam::YOUR_EC2_ACCOUNT_ID:role/YOUR_IAM_ROLE_NAME" - }, - "Action": ["s3:GetObject", "s3:PutObject"], - "Resource": "arn:aws:s3:::TARGET_BUCKET_NAME/*" - } - ] -}