-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* build: dev dockerfile * docs: `.env` 예제 추가 * build: compose 내에서 DB 연결 컨테이너간에는 컨테이너명으로 DB에 접근해야 함, 참고: https://old.reddit.com/r/docker/comments/jsshgu/help_nodjs_mysql_dockercompose_connect/gc1ktqr/ * docs: docker compose 사용법 정리
- Loading branch information
Showing
8 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
### Node ### | ||
node_modules/ | ||
|
||
.env* | ||
!.env.example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 명세가 올바르게 표시되는지 확인합니다. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,5 +76,6 @@ | |
], | ||
"coverageDirectory": "../coverage", | ||
"testEnvironment": "node" | ||
} | ||
}, | ||
"packageManager": "[email protected]+sha512.4abf725084d7bcbafbd728bfc7bee61f2f791f977fd87542b3579dcb23504d170d46337945e4c66485cd12d588a0c0e570ed9c477e7ccdd8507cf05f3f92eaca" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.