Skip to content
Merged
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
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
npm-debug.log
build
.git
.gitignore
README.md
.env
.DS_Store
23 changes: 23 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Deploy to EC2
on:
push:
branches:
- 김선영 # push 발생 시 AWS 배포

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Deploy to EC2 via SSH
uses: appleboy/ssh-action@v0.1.6
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
port: 22
script: |
cd /home/ec2-user/6-sprint-mission
git pull origin 김선영
docker compose down
docker compose up -d --build
Comment on lines +19 to +23
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.

현재 구조에서는 down → up 사이에 서비스가 중단되는 시간이 발생해요.
지금 단계에서 무중단 배포까지 구현할 필요는 없지만, docker compose downup 사이에 빌드가 포함되어 있어서 다운타임이 길어질 수 있다는 점은 인식하고 계시면 좋겠어요.

docker compose up -d --build만 사용하면 새 컨테이너가 준비된 후 기존 것을 교체하는 방식으로 동작하기도 합니다.

37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Test
on:
pull_request:
branches:
- 김선영 # PR 발생 시 테스트

jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: testdb
ports:
- 5433:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5433/testdb
JWT_ACCESS_TOKEN_SECRET: ${{ secrets.JWT_ACCESS_TOKEN_SECRET }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '24.13.0'
- run: npm ci
- run: npx prisma migrate deploy
- name: Type Check
run: npm run typecheck
- name: Run Tests
run: npm run test
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

23 changes: 23 additions & 0 deletions Dockerfile
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.

현재 단일 스테이지 빌드를 사용하고 있어서, 최종 이미지에 devDependencies(jest, ts-jest, prettier 등)와 TypeScript 소스 코드가 모두 포함돼요.
Docker의 multi-stage build 방식을 활용하면 빌드 단계와 실행 단계를 분리해서 최종 이미지 크기를 줄일 수 있습니다.
구글에 Docker multi-stage build Node.js를 검색하여 관련 내용을 한번 살펴보시기 바랍니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 베이스 이미지
ARG NODE_VERSION=24.13.0
FROM node:${NODE_VERSION}

# 환경 변수 선언: express 서버를 실행할 포트
ENV SERVER_PORT=3000

# 이미지 빌드 간 현재 디렉토리 설정: 프로젝트 루트 디렉토리
WORKDIR /app

# 4. 패키지 설치
COPY package*.json ./
RUN npm ci

# 5. 소스 코드 복사
COPY . .

# 6. Prisma 및 빌드
RUN npx prisma generate
RUN npm run build

# 컨테이너가 켜질 때 DB 테이블부터 만들고 서버 실행
ENTRYPOINT ["sh", "-c", "npx prisma migrate deploy && npm run start"]
38 changes: 38 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: sprint-mission-11
services:
server:
build:
context: .
dockerfile: Dockerfile
ports:
- '3000:3000'
environment:
DATABASE_URL: 'postgresql://postgres:password123@db:5432/mission11'
JWT_ACCESS_TOKEN_SECRET: ${JWT_ACCESS_TOKEN_SECRET}
JWT_REFRESH_TOKEN_SECRET: ${JWT_REFRESH_TOKEN_SECRET}
ACCESS_TOKEN_COOKIE_NAME: ${ACCESS_TOKEN_COOKIE_NAME}
REFRESH_TOKEN_COOKIE_NAME: ${REFRESH_TOKEN_COOKIE_NAME}
S3_BUCKET_NAME: ${S3_BUCKET_NAME}
S3_REGION: ${S3_REGION}
S3_ACCESS_KEY: ${S3_ACCESS_KEY}
S3_SECRET_KEY: ${S3_SECRET_KEY}
volumes:
- ./uploads:/app/uploads:rw
Comment on lines +19 to +20
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.

Volume을 uploads 폴더에 매핑한 건 요구사항에 맞게 잘 구현하셨는데, 실제 이미지 업로드 코드(imagesController.ts)를 보면 S3에 직접 업로드하는 방식으로 되어있습니다.
로컬 파일시스템의 uploads 폴더에 저장하는 로직이 보이지 않아요.

미션의 요구사항을 충족하려면, 실제로 파일이 해당 경로에 저장되도록 업로드 로직을 맞춰줄 필요가 있을 거 같네요.
multer의 diskStorage를 활용하면 로컬 경로에 저장하는 방식을 구현할 수 있습니다.

depends_on:
db:
condition: service_healthy

db:
image: postgres:15
container_name: postgres-db
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password123
POSTGRES_DB: mission11
ports:
- '5434:5432'
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U postgres']
interval: 5s
timeout: 5s
retries: 5
4 changes: 2 additions & 2 deletions infra/ec2/ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'build/main.js',module.exports = {
module.exports = {
apps: [
{
name: 'sprint-mission',
script: 'build/main.js',
script: 'build/main.js',
instances: 1,
exec_mode: 'fork',
env: {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"start": "node ./build/main.js",
"build": "tsc",
"dev": "nodemon ./src/main.ts --watch ./src",
"test": "dotenv -e .env.test -- prisma migrate dev && dotenv -e .env.test -- jest -i --coverage"
"typecheck": "tsc --noEmit",
"test": "jest -i --coverage"
},
"devDependencies": {
"@types/bcrypt": "^5.0.2",
Expand Down
File renamed without changes.
Loading