Skip to content
Open
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
21 changes: 21 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

## 요구사항

### 기본
- [x] 기본 항목 1
- [ ] 기본 항목 2

### 심화
- [ ] 심화 항목 1
- [ ] 심화 항목 2

## 주요 변경사항
-
-

## 스크린샷
![image](이미지url)

## 멘토에게
- 셀프 코드 리뷰를 통해 질문 이어가겠습니다.
-
50 changes: 50 additions & 0 deletions .github/workflows/main-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Deploy to EC2

on:
push:
branches:
- main

jobs:
deploy:
name: Build & Deploy
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

# 깃허브 액션 서버에서 빌드가 잘 되는지 미리 체크
- name: Setup Node.js
uses: aws-actions/setup-node@v4
with:
node-version: "20"

- name: Install & Build Check
working-directory: ./sprint11
run: |
npm ci
npx prisma generate
npm run build

# 실제 EC2 서버에 접속해서 배포 명령어 실행
- name: Deploy to EC2 via SSH
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.EC2_HOST }} # EC2 퍼블릭 IP
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }} # .pem 키 파일 내용
script: |
cd ~/7-sprint-mission
git pull origin main

cd sprint11
npm install
npx prisma generate
npx prisma migrate deploy
npm run build

# PM2로 서버 재시작
pm2 reload all || pm2 start dist/main.js --name "my-app"

echo "배포가 완료되었습니다!"
Comment on lines +37 to +50
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

만약 새로운 폴더를 새로 만들어서 작업을 진행하게되면 (ex. sprint 12, sprint 13...)
작성하신 스크립트로는 새로운 코드가 서버에 적용되지 않을거같은데 어떻게 해결할 수 있을까요?? 🤔

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

새로운 폴더에 맞춰서 스크립트를 변경하면 되지 않을까요?!😭.. 현재는 새 미션마다 폴더를 새로 생성해서 작업중이라 저렇게 했었습니다! ㅠㅠ

65 changes: 65 additions & 0 deletions .github/workflows/pr-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Pull Request Test

on:
pull_request:
branches:
- main
- develop

jobs:
test:
name: Run Tests
runs-on: ubuntu-latest

defaults:
run:
working-directory: ./sprint11

# 깃허브 액션 안에서 임시로 사용할 테스트용 DB 설정
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpassword
POSTGRES_DB: testdb
# DB가 준비될 때까지 기다리는 헬스 체크
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
Comment on lines +26 to +31
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍👍👍👍

ports:
- 5432:5432

steps:
- name: Checkout code #코드 복사
uses: actions/checkout@v4

- name: Setup Node.js #node 설치
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"

- name: Install dependencies #라이브러리 설치
run: npm ci

- name: Generate Prisma Client #prisma 준비
run: npx prisma generate

# 테스트용 DB에 테이블 구조 생성.
- name: Run DB migrations
env:
DATABASE_URL: postgresql://testuser:testpassword@localhost:5432/testdb
run: npx prisma migrate deploy

- name: Run tests
env:
NODE_ENV: test
PORT: 3000
DATABASE_URL: postgresql://testuser:testpassword@localhost:5432/testdb
# 테스트에 필요한 키
JWT_SECRET: test_jwt_secret
REFRESH_SECRET: test_refresh_secret
run: npm test
21 changes: 15 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@

# Local files
.vscode/
node_modules/
.env*
!.env.example
build/
coverage/
bun.lock*

