Skip to content

Commit

Permalink
deploy v0.1 추가 (#144)
Browse files Browse the repository at this point in the history
* ✨ feat(module openapi-scrapper 추가): module로 개발 시작

* 🚚 chore: backend packege 의존성 업데이트

* ✨ feat: backend/stock-price 추가

* 🚚 chore: yarn.lock 업데이트

* ✨ feat(korea-stock-info.*.ts): 한국 주식 데이터를 파싱하고, 가져오는 것을 제작함

* 🚚 chore: deploy 추가, front, backend dockerfile 추가

* commit after merge

* 🚚 chore: yarn.lock, package.json

ISSUES CLOSED: unzipper, axios 설치

* 🚚 chore: yarn.lock, workflows 업데이트 - dev,fe,be 모두 작동

* 🚚 chore: type unzipper 추가

* 🚚 chore: path 문제 해결 - build -\> dist, packages/fronted/dist =\> dist

* 🚚 chore: server password

* 🚚 chore: tsconfig.buildjson output dir 추가

* 📦️ ci: frontend dockerfile 수정

* ✨ feat: 구글 로그인 페이지 이동 관련 swagger 설정

* ✨ feat: 구글 로그인 성공시 리다이렉트 엔드포인트 구현

* ✨ feat: 구글 oauth 서버로부터 access token 획득

* ♻️ refactor: request 관련 타입 수정

* ✨ feat: 구글 oauth 로그인 성공 후 사용자 정보를 획득

* ✨ feat(module openapi-scrapper 추가): module로 개발 시작

* ✨ feat: backend/stock-price 추가

* ✨ feat(korea-stock-info.*.ts): 한국 주식 데이터를 파싱하고, 가져오는 것을 제작함

* 🐛 fix: 리뷰 반영 -  env, 중복코드 제거, .vscode 삭제 / dto 사용 확대

* 🚚 chore: backend package prod 위치 변경

* 📦️ ci: package.json 수정 - ..좋은 방법은 아니지만..

* 📦️ ci: packages.json 중복 삭제

* 🐛 fix: 충돌로 발생한 문제 해결

* 🚚 chore: deploy.yml backend 부터 만들게 설정

* 🚚 chore: deploy docker-down 추가

* 📦️ ci: 편-안하게 ssh로 변경, pull request 작동 삭제

* 📦️ ci: front, backend action 다르게 설정.

* 📦️ ci: 이름 변경

---------

Co-authored-by: kimminsu <[email protected]>
  • Loading branch information
swkim12345 and xjfcnfw3 authored Nov 13, 2024
1 parent 91fed6d commit e5a3de4
Show file tree
Hide file tree
Showing 28 changed files with 590 additions and 59 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/deploy-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Deploy Backend in Monorepo

on:
push:
branches:
- dev-be

jobs:
build-and-deploy:
runs-on: ubuntu-latest

services:
docker:
image: docker:20.10.7
options: --privileged

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache Yarn dependencies
uses: actions/cache@v3
with:
path: |
**/node_modules
~/.yarn-cache
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Build backend
run: |
yarn workspace backend build
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push backend Docker image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/backend:latest -f packages/backend/Dockerfile .
docker push ${{ secrets.DOCKER_USERNAME }}/backend:latest
- name: Deploy to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY}}
port: ${{ secrets.SERVER_PORT }}
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/backend:latest
docker-compose down
docker-compose up -d
65 changes: 65 additions & 0 deletions .github/workflows/deploy-frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Deploy Frontend in Monorepo

on:
push:
branches:
- dev-fe

jobs:
build-and-deploy:
runs-on: ubuntu-latest

