Skip to content

Commit 740314b

Browse files
committed
Merge branch 'develop' into feature-shared-#211
2 parents 54b325a + f2572a5 commit 740314b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2232
-11027
lines changed

.github/workflows/develop.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Create Directory on Remote Server
2+
on:
3+
push:
4+
branches:
5+
- develop
6+
7+
jobs:
8+
env:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
# 코드 체크아웃
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
# .env 파일 생성 후 붙여넣기
17+
- name: Create .env file
18+
run: |
19+
echo "${{secrets.DEVELOPMENT_ENV}}" > ./.env
20+
21+
# sh 실행
22+
- name: Connect to Remote Server and Run Commands
23+
env:
24+
REMOTE_HOST: ${{ secrets.REMOTE_DEV_IP }}
25+
REMOTE_USER: ${{ secrets.REMOTE_USER }}
26+
SSH_KEY: ${{ secrets.REMOTE_PRIVATE_KEY }}
27+
BRANCH_NAME: "develop"
28+
run: |
29+
mkdir ~/.ssh
30+
echo "$SSH_KEY" > ~/.ssh/id_rsa
31+
chmod 600 ~/.ssh/id_rsa
32+
ssh -o StrictHostKeyChecking=no $REMOTE_USER@$REMOTE_HOST << 'EOF'
33+
DIR="/home/root/app/octodocs"
34+
35+
# Check if directory exists
36+
if [ -d "$DIR" ]; then
37+
echo "$DIR 디렉토리가 존재합니다. 최신 버전으로 업데이트 중..."
38+
cd "$DIR"
39+
git switch -c develop
40+
git pull origin develop
41+
42+
43+
else
44+
echo "$DIR 디렉토리가 존재하지 않습니다. 클론 중..."
45+
git clone https://github.com/boostcampwm-2024/web15-OctoDocs.git "$DIR"
46+
cd "$DIR"
47+
git switch -c develop
48+
git pull origin develop
49+
fi
50+
51+
52+
# Install dependencies
53+
echo "의존성 설치"
54+
yarn -v
55+
yarn install
56+
57+
# build
58+
yarn build
59+
60+
# Check and kill existing process
61+
EXISTING_PID=$(lsof -ti :3000)
62+
63+
if [ -n "$EXISTING_PID" ]; then
64+
echo "3000 프로세스 종료 중...: $EXISTING_PID"
65+
kill -9 "$EXISTING_PID"
66+
echo "$EXISTING_PID 프로세스 종료"
67+
else
68+
echo "실행 중인 프로세스가 없습니다."
69+
fi
70+
EXISTING_PID=$(lsof -ti :1234)
71+
72+
if [ -n "$EXISTING_PID" ]; then
73+
echo "1234 프로세스 종료 중...: $EXISTING_PID"
74+
kill -9 "$EXISTING_PID"
75+
echo "$EXISTING_PID 프로세스 종료"
76+
else
77+
echo "실행 중인 프로세스가 없습니다."
78+
fi
79+
EOF
80+
# .env 파일 전송
81+
- name: Copy .env to remote server
82+
uses: appleboy/scp-action@master
83+
with:
84+
host: ${{ secrets.REMOTE_DEV_IP }}
85+
username: ${{ secrets.REMOTE_USER }}
86+
key: ${{ secrets.REMOTE_PRIVATE_KEY }}
87+
source: ./.env
88+
target: /home/root/app/octodocs/apps/backend
89+
- name: Copy .env to remote server
90+
uses: appleboy/scp-action@master
91+
with:
92+
host: ${{ secrets.REMOTE_DEV_IP }}
93+
username: ${{ secrets.REMOTE_USER }}
94+
key: ${{ secrets.REMOTE_PRIVATE_KEY }}
95+
source: ./.env
96+
target: /home/root/app/octodocs/apps/frontend
97+
98+
# yarn start
99+
- name: yarn start
100+
env:
101+
REMOTE_HOST: ${{ secrets.REMOTE_DEV_IP }}
102+
REMOTE_USER: ${{ secrets.REMOTE_USER }}
103+
SSH_KEY: ${{ secrets.REMOTE_PRIVATE_KEY }}
104+
run: |
105+
ssh -o StrictHostKeyChecking=no $REMOTE_USER@$REMOTE_HOST "nohup node /home/root/app/octodocs/apps/backend/dist/main.js > nohup.out 2> nohup.err < /dev/null &"

.github/workflows/main.yml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Create Directory on Remote Server
22
on:
33
push:
44
branches:
5-
- develop
5+
- main
66

