Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: 개발용 docker compose 파일 #67

Merged
merged 4 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
### Node ###
node_modules/

.env*
!.env.example
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

<http://localhost:3000/api> 경로에 접근하여 API 명세가 올바르게 표시되는지 확인합니다.
6 changes: 6 additions & 0 deletions backend/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM node:22-slim AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

WORKDIR /app
3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
},
"packageManager": "[email protected]+sha512.4abf725084d7bcbafbd728bfc7bee61f2f791f977fd87542b3579dcb23504d170d46337945e4c66485cd12d588a0c0e570ed9c477e7ccdd8507cf05f3f92eaca"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packageManager 가 어떤 역할을 하는지 알려주시면 감사하겠습니다.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packagemanager는 corepack에서 사용할 패키지 매니저 (npm, yarn, pnpm 등) 버전을 고정하기 위해 사용하는 식별자입니다. 다음을 참고해주세요:

}
29 changes: 29 additions & 0 deletions compose-dev.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
Binary file added swagger.webp
Binary file not shown.
Loading