Skip to content

Commit

Permalink
Merge pull request #171 from boostcampwm-2024/feature/be/#166-deployB…
Browse files Browse the repository at this point in the history
…ackend

[BE][Chore] #166 : docker-compose, nginx 설정 및 백엔드 dockerfile 작성
  • Loading branch information
happyhyep authored Nov 14, 2024
2 parents d09b862 + 67329ba commit 20bc0b4
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
29 changes: 29 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 1. 베이스 이미지 설정 (Node.js 18 버전 사용)
FROM node:18

# 2. 작업 디렉토리 설정
WORKDIR /app

# 3. root 폴더의 package.json, pnpm-lock.yaml, pnpm-workspace.yaml 파일을 복사
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./

# 4. pnpm을 설치
RUN npm install -g pnpm

# 5. 전체 의존성 설치 (root)
RUN pnpm install

# 6. backend 폴더를 컨테이너로 복사
COPY backend /app/backend

# 7. 작업 디렉토리 backend로 이동
WORKDIR /app/backend

# 8. backend 의존성 설치
RUN pnpm install

# 9. 백엔드 실행
CMD ["pnpm", "run", "dev"]

#10. 백엔드 포트 설정
EXPOSE 3001
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3'
services:
backend:
build:
context: .
dockerfile: backend/Dockerfile
ports:
- "3001:3001"
environment:
- NODE_ENV=production
networks:
- app-network

nginx:
image: nginx:alpine
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
ports:
- "80:80"
networks:
- app-network
depends_on:
- backend

networks:
app-network:
driver: bridge
27 changes: 27 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
worker_processes 1;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

server {
listen 80;

location /api/ {
proxy_pass http://backend:3001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

# TODO: 프론트엔드 요청 처리 (나중에 활성화)
location / {
root /usr/share/nginx/html;
index index.html;
}
}
}

0 comments on commit 20bc0b4

Please sign in to comment.