77
jobs:
88
env:
@@ -16,15 +16,15 @@ jobs:
1616
# .env 파일 생성 후 붙여넣기
1717
- name: Create .env file
1818
run: |
19-
echo "${{secrets.DEVELOPMENT_ENV}}" > ./.env
19+
echo "${{secrets.PRODUCTION_ENV}}" > ./.env
2020
2121
# sh 실행
2222
- name: Connect to Remote Server and Run Commands
2323
env:
24-
REMOTE_HOST: ${{ secrets.REMOTE_DEV_IP }}
24+
REMOTE_HOST: ${{ secrets.REMOTE_PROD_IP }}
2525
REMOTE_USER: ${{ secrets.REMOTE_USER }}
2626
SSH_KEY: ${{ secrets.REMOTE_PRIVATE_KEY }}
27-
BRANCH_NAME: "develop"
27+
BRANCH_NAME: "main"
2828
run: |
2929
mkdir ~/.ssh
3030
echo "$SSH_KEY" > ~/.ssh/id_rsa
@@ -36,16 +36,16 @@ jobs:
3636
if [ -d "$DIR" ]; then
3737
echo "$DIR 디렉토리가 존재합니다. 최신 버전으로 업데이트 중..."
3838
cd "$DIR"
39-
git switch -c develop
40-
git pull origin develop
39+
git switch -c main
40+
git pull origin main
4141
4242
4343
else
4444
echo "$DIR 디렉토리가 존재하지 않습니다. 클론 중..."
4545
git clone https://github.com/boostcampwm-2024/web15-OctoDocs.git "$DIR"
4646
cd "$DIR"
47-
git switch -c develop
48-
git pull origin develop
47+
git switch -c main
48+
git pull origin main
4949
fi
5050
5151
@@ -61,7 +61,16 @@ jobs:
6161
EXISTING_PID=$(lsof -ti :3000)
6262
6363
if [ -n "$EXISTING_PID" ]; then
64-
echo "프로세스 종료 중...: $EXISTING_PID"
64+
echo "3000 프로세스 종료 중...: $EXISTING_PID"
65+
kill -9 "$EXISTING_PID"
66+
echo "$EXISTING_PID 프로세스 종료"
67+
else
68+
echo "실행 중인 프로세스가 없습니다."
69+
fi
70+
EXISTING_PID=$(lsof -ti :1234)
71+
72+
if [ -n "$EXISTING_PID" ]; then
73+
echo "1234 프로세스 종료 중...: $EXISTING_PID"
6574
kill -9 "$EXISTING_PID"
6675
echo "$EXISTING_PID 프로세스 종료"
6776
else
@@ -72,24 +81,25 @@ jobs:
7281
- name: Copy .env to remote server
7382
uses: appleboy/scp-action@master
7483
with:
75-
host: ${{ secrets.REMOTE_DEV_IP }}
84+
host: ${{ secrets.REMOTE_PROD_IP }}
7685
username: ${{ secrets.REMOTE_USER }}
7786
key: ${{ secrets.REMOTE_PRIVATE_KEY }}
7887
source: ./.env
7988
target: /home/root/app/octodocs/apps/backend
8089
- name: Copy .env to remote server
8190
uses: appleboy/scp-action@master
8291
with:
83-
host: ${{ secrets.REMOTE_DEV_IP }}
92+
host: ${{ secrets.REMOTE_PROD_IP }}
8493
username: ${{ secrets.REMOTE_USER }}
8594
key: ${{ secrets.REMOTE_PRIVATE_KEY }}
8695
source: ./.env
8796
target: /home/root/app/octodocs/apps/frontend
97+
8898
# yarn start
8999
- name: yarn start
90100
env:
91-
REMOTE_HOST: ${{ secrets.REMOTE_DEV_IP }}
101+
REMOTE_HOST: ${{ secrets.REMOTE_PROD_IP }}
92102
REMOTE_USER: ${{ secrets.REMOTE_USER }}
93103
SSH_KEY: ${{ secrets.REMOTE_PRIVATE_KEY }}
94104
run: |
95-
ssh -o StrictHostKeyChecking=no $REMOTE_USER@$REMOTE_HOST "nohup node /home/root/app/octodocs/apps/backend/dist/main.js > nohup.out 2> nohup.err < /dev/null &"
105+
ssh -o StrictHostKeyChecking=no $REMOTE_USER@$REMOTE_HOST "nohup node /home/root/app/octodocs/apps/backend/dist/main.js > nohup.out 2> nohup.err < /dev/null &"

apps/backend/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@nestjs/config": "^3.3.0",
2626
"@nestjs/core": "^10.0.0",
2727
"@nestjs/mapped-types": "*",
28+
"@nestjs/passport": "^10.0.3",
2829
"@nestjs/platform-express": "^10.0.0",
2930
"@nestjs/platform-socket.io": "^10.4.8",
3031
"@nestjs/platform-ws": "^10.4.7",
@@ -38,6 +39,9 @@
3839
"lib0": "^0.2.98",
3940
"node-ts-cache": "^4.4.0",
4041
"node-ts-cache-storage-memory": "^4.4.0",
42+
"passport": "^0.7.0",
43+
"passport-kakao": "^1.0.1",
44+
"passport-naver": "^1.0.6",
4145
"path": "^0.12.7",
4246
"reflect-metadata": "^0.1.13",
4347
"rxjs": "^7.8.1",

