Skip to content

Commit 8b217cd

Browse files
hye-onainHo-s
authored
GitHub Actions를 활용한 CD 파이프라인 작성 (#10)
* feat: cd 스크립트 작성 * chore: cd스크립트 workflows폴더로 이동 * chore: 버전 수정 * chore: serverless 버전 3.38.0으로 고정 및 credential 과정 삭제 - serverless v4부터 로그인/라이선스 키가 필요해 v3.38.0으로 고정 - AWS 인증은 환경 변수만으로 처리하도록 변경 * chore: prisma deploy과정에 Prisma CLI 설치 추가 * chore: 프리즈마 스키마 파일 위치 설정 * chore: 경로 추가 * chore: 환경 변수 이름 수정 * fix: serverless 배포 명령어 수정. 플러그인 충돌 해결 - npx --no-install 옵션을 사용하여 serverless 버전 충돌 문제 해결 * chore: 플러그인 주석 * chore: 서버리스 버전 수정 * chore: 노드 버전 수정 * chore: 플러그인 충돌로 인해 주석처리 * chore: AWS 자격 증명 설정 * chore: serverless secret key 추가 * chore: 서버리스 버전 수정 * chore: 대시보드 비활성화 * chore: 대시보드 모드 비활성화 * chore: --no-console 제거 * chore: pakage할때 제외 pnpm제외 * chore: remove @generated from code config * fix: build type error * feat: bcrypt -> bcryptjs로 변경 - lambda 환경에서 bcrypt는 호환 이슈가 있어요 ref: kelektiv/node.bcrypt.js#505 (comment) * feat: 필요한 환경변수 재설정 * feat: aws-lambda 를 serverless 배포에서 제외 * chore: only import type * feat: 민감한 정보 masking * feat: use dotenv plugin * feat: build / deploy workflow 나눔 - npx prisma generate 는 삭제 -> yarn install 시 prisma 내부 postinstall 로 shcema에 따라 자동 생성 * feat: install serverless in local * chore: remove no use * chore: 필요없는 환경변수 제거 * chore: 주석 삭제 * chore: remove this branch from workflow triggers * chore: remove useless --------- Co-authored-by: ain <ain.jo@kmpns.com> Co-authored-by: Joo-Byungho <kjcoco13@gmail.com>
1 parent 24a8f0b commit 8b217cd

File tree

11 files changed

+3161
-231
lines changed

11 files changed

+3161
-231
lines changed

.example.env

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
# DB
21
DB_URL="postgresql://postgres:1q2w3e4r@localhost:5432/postgres?schema=public"
3-
DB_HOST=localhost
4-
DB_PORT=5432
5-
DB_USER=postgres
6-
DB_PASSWORD=1q2w3e4r
7-
DB_NAME=postgres
8-
DB_SCHEMA=public
92

103
PORT=8000
114

12-
# JWT
135
ACCESS_TOKEN_SECRET=
146
REFRESH_TOKEN_SECRET=

.github/workflows/deploy.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Deploy serverless application
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: '20'
19+
cache: 'yarn'
20+
21+
- name: Install dependencies
22+
run: yarn install --frozen-lockfile
23+
24+
- name: Run Prisma migrations
25+
run: npx prisma migrate deploy 2>&1 | grep -v 'Datasource "db":' | grep -v 'PostgreSQL database'
26+
env:
27+
DB_URL: ${{ secrets.DB_URL }}
28+
29+
- name: Create .env file
30+
run: |
31+
echo "ACCESS_TOKEN_SECRET=${{ secrets.ACCESS_TOKEN_SECRET }}" >> .env
32+
echo "REFRESH_TOKEN_SECRET=${{ secrets.REFRESH_TOKEN_SECRET }}" >> .env
33+
echo "DB_URL=${{ secrets.DB_URL }}" >> .env
34+
35+
- name: Run build
36+
run: yarn build
37+
38+
- name: Configure serverless credentials
39+
run: npx serverless config credentials --provider aws --key ${{ secrets.AWS_ACCESS_KEY_ID }} --secret ${{ secrets.AWS_SECRET_ACCESS_KEY }}
40+
41+
- name: Deploy serverless app
42+
run: npx serverless deploy 2>&1 | grep -v 'endpoint:'

.github/workflows/validate.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Run build & test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
validate:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: '20'
19+
cache: 'yarn'
20+
21+
- name: Install dependencies
22+
run: yarn install --frozen-lockfile
23+
24+
- name: Lint code
25+
run: yarn lint
26+
27+
- name: Build project
28+
run: yarn build

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,3 @@ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
6161
postgres-data/
6262

6363
graphql-schema.gql
64-
65-
@generated

.prettierignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
graphql-schema.gql
2-
@generated
1+
graphql-schema.gql

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
},
2626
"dependencies": {
2727
"@fastify/aws-lambda": "5.1.4",
28+
"@nestjs/cli": "^11.0.6",
2829
"@nestjs/common": "^11.0.1",
2930
"@nestjs/config": "^4.0.2",
3031
"@nestjs/core": "^11.0.1",
@@ -35,8 +36,7 @@
3536
"@nestjs/platform-express": "^11.0.1",
3637
"@nestjs/platform-fastify": "11.0.12",
3738
"@prisma/client": "^6.5.0",
38-
"aws-lambda": "^1.0.7",
39-
"bcrypt": "^5.1.1",
39+
"bcryptjs": "^3.0.2",
4040
"class-transformer": "^0.5.1",
4141
"class-validator": "^0.14.1",
4242
"fastify": "5.2.1",
@@ -52,7 +52,6 @@
5252
"devDependencies": {
5353
"@eslint/eslintrc": "^3.2.0",
5454
"@eslint/js": "^9.18.0",
55-
"@nestjs/cli": "^11.0.0",
5655
"@nestjs/schematics": "^11.0.0",
5756
"@nestjs/testing": "^11.0.1",
5857
"@swc/cli": "^0.6.0",
@@ -71,6 +70,7 @@
7170
"globals": "^16.0.0",
7271
"jest": "^29.7.0",
7372
"prettier": "^3.4.2",
73+
"serverless": "3.38.0",
7474
"serverless-dotenv-plugin": "^6.0.0",
7575
"source-map-support": "^0.5.21",
7676
"supertest": "^7.0.0",
@@ -98,4 +98,4 @@
9898
"coverageDirectory": "../coverage",
9999
"testEnvironment": "node"
100100
}
101-
}
101+
}

