Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/dev-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Deploy to Dev

on:
workflow_dispatch:
push:
branches:
- dev

jobs:
deploy-dev: # 개발 환경 배포
runs-on: ubuntu-latest

steps:
- name: Get Github Actions IP # 깃허브의 현재 ip가져오기
id: ip
uses: haythem/public-ip@v1.2

- name: Setting environment variables
run: |
echo "AWS_DEFAULT_REGION=ap-northeast-2" >> $GITHUB_ENV
echo "AWS_SG_NAME=general-web-sg" >> $GITHUB_ENV

- name: Configure AWS Credentials # AWS 관련 설정값 등록
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2

- name: Add Github Actions IP to Security group # 보안 그룹에 깃허브 ip 추가
run: |
aws ec2 authorize-security-group-ingress --group-name ${{ env.AWS_SG_NAME }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ap-northeast-2

- name: Deploy to Dev EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEV_EC2_HOST }} # Dev EC2의 호스트 주소
username: ${{ secrets.EC2_USER }} # SSH 사용자
key: ${{ secrets.DEV_EC2_KEY }} # SSH 비밀 키
script_stop: true # 연결 실패 시 작업 중지
script: |
cd services/${{ github.event.repository.name }}
git pull origin dev
npm ci --omit=dev
pm2 reload ${{ github.event.repository.name }}

- name: Remove Github Actions IP from security group # 추가했던 ip 삭제
run: |
aws ec2 revoke-security-group-ingress --group-name ${{ env.AWS_SG_NAME }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ap-northeast-2
30 changes: 30 additions & 0 deletions .github/workflows/dev-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: dev CI

on:
workflow_dispatch:
pull_request:
branches:
- dev

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code # 코드 체크아웃 단계
uses: actions/checkout@v2

- name: Set up Node.js # Node.js 설정 단계
uses: actions/setup-node@v2
with:
node-version: '18' # 사용할 Node.js 버전 설정

- name: Install dependencies # 종속성 설치 단계
run: npm install

- name: Run lint # 코드 스타일 검사 단계
run: npm run lint
continue-on-error: false # lint 실패 시 작업 중단

- name: Run tests # 테스트 실행 단계
run: npm test
57 changes: 57 additions & 0 deletions .github/workflows/prod-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Deploy to Prod

on:
workflow_dispatch:
push:
branches:
- main

jobs:
deploy-prod: # 배포 환경 배포
runs-on: ubuntu-latest

steps:
- name: Get Github Actions IP # 깃허브의 현재 ip가져오기
id: ip
uses: haythem/public-ip@v1.2

- name: Setting environment variables
run: |
echo "AWS_DEFAULT_REGION=ap-northeast-2" >> $GITHUB_ENV
echo "AWS_SG_NAME=general-web-sg" >> $GITHUB_ENV

- name: Configure AWS Credentials # AWS 관련 설정값 등록
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2

- name: Add Github Actions IP to Security group # 보안 그룹에 깃허브 ip 추가
run: |
aws ec2 authorize-security-group-ingress --group-name ${{ env.AWS_SG_NAME }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ap-northeast-2

- name: Deploy to PROD EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PROD_EC2_HOST }} # Prod EC2의 호스트 주소
username: ${{ secrets.EC2_USER }} # SSH 사용자
key: ${{ secrets.PROD_EC2_KEY }} # SSH 비밀 키
script_stop: true # 연결 실패 시 작업 중지
script: |
cd services/${{ github.event.repository.name }}
git pull origin main
npm ci --omit=dev
pm2 reload ${{ github.event.repository.name }}

- name: Remove Github Actions IP from security group # 추가했던 ip 삭제
run: |
aws ec2 revoke-security-group-ingress --group-name ${{ env.AWS_SG_NAME }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ap-northeast-2
30 changes: 30 additions & 0 deletions .github/workflows/prod-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: prod CI

on:
workflow_dispatch:
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code # 코드 체크아웃 단계
uses: actions/checkout@v2

- name: Set up Node.js # Node.js 설정 단계
uses: actions/setup-node@v2
with:
node-version: '18' # 사용할 Node.js 버전 설정

- name: Install dependencies # 종속성 설치 단계
run: npm install

- name: Run lint # 코드 스타일 검사 단계
run: npm run lint
continue-on-error: false # lint 실패 시 작업 중단

- name: Run tests # 테스트 실행 단계
run: npm test
22 changes: 12 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "user-service",
"version": "1.0.0",
"version": "1.1.0",
"main": "src/index.js",
"type": "module",
"scripts": {
Expand Down Expand Up @@ -29,8 +29,8 @@
"dependencies": {
"@frolog/common-utils": "^1.0.5",
"@frolog/express-api-server": "^1.0.8",
"@frolog/frolog-api": "^1.0.3",
"@frolog/models": "^1.0.3",
"@frolog/frolog-api": "^1.3.3",
"@frolog/models": "^1.3.2",
"aws-sdk": "^2.1692.0",
"bcrypt": "^5.1.1",
"dotenv": "^16.4.5",
Expand Down
10 changes: 8 additions & 2 deletions src/services/postUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ export default async function postUser(reqDto) {
const encryptedEmail = encryptData(email, EMAIL_SECRET);
const emailHash = hashEmail(email);

// 비밀번호 해싱
const pwHash = hashSync(reqDto.password, BCRYPT_ROUNDS);
// 로그인 타입에 따른 데이터 설정
const isGoogleLogin = !reqDto.password;

const pwHash = isGoogleLogin
? null
: hashSync(reqDto.password, BCRYPT_ROUNDS);
const loginType = isGoogleLogin ? 1 : 0; // 0: 로컬 로그인, 1: 구글 로그인

// 테이블 INSERT
const user = await User.create({
email: encryptedEmail,
email_hash: Buffer.from(emailHash, 'hex'),
pw_hash: pwHash,
login_type: loginType,
is_admin: reqDto.is_admin,
}).catch(handleSqlError);

Expand Down
Loading