apps/backend/src/app.module.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ import { TypeOrmModule } from '@nestjs/typeorm';
99
import { Page } from './page/page.entity';
1010
import { Edge } from './edge/edge.entity';
1111
import { Node } from './node/node.entity';
12+
import { User } from './user/user.entity';
1213
import { YjsModule } from './yjs/yjs.module';
1314
import * as path from 'path';
1415
import { ServeStaticModule } from '@nestjs/serve-static';
1516
import { UploadModule } from './upload/upload.module';
17+
import { AuthModule } from './auth/auth.module';
18+
import { UserModule } from './user/user.module';
1619

1720
@Module({
1821
imports: [
@@ -29,7 +32,7 @@ import { UploadModule } from './upload/upload.module';
2932
useFactory: (configService: ConfigService) => ({
3033
type: 'sqlite',
3134
database: configService.get('DB_NAME'),
32-
entities: [Node, Page, Edge],
35+
entities: [Node, Page, Edge, User],
3336
logging: true,
3437
synchronize: true,
3538
}),
@@ -39,6 +42,8 @@ import { UploadModule } from './upload/upload.module';
3942
EdgeModule,
4043
YjsModule,
4144
UploadModule,
45+
AuthModule,
46+
UserModule,
4247
],
4348
controllers: [AppController],
4449
providers: [AppService],
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { AuthController } from './auth.controller';
3+
import { AuthService } from './auth.service';
4+
5+
describe('AuthController', () => {
6+
let controller: AuthController;
7+
8+
beforeEach(async () => {
9+
const module: TestingModule = await Test.createTestingModule({
10+
controllers: [AuthController],
11+
providers: [
12+
{
13+
provide: AuthService,
14+
useValue: {},
15+
},
16+
],
17+
}).compile();
18+
19+
controller = module.get<AuthController>(AuthController);
20+
});
21+
22+
it('should be defined', () => {
23+
expect(controller).toBeDefined();
24+
});
25+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Controller, Get, UseGuards, Req } from '@nestjs/common';
2+
import { AuthGuard } from '@nestjs/passport';
3+
import { AuthService } from './auth.service';
4+
5+
@Controller('auth')
6+
export class AuthController {
7+
constructor(private readonly authService: AuthService) {}
8+
9+
@Get('naver')
10+
@UseGuards(AuthGuard('naver'))
11+
async naverLogin() {
12+
// 네이버 로그인 페이지로 리디렉션
13+
// Passport가 리디렉션 처리
14+
}
15+
16+
@Get('naver/callback')
17+
@UseGuards(AuthGuard('naver'))
18+
async naverCallback(@Req() req) {
19+
// 네이버 인증 후 사용자 정보 반환
20+
return {
21+
message: '네이버 로그인 성공',
22+
user: req.user,
23+
};
24+
}
25+
26+
@Get('kakao')
27+
@UseGuards(AuthGuard('kakao'))
28+
async kakaoLogin() {
29+
// 카카오 로그인 페이지로 리디렉션
30+
// Passport가 리디렉션 처리
31+
}
32+
33+
@Get('kakao/callback')
34+
@UseGuards(AuthGuard('kakao'))
35+
async kakaoCallback(@Req() req) {
36+
// 카카오 인증 후 사용자 정보 반환
37+
return {
38+
message: '카카오 로그인 성공',
39+
user: req.user,
40+
};
41+
}
42+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Module } from '@nestjs/common';
2+
import { UserRepository } from '../user/user.repository';
3+
import { UserModule } from 'src/user/user.module';
4+
import { AuthService } from './auth.service';
5+
import { AuthController } from './auth.controller';
6+
import { NaverStrategy } from './strategies/naver.strategy';
7+
import { KakaoStrategy } from './strategies/kakao.strategy';
8+
@Module({
9+
imports: [UserModule],
10+
controllers: [AuthController],
11+
providers: [AuthService, NaverStrategy, KakaoStrategy, UserRepository],
12+
})
13+
export class AuthModule {}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { AuthService } from './auth.service';
3+
import { UserRepository } from '../user/user.repository';
4+
5+
describe('AuthService', () => {
6+
let service: AuthService;
7+
8+
beforeEach(async () => {
9+
const module: TestingModule = await Test.createTestingModule({
10+
providers: [
11+
AuthService,
12+
{
13+
provide: UserRepository,
14+
useValue: {},
15+
},
16+
],
17+
}).compile();
18+
19+
service = module.get<AuthService>(AuthService);
20+
});
21+
22+
it('should be defined', () => {
23+
expect(service).toBeDefined();
24+
});
25+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Injectable } from '@nestjs/common';
2+
import { UserRepository } from '../user/user.repository';
3+
import { User } from '../user/user.entity';
4+
import { CreateUserDto } from './dto/createUser.dto';
5+
6+
@Injectable()
7+
export class AuthService {
8+
constructor(private readonly userRepository: UserRepository) {}
9+
10+
async findUser(dto: CreateUserDto): Promise<User | null> {
11+
const { providerId, provider } = dto;
12+
13+
const user = await this.userRepository.findOne({
14+
where: { providerId, provider },
15+
});
16+
17+
return user;
18+
}
19+
20+
async createUser(dto: CreateUserDto): Promise<User> {
21+
const user = this.userRepository.create(dto);
22+
return this.userRepository.save(user);
23+
}
24+
}

0 commit comments

Comments
 (0)