Skip to content

Commit 5e70897

Browse files
Merge pull request #301 from boostcampwm-2024/feature-be-#300
로컬 개발환경 편의성 개선
2 parents eaba7e1 + bb45e9f commit 5e70897

File tree

12 files changed

+100
-51
lines changed

12 files changed

+100
-51
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
.env*
44
*.local
55
.turbo
6-
.crt
7-
.key
6+
*.crt
7+
*.key
88
!Dockerfile.local
99

1010
# compiled output

apps/backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"build": "nest build",
1010
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
1111
"start": "nest start",
12-
"dev": "nest start --watch",
12+
"dev": "nest start --tsc --watch --preserveWatchOutput --watchAssets",
1313
"start:debug": "nest start --debug --watch",
1414
"start:prod": "node dist/main",
1515
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",

apps/backend/src/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { RoleModule } from './role/role.module';
2828
}),
2929
ConfigModule.forRoot({
3030
isGlobal: true,
31-
envFilePath: path.join(__dirname, '..', '..', '..', '.env'), // * nest 디렉터리 기준
31+
envFilePath: '/app/.env', // * docker 내부 디렉터리 기준
3232
}),
3333
TypeOrmModule.forRootAsync({
3434
imports: [ConfigModule],

apps/backend/tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"noImplicitAny": false,
1717
"strictBindCallApply": false,
1818
"forceConsistentCasingInFileNames": false,
19-
"noFallthroughCasesInSwitch": false
19+
"noFallthroughCasesInSwitch": false,
20+
},
21+
"watchOptions": {
22+
"watchFile": "fixedPollingInterval"
2023
}
2124
}

apps/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212
},
1313
"scripts": {
14-
"dev": "vite --host",
14+
"dev": "vite",
1515
"build": "tsc -b && vite build",
1616
"lint": "eslint .",
1717
"preview": "vite preview --host"

apps/frontend/vite.config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,17 @@ export default defineConfig({
1010
plugins: [tailwindcss()],
1111
},
1212
},
13+
server: {
14+
host: "0.0.0.0",
15+
port: 5173,
16+
watch: {
17+
usePolling: true,
18+
interval: 1000,
19+
},
20+
hmr: {
21+
protocol: "wss",
22+
clientPort: 443,
23+
path: "hmr/",
24+
},
25+
},
1326
});

compose.local.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,25 @@ services:
2424
image: backend:latest
2525
env_file:
2626
- .env
27+
volumes:
28+
- .env:/app/.env
29+
# 소스 코드 마운트
30+
- ./apps/backend:/app/apps/backend
31+
- ./apps/frontend:/app/apps/frontend
32+
# 의존성 캐시를 위한 볼륨
33+
- backend_node_modules:/app/node_modules
34+
- backend_app_node_modules:/app/apps/backend/node_modules
35+
- frontend_app_node_modules:/app/apps/frontend/node_modules
2736
depends_on:
2837
postgres:
2938
condition: service_healthy
3039
networks:
3140
- backend
3241
- frontend
42+
ports:
43+
- "5173:5173" # Vite dev server
44+
- "3000:3000" # 백엔드 API 포트
45+
- "1234:1234" # WebSocket 포트
3346

3447
nginx:
3548
build:
@@ -49,6 +62,7 @@ services:
4962
bind:
5063
create_host_path: true
5164
propagation: rprivate
65+
- ./services/nginx/conf.d:/etc/nginx/conf.d
5266

5367
networks:
5468
backend:
@@ -57,3 +71,6 @@ networks:
5771

5872
volumes:
5973
postgres_data:
74+
backend_node_modules:
75+
backend_app_node_modules:
76+
frontend_app_node_modules:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"author": "ez <[email protected]>",
77
"license": "MIT",
88
"scripts": {
9-
"dev": "turbo run dev",
9+
"dev": "turbo run dev --parallel",
1010
"build": "turbo run build",
1111
"start": "node apps/backend/dist/main.js",
1212
"lint": "turbo run lint",

services/backend/Dockerfile.local

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,19 @@
1-
FROM node:20-alpine AS builder
1+
FROM node:20-alpine
22

3-
WORKDIR /
3+
WORKDIR /app
44

5-
# 모노레포 관련 파일 복사
5+
# 개발 의존성 설치를 위한 파일들
66
COPY package.json yarn.lock ./
77
COPY turbo.json ./
88
COPY apps/backend/package.json ./apps/backend/
99
COPY apps/frontend/package.json ./apps/frontend/
1010

11-
# 의존성 설치
12-
RUN yarn install --frozen-lockfile
13-
14-
# 소스 코드 복사
15-
COPY apps/backend/ ./apps/backend/
16-
COPY apps/frontend/ ./apps/frontend/
17-
18-
# 프론트엔드와 백엔드 모두 빌드
19-
RUN yarn build
20-
21-
FROM node:20-alpine AS runner
22-
23-
WORKDIR /app
24-
25-
# 프로덕션 의존성만 설치하기 위한 파일들 복사
26-
COPY --from=builder package.json yarn.lock ./
27-
COPY --from=builder apps/backend/package.json ./apps/backend/
28-
29-
# 프로덕션 의존성만 설치
30-
RUN yarn install --production --frozen-lockfile
11+
# 개발 의존성 설치 (프로덕션 플래그 제거)
12+
RUN yarn install
3113

32-
# 빌드된 결과물 복사
33-
COPY --from=builder apps/backend/dist ./apps/backend/dist
34-
COPY --from=builder apps/frontend/dist ./public/
14+
# 소스 코드는 볼륨으로 마운트할 예정이므로 COPY 불필요
3515

3616
EXPOSE 3000 1234
3717

38-
CMD ["yarn", "start"]
18+
# 개발 모드로 실행
19+
CMD ["yarn", "dev"]

services/nginx/Dockerfile.local

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
FROM backend:latest AS backend_build
2-
31
FROM nginx:alpine
42

53
# 필요한 설정 파일 복사
64
COPY services/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
75

8-
# 빌드된 프론트엔드 파일 복사
9-
COPY --from=backend_build /app/public /usr/share/nginx/html
10-
116
# SSL 설정 및 권한 조정
127
RUN mkdir -p /etc/nginx/ssl && \
138
chown -R nginx:nginx /etc/nginx/ssl && \

0 commit comments

Comments
 (0)