diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d7f1b25 --- /dev/null +++ b/.env.example @@ -0,0 +1,8 @@ +# 42seoul_club_42jiphyeonjeon_dev 캔버스 참고: +# https://42born2code.slack.com/canvas/C03BAMF3727 + +MYSQL_DATABASE=jip_serv +MYSQL_USER=saseo +MYSQL_PASSWORD= +MYSQL_ROOT_PASSWORD= +MYSQL_HOST="127.0.0.1" diff --git a/.gitignore b/.gitignore index 2079630..9f15018 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ ### Node ### node_modules/ + +.env* +!.env.example diff --git a/README.md b/README.md index 9d8cd16..10b44dc 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,67 @@ # backend-nest + 6차 개발팀은 nestjs 로 새로 작성하기로 했습니다 + +## 개발 환경 설정 + +### 환경 변수 + +[.env.example](./.env.example)의 내용을 참고하여 루트 디렉토리에 `.env` 파일을 생성합니다. + +### 백엔드 + +```sh +$ brew install corepack +$ corepack enable +``` + +[corepack](https://github.com/nodejs/corepack?tab=readme-ov-file#how-to-install)으로 pnpm을 설치합니다. + +> [!NOTE] +> mac OS 환경에서는 `corepack` 패키지가 `yarn`과 `pnpm` 패키지와 충돌이 있을 수 있습니다. +> 이 경우 두 패키지를 모두 삭제하고 `corepack`을 설치해야 합니다. + +```sh +$ pnpm install +``` + +프로젝트 의존성을 설치합니다. + +### DB + +```sh +$ docker compose -f compose-dev.yml up --remove-orphans +# (다른 터미널에서) +$ docker compose -f compose-dev.yml exec database /bin/sh +# mysql -h 127.0.0.1 -P 3306 -u root -p +mysql> use jip_serv; +mysql> source /내려받은/DB/덤프/파일/경로.sql; +``` + +초기 실행 시 [DB 덤프 파일](https://discord.com/channels/1277878039090565139/1277878039593619468/1278599701532377088)을 사용해 [데이터베이스를 초기화해야 합니다.](https://stackoverflow.com/questions/17666249/how-to-import-an-sql-file-using-the-command-line-in-mysql) + +``` +mysql> show databases; ++--------------------+ +| Database | ++--------------------+ +| information_schema | +| jip_serv | +| performance_schema | ++--------------------+ +3 rows in set (0.01 sec) +``` + +다음과 같이 데이터베이스가 생성되어 있는지 확인합니다. + +### docker compose 실행 + +```sh +$ pnpm dev +``` + +위 명령어로 개발용 docker compose를 실행합니다. + +![](./swagger.webp) + + 경로에 접근하여 API 명세가 올바르게 표시되는지 확인합니다. diff --git a/backend/Dockerfile.dev b/backend/Dockerfile.dev new file mode 100644 index 0000000..e070061 --- /dev/null +++ b/backend/Dockerfile.dev @@ -0,0 +1,6 @@ +FROM node:22-slim AS base +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" +RUN corepack enable + +WORKDIR /app diff --git a/backend/package.json b/backend/package.json index 5199d2d..1554d0b 100644 --- a/backend/package.json +++ b/backend/package.json @@ -76,5 +76,6 @@ ], "coverageDirectory": "../coverage", "testEnvironment": "node" - } + }, + "packageManager": "pnpm@9.12.0+sha512.4abf725084d7bcbafbd728bfc7bee61f2f791f977fd87542b3579dcb23504d170d46337945e4c66485cd12d588a0c0e570ed9c477e7ccdd8507cf05f3f92eaca" } diff --git a/compose-dev.yml b/compose-dev.yml new file mode 100644 index 0000000..c36a787 --- /dev/null +++ b/compose-dev.yml @@ -0,0 +1,29 @@ +services: + database: + platform: linux/x86_64 + container_name: database + image: mysql:8.0 + environment: + - TZ=Asia/Seoul + + ports: + - 3306:3306 + + env_file: .env + + backend: + container_name: backend + restart: on-failure + build: + context: backend + dockerfile: Dockerfile.dev + + entrypoint: ["pnpm", "run", "start:dev"] + volumes: + - ./backend:/app + - ./backend/logs:/app/backend/logs + ports: + - 3000:3000 + environment: + - MYSQL_HOST=database + env_file: .env diff --git a/package.json b/package.json index b08d846..605553f 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "6차 개발팀은 nestjs 로 새로 작성하기로 했습니다", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "dev": "docker compose -f compose-dev.yml up --remove-orphans" }, "keywords": [], "author": "", diff --git a/swagger.webp b/swagger.webp new file mode 100644 index 0000000..36fe263 Binary files /dev/null and b/swagger.webp differ