diff --git a/.github/workflows/backend-prod-cd.yml b/.github/workflows/backend-prod-cd.yml index a275494..8929f83 100644 --- a/.github/workflows/backend-prod-cd.yml +++ b/.github/workflows/backend-prod-cd.yml @@ -68,7 +68,7 @@ jobs: port: ${{ secrets.SSH_PORT }} script: | docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} - docker pull ${{ secrets.DOCKER_USERNAME }}/siso-backend:latest docker stop siso-backend || true docker rm siso-backend || true - docker run -d --env-file /home/ubuntu/env/backend.env -p 80:80 --name siso-backend ${{ secrets.DOCKER_USERNAME }}/siso-backend:latest + docker pull ${{ secrets.DOCKER_USERNAME }}/siso-backend:latest + docker run -d -p 80:80 -p 443:443 --env-file /home/ubuntu/env/backend.env --name siso-backend -v /etc/letsencrypt:/etc/letsencrypt ${{ secrets.DOCKER_USERNAME }}/siso-backend:latest diff --git a/backend/Dockerfile b/backend/Dockerfile index f1411b6..899a302 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,8 +1,82 @@ -FROM node:18 -RUN mkdir -p /var/app -WORKDIR /var/app +# FROM node:18 +# RUN mkdir -p /var/app +# WORKDIR /var/app +# COPY . . +# RUN npm install +# RUN npm run build +# EXPOSE 80 +# CMD [ "node", "dist/main.js" ] + + +# FROM node:19-alpine AS builder + +# WORKDIR /usr/src/app + +# COPY . . + +# RUN npm install +# RUN npm run build + +# FROM node:19-alpine AS Release + +# WORKDIR /app + +# COPY --from=builder /usr/src/app/dist /app/dist + +# FROM nginx:latest + +# RUN rm /etc/nginx/conf.d/default.conf + +# COPY ./nginx.conf /etc/nginx/conf.d/default.conf + +# RUN rm -rf ./usr/share/nginx/html/* + +# COPY --from=Release /app/dist ./usr/share/nginx/html/ + +# EXPOSE 80 +# EXPOSE 443 + +# ENTRYPOINT ["nginx", "-g", "daemon off;"] + +# Node.js 빌드를 위한 스테이지 +FROM node:19-alpine AS builder + +WORKDIR /usr/src/app + COPY . . + RUN npm install RUN npm run build + +# Node.js 서버 실행을 위한 스테이지 +FROM node:19-alpine AS release + +WORKDIR /app + +COPY --from=builder /usr/src/app /app + +# Nginx 설정을 위한 스테이지 +FROM nginx:latest + +# 기존의 기본 Nginx 설정 제거 +RUN rm /etc/nginx/conf.d/default.conf + +# 새로운 Nginx 설정 복사 +COPY ./nginx.conf /etc/nginx/conf.d/default.conf + +# 정적 파일을 제공하는 폴더를 비우기 +RUN rm -rf /usr/share/nginx/html/* + +# 정적 파일을 제공하는 폴더에 빌드된 파일 복사 +COPY --from=release /app/dist /usr/share/nginx/html/ + +# Nginx가 80 및 443 포트를 노출하도록 설정 EXPOSE 80 -CMD [ "node", "dist/main.js" ] +EXPOSE 443 + +# Node.js 애플리케이션을 백그라운드에서 실행하기 위한 명령 추가 +# CMD를 사용하여 Node.js 서버를 백그라운드에서 실행 +CMD ["node", "/app/dist/main.js"] & + +# Nginx를 포그라운드에서 실행 +ENTRYPOINT ["nginx", "-g", "daemon off;"] diff --git a/backend/nginx.conf b/backend/nginx.conf new file mode 100644 index 0000000..b84ed8e --- /dev/null +++ b/backend/nginx.conf @@ -0,0 +1,24 @@ +server { + listen 80; + server_name api.siso-balance-game.com; + + location / { + return 301 https://$host$request_uri; + } +} +server { + listen 443 ssl; + server_name api.siso-balance-game.com; + + ssl_certificate /etc/letsencrypt/live/api.siso-balance-game.com/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/api.siso-balance-game.com/privkey.pem; + + location / { + proxy_pass http://localhost; # Assuming your NestJS app runs on port 3000 + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } +} diff --git a/backend/src/game/game.controller.ts b/backend/src/game/game.controller.ts index 12658f1..cd7e9a1 100644 --- a/backend/src/game/game.controller.ts +++ b/backend/src/game/game.controller.ts @@ -75,7 +75,7 @@ export class GameController { async findGamesByUserId( @Req() req: Request, @Query('page') page: number = 1, // 페이지 번호 - @Query('limit') limit: number = 10, // 페이지당 항목 수 + @Query('limit') limit: number = 10, // 페이지당 아이템 수 ): Promise { const kakaoId = req.user.kakaoId; return this.gameService.findGamesByUserId(kakaoId, page, limit);