services:
docker:
image: docker:20.10.7
options: --privileged

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache Yarn dependencies
uses: actions/cache@v3
with:
path: |
**/node_modules
~/.yarn-cache
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Build frontend
run: |
yarn workspace frontend build
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push backend Docker image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/backend:latest -f packages/backend/Dockerfile .
docker push ${{ secrets.DOCKER_USERNAME }}/backend:latest
- name: Deploy to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY}}
port: ${{ secrets.SERVER_PORT }}
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/frontend:latest
docker-compose down
docker-compose up -d
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ pids
*.pid.lock

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# vscode setting
.vscode
7 changes: 7 additions & 0 deletions packages/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:20-alpine
WORKDIR /packages
COPY . .
RUN yarn install --frozen-lockfile
RUN yarn workspace backend build
EXPOSE 3000
CMD ["yarn", "workspace", "backend", "start:prod"]
7 changes: 6 additions & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"start:prod": "node ../../dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
Expand All @@ -21,13 +21,15 @@
},
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.3.0",
"@nestjs/core": "^10.0.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-socket.io": "^10.4.7",
"@nestjs/swagger": "^8.0.5",
"@nestjs/typeorm": "^10.0.2",
"@nestjs/websockets": "^10.4.7",
"axios": "^1.7.7",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"dotenv": "^16.4.5",
Expand All @@ -40,6 +42,7 @@
"rxjs": "^7.8.1",
"socket.io": "^4.8.1",
"typeorm": "^0.3.20",
"unzipper": "^0.12.3",
"winston": "^3.17.0",
"winston-daily-rotate-file": "^5.0.0"
},
Expand All @@ -53,8 +56,10 @@
"@types/node": "^20.3.1",
"@types/passport-google-oauth20": "^2.0.16",
"@types/supertest": "^6.0.0",
"@types/unzipper": "^0.10.10",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"cz-emoji-conventional": "^1.1.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
Expand Down
22 changes: 0 additions & 22 deletions packages/backend/src/app.controller.spec.ts

This file was deleted.

16 changes: 0 additions & 16 deletions packages/backend/src/app.controller.ts

This file was deleted.

8 changes: 4 additions & 4 deletions packages/backend/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { WinstonModule } from 'nest-winston';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AuthModule } from '@/auth/auth.module';
import { logger } from '@/configs/logger.config';
import {
Expand All @@ -14,6 +12,8 @@ import { UserModule } from '@/user/user.module';

@Module({
imports: [
//OpenapiScraperModule,
//StockPriceModule,
StockModule,
UserModule,
TypeOrmModule.forRoot(
Expand All @@ -24,7 +24,7 @@ import { UserModule } from '@/user/user.module';
WinstonModule.forRoot(logger),
AuthModule,
],
controllers: [AppController],
providers: [AppService],
controllers: [],
providers: [],
})
export class AppModule {}
8 changes: 0 additions & 8 deletions packages/backend/src/app.service.ts

This file was deleted.

5 changes: 3 additions & 2 deletions packages/backend/src/auth/passport/google.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Injectable } from '@nestjs/common';
import { Inject, Injectable } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { Profile, Strategy, VerifyCallback } from 'passport-google-oauth20';
import { GoogleAuthService } from '@/auth/googleAuth.service';
import { OauthType } from '@/user/domain/ouathType';
import { Logger } from 'winston';

export interface OauthUserInfo {
type: OauthType;
Expand All @@ -14,7 +15,7 @@ export interface OauthUserInfo {

@Injectable()
export class GoogleStrategy extends PassportStrategy(Strategy) {
constructor(private readonly googleAuthService: GoogleAuthService) {
constructor(private readonly googleAuthService: GoogleAuthService, @Inject('winston') private readonly logger: Logger) {
super({
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { IsString } from "class-validator";

export class MasterDownloadDto {
@IsString()
baseDir!: string;

@IsString()
target: string;

constructor(baseDir: string, target: string) {
this.baseDir = baseDir;
this.target = target;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { IsArray } from 'class-validator';

export class MasterSplit {
@IsArray()
shortCode: [number, number];

@IsArray()
standardCode: [number, number];

@IsArray()
koreanName: [number, number];

@IsArray()
groupCode: [number, number];

@IsArray()
marketCapSize: [number, number];

constructor(
shortCode: [number, number],
standardCode: [number, number],
koreanName: [number, number],
groupCode: [number, number],
marketCapSize: [number, number],
) {
this.shortCode = shortCode;
this.standardCode = standardCode;
this.koreanName = koreanName;
this.groupCode = groupCode;
this.marketCapSize = marketCapSize;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';

//TODO : entity update require
@Entity()
export class Master {
@PrimaryGeneratedColumn({ type: 'int', unsigned: true })
id?: number;

@Column()
shortCode?: string;

@Column()
standardCode?: string;

@Column()
koreanName?: string;

@Column()
groupCode?: string;

@Column()
marketCapSize?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { KoreaStockInfoController } from './korea-stock-info.controller';

describe('KoreaStockInfoController', () => {
let controller: KoreaStockInfoController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [KoreaStockInfoController],
}).compile();

controller = module.get<KoreaStockInfoController>(KoreaStockInfoController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Controller } from '@nestjs/common';

@Controller('korea-stock-info')
export class KoreaStockInfoController {}
Loading

0 comments on commit e5a3de4

Please sign in to comment.