serverless.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
org: hospace
2-
app: mashup-node
3-
41
service: nest-graphql-mercurius-fastify
52

63
plugins:
@@ -30,3 +27,4 @@ package:
3027
- 'node_modules/.prisma/client/libquery_engine-rhel-*'
3128
- '!node_modules/prisma/libquery_engine-*'
3229
- '!node_modules/@prisma/engines/**'
30+
- '!node_modules/aws-lambda'

src/auth/auth.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable, UnauthorizedException } from '@nestjs/common';
22
import { ConfigService } from '@nestjs/config';
33
import { PrismaService } from '../prisma/prisma.service';
4-
import * as bcrypt from 'bcrypt';
4+
import * as bcrypt from 'bcryptjs';
55
import { SignInInput, SignUpInput } from './inputs/auth.input';
66
import { JwtService } from '@nestjs/jwt';
77
import { User } from '@prisma/client';
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { ExecutionContext, createParamDecorator } from '@nestjs/common';
22
import { GqlExecutionContext } from '@nestjs/graphql';
3+
import { GraphQLContext } from '../config/graphql.context';
34

45
export const CurrentUser = createParamDecorator(
5-
(data: unknown, context: ExecutionContext) => {
6-
const ctx = GqlExecutionContext.create(context);
7-
return ctx.getContext().req.user;
6+
(_: unknown, context: ExecutionContext) => {
7+
const gqlContext = GqlExecutionContext.create(context);
8+
const { user } = gqlContext.getContext<GraphQLContext>();
9+
10+
return user;
811
},
912
);

src/lambda.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import awsLambdaFastify, {
22
LambdaResponse,
33
PromiseHandler,
44
} from '@fastify/aws-lambda';
5-
import {
5+
import type {
66
APIGatewayProxyEvent,
77
APIGatewayProxyResult,
88
Context,

0 commit comments

Comments
 (0)