Skip to content

Commit

Permalink
Merge pull request #347 from boostcampwm-2022/develop
Browse files Browse the repository at this point in the history
Release v1.0.4
  • Loading branch information
username1103 authored Jan 22, 2023
2 parents 738b889 + cee8faf commit f858025
Show file tree
Hide file tree
Showing 40 changed files with 2,401 additions and 264 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backend-dev-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
username: ${{ secrets.BACKEND_DEV_REMOTE_SSH_ID }}
password: ${{ secrets.BACKEND_DEV_REMOTE_ADMIN_KEY }}
port: ${{ secrets.BACKEND_DEV_REMOTE_SSH_PORT }}
source: 'backend/docker-compose.yml,backend/nginx/dev/nginx.conf,backend/scripts/dev-deploy.sh'
source: 'backend/docker-compose.yml,backend/nginx/dev/conf/nginx.conf,backend/scripts/dev-deploy.sh'
target: 'moyeomoyeo'

- name: deploy
Expand Down
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,43 @@

<br></br>

# โœจ ์ฃผ์š” ๊ธฐ๋Šฅ

[๐Ÿ‘‰๐Ÿป ์‹œ์—ฐ์˜์ƒ ๋ณด๋Ÿฌ๊ฐ€๊ธฐ](https://www.youtube.com/watch?v=FR3IAFBxvO4)

<table>
<tr>
<td align="center" width="25%">๋ชจ์ง‘๊ฒŒ์‹œ๊ธ€ ๋ชฉ๋ก ์กฐํšŒ</td>
<td align="center" width="25%">๋ชจ์ง‘ ๊ฒŒ์‹œ๊ธ€ ๋“ฑ๋ก</td>
<td align="center" width="25%">๋ชจ์ง‘ ์‹ ์ฒญ ์ฐธ๊ฐ€/์ทจ์†Œ</td>
<td align="center" width="25%">๋ชจ์ง‘ ์„ฑ์‚ฌ ์•Œ๋ฆผ, ์˜คํ”ˆ์ฑ„ํŒ…๋ฐฉ ๋งํฌ</td>
</tr>
<tr>
<td><img src="https://user-images.githubusercontent.com/67570061/207778404-43ffe050-fdeb-41a0-a77e-db3977ab4a1c.gif"/></td>
<td><img src="https://user-images.githubusercontent.com/67570061/207778608-54e0a59a-5998-413b-8650-c9a8839a4179.gif"/></td>
<td><img src="https://user-images.githubusercontent.com/67570061/207778658-2bf27fc2-b55c-4621-8776-f8c72c8ca9ea.gif"/></td>
<td><img src="https://user-images.githubusercontent.com/67570061/207779175-1ca1f5f6-0cf4-4b96-bfa2-cbbe1cb494e3.gif"/></td>
</tr>
<tr>
<td>๋ฌดํ•œ ์Šคํฌ๋กค์„ ํ†ตํ•œ ํŽ˜์ด์ง€๋„ค์ด์…˜์ด ์ ์šฉ๋˜์–ด ์žˆ์œผ๋ฉฐ, ํ•„ํ„ฐ๋ง์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.</td>
<td>์›ํ•˜๋Š” ๋ชจ์ž„ ๋ชจ์ง‘ ๊ฒŒ์‹œ๊ธ€์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.</td>
<td>๋ชจ์ง‘์ค‘์ธ ๋ชจ์ž„์— ์ฐธ๊ฐ€ ์‹ ์ฒญ/์ทจ์†Œ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.</td>
<td>๋ชจ์ง‘์ด ์™„๋ฃŒ๋˜๋ฉด ์•Œ๋ฆผ์ด ๋ฐœ์†ก๋˜๋ฉฐ, ์˜คํ”ˆ์ฑ„ํŒ…๋ฐฉ ๋งํฌ๋ฅผ ํ†ตํ•ด ๋ชจ์ž„ ์ฑ„ํŒ…๋ฐฉ์— ์ฐธ์—ฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.</td>
</tr>
</table>



# ๐Ÿซต ํ”„๋กœ์ ํŠธ ํฌ์ธํŠธ
<br></br>


๊ฐ•์กฐํ•˜๊ณ  ์‹ถ์€ ๊ฒƒ๋“ค
# ๐Ÿซต ํ”„๋กœ์ ํŠธ ํฌ์ธํŠธ

- ์ค‘๋ณต ๊ฒŒ์‹œ๊ธ€ ์กฐํšŒ ๋ฐฉ์ง€๋ฅผ ์œ„ํ•ด ํŽ˜์ด์ง€๋„ค์ด์…˜ ๋ฐฉ์‹ ๋ณ€๊ฒฝ ๋ฐ ์ฟผ๋ฆฌ ๊ฐœ์„ ์„ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค. [๐Ÿ‘‰๐Ÿป๋ณด๋Ÿฌ๊ฐ€๊ธฐ](https://boostcamp-wm.notion.site/feat-2a1dd8ea684d44ebb7176d5efbbc8aeb)
- `custom hook`, `error class`, `ErrorBoundary`๋ฅผ ์ด์šฉํ•˜์—ฌ API ํ•ต์‹ฌ ๋กœ์ง๊ณผ ์—๋Ÿฌ ์ฒ˜๋ฆฌ์˜ ๊ด€์‹ฌ์‚ฌ๋ฅผ ๋ถ„๋ฆฌํ•˜์˜€๊ณ ,<br/>์‚ฌ์šฉ์ž์—๊ฒŒ ์ ์ ˆํ•œ ์˜ค๋ฅ˜ ํ™”๋ฉด์„ ๋ณด์—ฌ์ฃผ๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค. [๐Ÿ‘‰๐Ÿป๋ณด๋Ÿฌ๊ฐ€๊ธฐ](https://boostcamp-wm.notion.site/957e4b7034d64d0c8fa59f47e58c112d)
- ์„ฑ๋Šฅ ๋ฐ ์‚ฌ์šฉ์ž ๊ฒฝํ—˜ ๊ฐœ์„ ์„ ์œ„ํ•ด ์ด๋ฏธ์ง€ ์ตœ์ ํ™”์™€ SSR, Blur, Skeleton์„ ์ ์šฉ ํ–ˆ์Šต๋‹ˆ๋‹ค. [๐Ÿ‘‰๐Ÿป๋ณด๋Ÿฌ๊ฐ€๊ธฐ](https://boostcamp-wm.notion.site/e959fbc871514fb29a407dfe3f2447b9)
- ์ปดํฌ๋„ŒํŠธ์˜ ์ฒด๊ณ„์ ์ธ ์„ค๊ณ„์™€ ๋ฌธ์„œํ™”๋ฅผ ํ†ตํ•ด ๊ฐœ๋ฐœ์ž ๊ฒฝํ—˜์„ ํ–ฅ์ƒ์‹œํ‚ค๊ณ ์ž ์Šคํ† ๋ฆฌ๋ถ์„ ๋„์ž…ํ–ˆ์Šต๋‹ˆ๋‹ค. [๐Ÿ‘‰๐Ÿป๋ณด๋Ÿฌ๊ฐ€๊ธฐ](https://boostcamp-wm.notion.site/a54eb762007f4ec185ee008a396d7a82)
- CI/CD ํŒŒ์ดํ”„๋ผ์ธ์„ ๊ตฌ์ถ•ํ•˜๊ณ  ์ง€์†์ ์œผ๋กœ ๊ฐœ์„ ํ–ˆ์Šต๋‹ˆ๋‹ค. CI ์‹œ๊ฐ„์„ ์•ฝ 40s ๋‹จ์ถ•ํ–ˆ์Šต๋‹ˆ๋‹ค. [๐Ÿ‘‰๐Ÿป๋ณด๋Ÿฌ๊ฐ€๊ธฐ](https://boostcamp-wm.notion.site/CI-CD-e6f15386baa34b238884678928ff3c61)

<br></br>

Expand Down
37 changes: 23 additions & 14 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ services:
image: nginx
restart: always
volumes:
- ./nginx/dev:/etc/nginx/conf.d
- ./nginx/dev/conf:/etc/nginx/conf.d
- /letsencrypt/certbot/conf:/etc/letsencrypt
- /letsencrypt/certbot/www:/var/www/certbot
ports:
- 80:80
- 443:443
depends_on:
- moyeo-server
networks:
- backbone
command: '/bin/sh -c ''while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g "daemon off;"'''
Expand All @@ -31,17 +29,6 @@ services:
- backbone
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"

moyeo-server:
container_name: moyeo-server
image: ${DOCKER_SERVER_IMAGE}
environment:
NODE_ENV: development
ports:
- 3000:3000
command: npm run start:dev
networks:
- backbone

moyeo-db:
container_name: moyeo-db
image: mysql:8.0
Expand All @@ -61,6 +48,28 @@ services:
networks:
- backbone

moyeo-server-green:
container_name: moyeo-server-green
image: ${DOCKER_SERVER_IMAGE}
environment:
NODE_ENV: development
expose:
- 3000
command: npm run start:dev
networks:
- backbone

moyeo-server-blue:
container_name: moyeo-server-blue
image: ${DOCKER_SERVER_IMAGE}
environment:
NODE_ENV: development
expose:
- 3000
command: npm run start:dev
networks:
- backbone

networks:
backbone:
driver: bridge
6 changes: 6 additions & 0 deletions backend/local/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ server {
proxy_pass http://backend-server;
proxy_http_version 1.1;
}

location = /v1/sse {
proxy_pass http://backend-server;
proxy_http_version 1.1;
proxy_read_timeout 600s;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

upstream backend-server {
server moyeo-server:3000;
server moyeo-server-blue:3000;
}

server {
Expand Down Expand Up @@ -35,4 +35,10 @@ server {
proxy_pass http://backend-server;
proxy_http_version 1.1;
}

location = /v1/sse {
proxy_pass http://backend-server;
proxy_http_version 1.1;
proxy_read_timeout 600s;
}
}
6 changes: 6 additions & 0 deletions backend/nginx/prod/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ server {
proxy_pass http://backend-server;
proxy_http_version 1.1;
}

location = /v1/sse {
proxy_pass http://backend-server;
proxy_http_version 1.1;
proxy_read_timeout 600s;
}
}
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"start:prod": "node dist/main",
"start:local": "docker compose -f docker-compose.local.yml up -d --build",
"stop:local": "docker compose -f docker-compose.local.yml down",
"reload:local": "docker compose -f docker-compose.local.yml up --force-recreate -d",
"reload:local": "docker compose -f docker-compose.local.yml up -d --build",
"lint:fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
"test": "env-cmd -f .env.test jest",
Expand Down
47 changes: 42 additions & 5 deletions backend/scripts/dev-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,45 @@ echo -e $4 > .env

echo "create .env"

# docker down
docker compose down --rmi all --remove-orphans

# docker up
docker compose up -d --build
RUNNING_APPLICATION=$(docker ps | grep moyeo-server-blue)
DEFAULT_CONF="./nginx/dev/conf/nginx.conf"

if [ -n "$RUNNING_APPLICATION" ];then
echo "green Deploy..."
docker compose pull moyeo-server-green
docker compose up -d moyeo-server-green
docker rmi $(docker images -f "dangling=true" -q)

while [ 1 == 1 ]; do
echo "green health check...."
REQUEST=$(docker exec moyeo-nginx curl http://moyeo-server-green:3000)
echo $REQUEST
if [ -n "$REQUEST" ]; then
break ;
fi
sleep 3
done;

sed -i 's/moyeo-server-blue/moyeo-server-green/g' $DEFAULT_CONF
docker exec moyeo-nginx service nginx reload
docker compose stop moyeo-server-blue
else
echo "blue Deploy..."
docker compose pull moyeo-server-blue
docker compose up -d moyeo-server-blue
docker rmi $(docker images -f "dangling=true" -q)

while [ 1 == 1 ]; do
echo "blue health check...."
REQUEST=$(docker exec moyeo-nginx curl http://moyeo-server-blue:3000)
echo $REQUEST
if [ -n "$REQUEST" ]; then
break ;
fi
sleep 3
done;

sed -i 's/moyeo-server-green/moyeo-server-blue/g' $DEFAULT_CONF
docker exec moyeo-nginx service nginx reload
docker compose stop moyeo-server-green
fi
38 changes: 0 additions & 38 deletions backend/src/app.controller.spec.ts

This file was deleted.

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

This file was deleted.

12 changes: 6 additions & 6 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AppConfigModule } from '@config/app/config.module';
import { ApiSuccessLoggerMiddleware } from '@middleware/api-success-logger.middleware';
import { ApiExceptionLoggerMiddleware } from '@middleware/api-exception-logger.middleware';
Expand All @@ -17,6 +15,8 @@ import { GroupApplicationModule } from '@app/group-application/group-application
import { NotificationModule } from '@app/notification/notification.module';
import { CommentModule } from '@app/comment/comment.module';
import { AppConfigService } from '@common/config/app/config.service';
import { SseModule } from '@common/module/sse/sse.module';
import { SseController } from '@src/sse.controller';

@Module({
imports: [
Expand All @@ -33,15 +33,15 @@ import { AppConfigService } from '@common/config/app/config.service';
GroupApplicationModule,
NotificationModule,
CommentModule,
SseModule,
],
controllers: [AppController],
providers: [AppService],
controllers: [SseController],
})
export class AppModule implements NestModule {
constructor(private readonly appConfigSerivce: AppConfigService) {}
constructor(private readonly appConfigService: AppConfigService) {}

configure(consumer: MiddlewareConsumer) {
if (!this.appConfigSerivce.isTest()) {
if (!this.appConfigService.isTest()) {
consumer
.apply(ApiSuccessLoggerMiddleware, ApiExceptionLoggerMiddleware)
.forRoutes('*');
Expand Down
8 changes: 0 additions & 8 deletions backend/src/app.service.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class GroupArticleRegisterRequest {
required: true,
})
@IsString()
@Length(1)
contents: string;

@ApiProperty({
Expand Down Expand Up @@ -66,6 +67,7 @@ export class GroupArticleRegisterRequest {
description: '์ธ๋„ค์ผ ์ด๋ฏธ์ง€๊ฐ€ ์ €์žฅ๋˜์–ด์žˆ๋Š” ์ฃผ์†Œ(url)',
required: true,
})
@Length(1)
@IsUrl()
thumbnail: string;

Expand All @@ -75,5 +77,6 @@ export class GroupArticleRegisterRequest {
required: false,
})
@IsString()
@Length(1)
chatUrl: string;
}
2 changes: 1 addition & 1 deletion backend/src/app/group-article/group-article.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class GroupArticleController {

@Get('search')
@Version('2')
@ApiSuccessResponse(HttpStatus.OK)
@ApiSuccessResponse(HttpStatus.OK, V2SearchGroupArticlesResponse)
async searchV2(@Query() query: V2SearchGroupArticlesRequest) {
const result = await this.groupArticleRepository.searchV2({
limit: query.limit,
Expand Down
23 changes: 23 additions & 0 deletions backend/src/app/notification/dto/notification-sse.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { MessageEvent } from '@nestjs/common';
import { GetUserNotificationResult } from '@app/notification/dto/get-user-notification-result.dto';
import { UserNotification } from '@app/notification/entity/user-notification.entity';
import { randomUUID } from 'crypto';

export class NotificationSse implements MessageEvent {
id: string;
data: GetUserNotificationResult;
type: string;

retry: number;

static async from(userNotification: UserNotification) {
const notificationSse = new NotificationSse();
notificationSse.id = randomUUID();
notificationSse.data = await GetUserNotificationResult.from(
userNotification,
);
notificationSse.type = 'NOTIFICATION';
notificationSse.retry = 3 * 1000;
return notificationSse;
}
}
Loading

0 comments on commit f858025

Please sign in to comment.