# Uploaded files
public/*
!public/.gitkeep
!public/socket-client-test.html
# 의존성
/node_modules
/package-lock.json
Expand All @@ -17,11 +31,6 @@
# TypeScript 캐시
/.tsbuildinfo

# 환경 변수 및 보안 파일
.env
.env.local
.env.*.local

# 운영체제/에디터 파일
.DS_Store
Thumbs.db
Expand All @@ -36,4 +45,4 @@ Thumbs.db
.devcontainer/devcontainer.json
tests/test.http
tests/test.png
public/.gitkeep
public/.gitkeep
42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 빌드 스테이지
FROM node:20-alpine AS builder
WORKDIR /app

RUN apk add --no-cache openssl
COPY sprint11/package*.json ./
RUN npm ci

COPY sprint11/ .

# Prisma 타입 생성 및 TypeScript 컴파일
RUN npx prisma generate
RUN npx tsc

# 실행 스테이지
FROM node:20-alpine AS runner
WORKDIR /app

# Prisma 실행에 필수인 openssl 및 관련 라이브러리 설치
RUN apk add --no-cache openssl libc6-compat

# 보안 설정: root가 아닌 일반 사용자 생성
RUN addgroup -S appgroup && adduser -S appuser -G appgroup

# 의존성 설치
COPY sprint11/package*.json ./
RUN npm ci --only=production

# 빌드 스테이지에서 컴파일된 결과물만 가져오기
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder /app/prisma ./prisma

# 업로드 폴더 권한 설정 및 볼륨 준비
RUN mkdir -p /app/public && chown -R appuser:appgroup /app /app/public
# 생성한 일반 사용자로 전환
USER appuser

EXPOSE 3000

# Prisma 마이그레이션 적용 후 서버 실행
CMD ["sh", "-c", "npx prisma migrate deploy && node ./dist/main.js"]
41 changes: 41 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: panda-market-sprint11

services:
db:
image: postgres:latest
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

최신 버전(latest)의 postgres 이미지를 이용하고 계시네요!
지금은 문제없이 잘 돌아갈 수 있으나 추후에 이미지 버전이 업데이트되었을 때 오류가 발생할 수 있습니다.
그렇기때문에 되도록이면 RDS의 postgresql 버전을 명시해서 작성해주시는게 좋습니다. (ex. postgres:15)

( pr-test.yaml 파일에서는 정확한 버전을 명시하셔서 잘 사용하고 계시네요!)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

넵!

container_name: sprint11-db
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: pandamarket
ports:
- "5432:5432"
volumes:
# DB 데이터는 Named Volume으로 관리
- postgres_data:/var/lib/postgresql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5

app:
build:
context: .
dockerfile: Dockerfile
container_name: panda-market-app
ports:
- "3000:3000" # 호스트 3000번 포트 접근 가능
environment:
- DATABASE_URL=${DATABASE_URL}
- JWT_ACCESS_TOKEN_SECRET=${JWT_ACCESS_TOKEN_SECRET}
- PORT=${PORT}
- NODE_ENV=${NODE_ENV}
Comment on lines +29 to +33
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

환경변수를 이용하여 진행하신 점 좋네요!!

volumes:
- ./sprint11/public:/app/public
depends_on:
db:
condition: service_healthy # DB가 완전히 준비된 후 앱 실행
Comment on lines +36 to +38
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

단순히 depends_on만 사용한것이 아니라 헬스체크까지 진행하신점 너무 좋습니다! 👍


volumes:
postgres_data:
7 changes: 3 additions & 4 deletions sprint9-submit/.gitignore → sprint11/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Local files
.vscode/
node_modules/
.env*
Expand All @@ -10,7 +9,6 @@ public/*
!public/.gitkeep
!public/socket-client-test.html

README.md

# 빌드 출력 (TypeScript 컴파일 결과)
/dist
Expand All @@ -23,6 +21,7 @@ README.md

public

package-lock.json
coverage/

coverage/
.DS_Store
**/.DS_Store
9 changes: 9 additions & 0 deletions sprint11/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"singleQuote": true,
"trailingComma": "all",
"semi": true,
"printWidth": 100,
"endOfLine": "auto",
"arrowParens": "always",
"tabWidth": 2
}
9 changes: 9 additions & 0 deletions sprint11/infra/ec2/ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
apps: [{
script: 'npm',
args: 'start',
env: {
NODE_ENV: 'production'
}
}]
};
78 changes: 78 additions & 0 deletions sprint11/infra/ec2/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
keepalive_timeout 65;
types_hash_max_size 4096;

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

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

server {
listen 80;

location / {
proxy_pass http://localhost: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;
}
}


# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl;
# listen [::]:443 ssl;
# http2 on;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers PROFILE=SYSTEM;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# error_page 404 /404.html;
# location = /404.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
Binary file added sprint11/infra/ec2/secure-group-inbound.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprint11/infra/ec2/secure-group-outbound.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions sprint11/infra/ec2/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

npm install
npx prisma generate
npx prisma migrate deploy
npm run build

pm2 start ecosystem.config.js
Binary file added sprint11/infra/rds/secure-group-inbound.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprint11/infra/rds/secure-group-outbound.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprint11/infra/s3/policy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading