From e1573b92afef60a7e627c7a39fd5aa2a751e041a Mon Sep 17 00:00:00 2001 From: "Ji-Hyuck, Min" <45284810+jhMin95@users.noreply.github.com> Date: Sun, 30 Jul 2023 22:15:39 +0900 Subject: [PATCH 1/5] =?UTF-8?q?chore:=20=EC=9E=90=EB=8F=99=20=EB=B0=B1?= =?UTF-8?q?=EC=97=85=EC=9D=84=20cron=20=EC=9C=BC=EB=A1=9C=20=EC=A7=84?= =?UTF-8?q?=ED=96=89=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=9C=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=EB=B3=80=EC=88=98=20=EC=B6=94=EA=B0=80=20(#606)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 서버에서 매일 백업하고 진행 결과를 admin 유저에게 슬랙 알림으로 보내주기 위함 --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 68a3c6fd..af70210c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -51,6 +51,9 @@ jobs: MYSQL_DATABASE=${{ secrets.MYSQL_DATABASE }} MYSQL_USER=${{ secrets.MYSQL_USER }} MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }} + BACKUP_USER=${{ secrets.BACKUP_USER}} + BACKUP_PASSWORD=${{ secrets.BACKUP_PASSWORD }} + ADMIN_SLACK_ID=${{ secrets.ADMIN_SLACK_ID }} DB_SCHEMA=${{ secrets.DB_SCHEMA }} MODE=${{ secrets.MODE }} NODE_ENV=${{ secrets.NODE_ENV }} From a837dc9b6d9390c41676212628d3aaefb4dafa75 Mon Sep 17 00:00:00 2001 From: scarf Date: Mon, 31 Jul 2023 09:28:30 +0900 Subject: [PATCH 2/5] =?UTF-8?q?fix:=20=EB=A1=9C=EA=B7=B8=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20=EA=B2=BD=EB=A1=9C=EB=A5=BC=20`backend/logs`?= =?UTF-8?q?=EB=A1=9C=20=EC=9B=90=EB=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/app.ts | 2 +- backend/src/{v1/utils => }/logger.ts | 2 +- backend/src/mysql.ts | 2 +- backend/src/server.ts | 6 +++--- backend/src/v1/auth/auth.controller.ts | 6 +++--- backend/src/v1/auth/auth.validate.ts | 6 +++--- backend/src/v1/auth/auth.validateDefaultNullUser.ts | 6 +++--- backend/src/v1/books/books.controller.ts | 2 +- backend/src/v1/books/books.service.ts | 4 ++-- backend/src/v1/histories/histories.controller.ts | 4 ++-- backend/src/v1/lendings/lendings.controller.ts | 2 +- backend/src/v1/reservations/reservations.controller.ts | 6 +++--- backend/src/v1/slack/slack.controller.ts | 2 +- backend/src/v1/slack/slack.service.ts | 2 +- backend/src/v1/users/users.controller.ts | 7 +++---- backend/src/v1/users/users.service.spec.ts | 2 +- backend/src/v1/utils/error/errorConverter.ts | 4 +--- backend/src/v1/utils/error/errorHandler.ts | 4 ++-- 18 files changed, 33 insertions(+), 36 deletions(-) rename backend/src/{v1/utils => }/logger.ts (98%) diff --git a/backend/src/app.ts b/backend/src/app.ts index 81b7d7ce..e993819b 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -6,11 +6,11 @@ import swaggerJsdoc from 'swagger-jsdoc'; import swaggerUi from 'swagger-ui-express'; import jipDataSource from '~/app-data-source'; import { connectMode } from '~/config'; +import { logger, morganMiddleware } from '~/logger'; import { FtAuthentication, FtStrategy, JwtStrategy } from '~/v1/auth/auth.strategy'; import swaggerOptions from '~/v1/swagger/swagger'; import errorConverter from '~/v1/utils/error/errorConverter'; import errorHandler from '~/v1/utils/error/errorHandler'; -import { logger, morganMiddleware } from '~/v1/utils/logger'; // eslint-disable-next-line import/no-extraneous-dependencies import { contract } from '@jiphyeonjeon-42/contracts'; diff --git a/backend/src/v1/utils/logger.ts b/backend/src/logger.ts similarity index 98% rename from backend/src/v1/utils/logger.ts rename to backend/src/logger.ts index 3a6c6409..55e1711b 100644 --- a/backend/src/v1/utils/logger.ts +++ b/backend/src/logger.ts @@ -19,7 +19,7 @@ const { addColors(colors); -const logDir = '../../logs'; +const logDir = '../logs'; const logTimestampFormat = 'YYYY-MM-DD HH:mm:ss:ms'; const datePattern = 'YYYY-MM-DD'; diff --git a/backend/src/mysql.ts b/backend/src/mysql.ts index 260c7b4a..4940f01f 100644 --- a/backend/src/mysql.ts +++ b/backend/src/mysql.ts @@ -1,7 +1,7 @@ import { FieldPacket } from 'mysql2'; import mysql from 'mysql2/promise'; -import { logger } from '~/v1/utils/logger'; import { connectOption } from '~/config'; +import { logger } from '~/logger'; export const DBError = 'DB error'; diff --git a/backend/src/server.ts b/backend/src/server.ts index 52ba0693..4dac0c85 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -1,8 +1,8 @@ import { createHttpTerminator } from 'http-terminator'; -import { logger } from '~/v1/utils/logger'; -import scheduler from '~/v1/utils/scheduler'; -import { gracefulTerminationTimeout } from '~/config'; import jipDataSource from '~/app-data-source'; +import { gracefulTerminationTimeout } from '~/config'; +import { logger } from '~/logger'; +import scheduler from '~/v1/utils/scheduler'; import app from './app'; const port = '3000'; diff --git a/backend/src/v1/auth/auth.controller.ts b/backend/src/v1/auth/auth.controller.ts index 1d048045..e2a63eb2 100644 --- a/backend/src/v1/auth/auth.controller.ts +++ b/backend/src/v1/auth/auth.controller.ts @@ -2,11 +2,11 @@ import * as bcrypt from 'bcrypt'; import { NextFunction, Request, Response } from 'express'; import * as status from 'http-status'; import { randomUUID } from 'node:crypto'; -import * as errorCode from '~/v1/utils/error/errorCode'; -import ErrorResponse from '~/v1/utils/error/errorResponse'; -import { logger } from '~/v1/utils/logger'; import { oauth42ApiOption, oauthUrlOption } from '~/config'; +import { logger } from '~/logger'; import UsersService from '~/v1/users/users.service'; +import * as errorCode from '~/v1/utils/error/errorCode'; +import ErrorResponse from '~/v1/utils/error/errorResponse'; import * as models from '../DTO/users.model'; import { updateSlackIdByUserId } from '../slack/slack.service'; import * as authJwt from './auth.jwt'; diff --git a/backend/src/v1/auth/auth.validate.ts b/backend/src/v1/auth/auth.validate.ts index eb874f22..9fc964c7 100644 --- a/backend/src/v1/auth/auth.validate.ts +++ b/backend/src/v1/auth/auth.validate.ts @@ -1,11 +1,11 @@ import { Request, Response } from 'express'; import * as status from 'http-status'; import { verify } from 'jsonwebtoken'; -import * as errorCode from '~/v1/utils/error/errorCode'; -import ErrorResponse from '~/v1/utils/error/errorResponse'; -import { logger } from '~/v1/utils/logger'; import { jwtOption } from '~/config'; +import { logger } from '~/logger'; import UsersService from '~/v1/users/users.service'; +import * as errorCode from '~/v1/utils/error/errorCode'; +import ErrorResponse from '~/v1/utils/error/errorResponse'; import { User } from '../DTO/users.model'; import { role } from './auth.type'; diff --git a/backend/src/v1/auth/auth.validateDefaultNullUser.ts b/backend/src/v1/auth/auth.validateDefaultNullUser.ts index 3af67506..17f60864 100644 --- a/backend/src/v1/auth/auth.validateDefaultNullUser.ts +++ b/backend/src/v1/auth/auth.validateDefaultNullUser.ts @@ -1,11 +1,11 @@ import { Request, Response } from 'express'; import * as status from 'http-status'; import { verify } from 'jsonwebtoken'; -import * as errorCode from '~/v1/utils/error/errorCode'; -import ErrorResponse from '~/v1/utils/error/errorResponse'; -import { logger } from '~/v1/utils/logger'; import { jwtOption } from '~/config'; +import { logger } from '~/logger'; import UsersService from '~/v1/users/users.service'; +import * as errorCode from '~/v1/utils/error/errorCode'; +import ErrorResponse from '~/v1/utils/error/errorResponse'; import { User } from '../DTO/users.model'; import { role } from './auth.type'; diff --git a/backend/src/v1/books/books.controller.ts b/backend/src/v1/books/books.controller.ts index 054593a4..198e499c 100644 --- a/backend/src/v1/books/books.controller.ts +++ b/backend/src/v1/books/books.controller.ts @@ -2,10 +2,10 @@ import { NextFunction, Request, RequestHandler, Response, } from 'express'; import * as status from 'http-status'; +import { logger } from '~/logger'; import * as errorCode from '~/v1/utils/error/errorCode'; import ErrorResponse from '~/v1/utils/error/errorResponse'; import isNullish from '~/v1/utils/isNullish'; -import { logger } from '~/v1/utils/logger'; import * as BooksService from './books.service'; import * as types from './books.type'; import LikesService from './likes.service'; diff --git a/backend/src/v1/books/books.service.ts b/backend/src/v1/books/books.service.ts index 657542d5..5c019d85 100644 --- a/backend/src/v1/books/books.service.ts +++ b/backend/src/v1/books/books.service.ts @@ -1,12 +1,12 @@ /* eslint-disable prefer-regex-literals */ /* eslint-disable prefer-destructuring */ import axios from 'axios'; +import jipDataSource from '~/app-data-source'; import { nationalIsbnApiKey, naverBookApiOption } from '~/config'; +import { logger } from '~/logger'; import { executeQuery } from '~/mysql'; import * as errorCode from '~/v1/utils/error/errorCode'; -import { logger } from '~/v1/utils/logger'; import { StringRows } from '~/v1/utils/types'; -import jipDataSource from '~/app-data-source'; import * as models from './books.model'; import BooksRepository from './books.repository'; import { diff --git a/backend/src/v1/histories/histories.controller.ts b/backend/src/v1/histories/histories.controller.ts index 7bdb65ac..01de6a3a 100644 --- a/backend/src/v1/histories/histories.controller.ts +++ b/backend/src/v1/histories/histories.controller.ts @@ -2,9 +2,9 @@ import { NextFunction, Request, Response, } from 'express'; import * as status from 'http-status'; -import ErrorResponse from '~/v1/utils/error/errorResponse'; -import { logger } from '~/v1/utils/logger'; +import { logger } from '~/logger'; import * as errorCode from '~/v1/utils/error/errorCode'; +import ErrorResponse from '~/v1/utils/error/errorResponse'; import * as historiesService from './histories.service'; // eslint-disable-next-line import/prefer-default-export diff --git a/backend/src/v1/lendings/lendings.controller.ts b/backend/src/v1/lendings/lendings.controller.ts index 9e79cad1..e47ca818 100644 --- a/backend/src/v1/lendings/lendings.controller.ts +++ b/backend/src/v1/lendings/lendings.controller.ts @@ -2,9 +2,9 @@ import { NextFunction, Request, RequestHandler, Response, } from 'express'; import * as status from 'http-status'; +import { logger } from '~/logger'; import * as errorCode from '~/v1/utils/error/errorCode'; import ErrorResponse from '~/v1/utils/error/errorResponse'; -import { logger } from '~/v1/utils/logger'; import * as lendingsService from './lendings.service'; export const create: RequestHandler = async ( diff --git a/backend/src/v1/reservations/reservations.controller.ts b/backend/src/v1/reservations/reservations.controller.ts index 576c947f..5daed9b6 100644 --- a/backend/src/v1/reservations/reservations.controller.ts +++ b/backend/src/v1/reservations/reservations.controller.ts @@ -2,10 +2,10 @@ import { NextFunction, Request, RequestHandler, Response, } from 'express'; import * as status from 'http-status'; -import ErrorResponse from '~/v1/utils/error/errorResponse'; -import { logger } from '~/v1/utils/logger'; -import * as errorCode from '~/v1/utils/error/errorCode'; +import { logger } from '~/logger'; import * as userUtils from '~/v1/users/users.utils'; +import * as errorCode from '~/v1/utils/error/errorCode'; +import ErrorResponse from '~/v1/utils/error/errorResponse'; import * as reservationsService from './reservations.service'; export const create: RequestHandler = async ( diff --git a/backend/src/v1/slack/slack.controller.ts b/backend/src/v1/slack/slack.controller.ts index 6c4b20d0..84de2df6 100644 --- a/backend/src/v1/slack/slack.controller.ts +++ b/backend/src/v1/slack/slack.controller.ts @@ -1,8 +1,8 @@ import { NextFunction, Request, Response } from 'express'; import * as status from 'http-status'; +import { logger } from '~/logger'; import * as errorCode from '~/v1/utils/error/errorCode'; import ErrorResponse from '~/v1/utils/error/errorResponse'; -import { logger } from '~/v1/utils/logger'; import * as slack from './slack.service'; export const updateSlackList = async ( diff --git a/backend/src/v1/slack/slack.service.ts b/backend/src/v1/slack/slack.service.ts index 33eadf60..9936aa44 100644 --- a/backend/src/v1/slack/slack.service.ts +++ b/backend/src/v1/slack/slack.service.ts @@ -1,7 +1,7 @@ import { WebClient } from '@slack/web-api'; import { ResultSetHeader } from 'mysql2'; -import { logger } from '~/v1/utils/logger'; import { botOAuthToken as token } from '~/config'; +import { logger } from '~/logger'; import { executeQuery } from '~/mysql'; import UsersService from '~/v1/users/users.service'; import * as models from '../DTO/users.model'; diff --git a/backend/src/v1/users/users.controller.ts b/backend/src/v1/users/users.controller.ts index e15674c2..0b5ffda0 100644 --- a/backend/src/v1/users/users.controller.ts +++ b/backend/src/v1/users/users.controller.ts @@ -1,11 +1,10 @@ import bcrypt from 'bcrypt'; import { NextFunction, Request, Response } from 'express'; -import PasswordValidator from 'password-validator'; import * as status from 'http-status'; -import { z } from 'zod'; -import ErrorResponse from '~/v1/utils/error/errorResponse'; -import { logger } from '~/v1/utils/logger'; +import PasswordValidator from 'password-validator'; +import { logger } from '~/logger'; import * as errorCode from '~/v1/utils/error/errorCode'; +import ErrorResponse from '~/v1/utils/error/errorResponse'; import { User } from '../DTO/users.model'; import UsersService from './users.service'; import { searchSchema } from './users.types'; diff --git a/backend/src/v1/users/users.service.spec.ts b/backend/src/v1/users/users.service.spec.ts index f36b6bed..30b07530 100644 --- a/backend/src/v1/users/users.service.spec.ts +++ b/backend/src/v1/users/users.service.spec.ts @@ -2,7 +2,7 @@ import { QueryRunner } from 'typeorm'; import jipDataSource from '~/app-data-source'; import { connectMode } from '~/config'; -import { logger } from '~/v1/utils/logger'; +import { logger } from '~/logger'; import UsersService from './users.service'; const usersService = new UsersService(); diff --git a/backend/src/v1/utils/error/errorConverter.ts b/backend/src/v1/utils/error/errorConverter.ts index a0c45255..6de54912 100644 --- a/backend/src/v1/utils/error/errorConverter.ts +++ b/backend/src/v1/utils/error/errorConverter.ts @@ -1,8 +1,6 @@ import { NextFunction, Request, Response } from 'express'; -import * as Status from 'http-status'; -import ErrorResponse from './errorResponse'; -import { logger } from '../logger'; import * as errorCode from './errorCode'; +import ErrorResponse from './errorResponse'; export default function errorConverter( err: Error | ErrorResponse, diff --git a/backend/src/v1/utils/error/errorHandler.ts b/backend/src/v1/utils/error/errorHandler.ts index b7ce163c..e9aca049 100644 --- a/backend/src/v1/utils/error/errorHandler.ts +++ b/backend/src/v1/utils/error/errorHandler.ts @@ -1,8 +1,8 @@ import { NextFunction, Request, Response } from 'express'; import * as Status from 'http-status'; -import ErrorResponse from './errorResponse'; -import { logger } from '../logger'; +import { logger } from '~/logger'; import * as errorCode from './errorCode'; +import ErrorResponse from './errorResponse'; export default function errorHandler( err: Error | ErrorResponse, From 314ed4f08f724b83e5b6c71e2f5facd693c25c52 Mon Sep 17 00:00:00 2001 From: scarf Date: Mon, 31 Jul 2023 09:36:16 +0900 Subject: [PATCH 3/5] =?UTF-8?q?refactor:=20=ED=83=80=EC=9E=85=EB=A7=8C=20i?= =?UTF-8?q?mport?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/config/logOption.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/config/logOption.ts b/backend/src/config/logOption.ts index f087656f..1477cdbf 100644 --- a/backend/src/config/logOption.ts +++ b/backend/src/config/logOption.ts @@ -1,4 +1,4 @@ -import { LogLevel, LogLevelOption } from './config.type'; +import type { LogLevel, LogLevelOption } from './config.type'; import { RuntimeMode } from './runtimeOption'; export const levels = { From dee84dfedd8f3ceca2a24fb5dbf9ed3b77a219f0 Mon Sep 17 00:00:00 2001 From: scarf Date: Mon, 31 Jul 2023 09:36:36 +0900 Subject: [PATCH 4/5] =?UTF-8?q?refactor:=20config=EC=97=90=EC=84=9C=20`log?= =?UTF-8?q?FormatOption`=EB=A7=8C=20=EB=82=B4=EB=B3=B4=EB=82=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/config/index.ts | 2 ++ backend/src/logger.ts | 8 +++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 21138f6d..d3c56bd1 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -9,6 +9,8 @@ import { getOauth42ApiOption, getOauthUrlOption } from './oauthOption'; import { getRuntimeMode } from './runtimeOption'; import { getSlackbotOAuthToken } from './slackbotOAuthTokenOption'; +export * as logFormatOption from './logOption'; + // .env 파일을 읽어서 process.env에 추가 dotenv.config(); diff --git a/backend/src/logger.ts b/backend/src/logger.ts index 55e1711b..ebd9295c 100644 --- a/backend/src/logger.ts +++ b/backend/src/logger.ts @@ -7,11 +7,9 @@ import { transports, } from 'winston'; import WinstonDaily from 'winston-daily-rotate-file'; -import { logLevelOption } from '~/config'; -import { - colors, - levels, -} from '~/config/logOption'; +import { logFormatOption, logLevelOption } from '~/config'; + +const { colors, levels } = logFormatOption; const { combine, timestamp, printf, colorize, errors, From a2ec7ebbe8db797588dcc24da1a0cbb1321c2559 Mon Sep 17 00:00:00 2001 From: scarf Date: Mon, 31 Jul 2023 09:54:48 +0900 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20log=20=EB=A7=88=EC=9A=B4=ED=8A=B8=20?= =?UTF-8?q?=EA=B2=BD=EB=A1=9C=EB=A5=BC=20=EC=83=88=20workdir=EC=97=90=20?= =?UTF-8?q?=EB=A7=9E=EC=B6=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 42deec29..3358af1a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -27,13 +27,10 @@ services: backend: container_name: backend - #image : node:16 build: context: . volumes: - #- ./backend/src/:/src/ - - ./backend/logs:/logs - #command: ${MODE} + - ./backend/logs:/app/backend/logs ports: - 3000:3000 env_file: .env