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
1 change: 0 additions & 1 deletion .env

This file was deleted.

18 changes: 18 additions & 0 deletions part4-mission11/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 빌드/런타임에 필요 없는 것들

coverage
node_modules
dist
infra

# VCS / 설정 / 도구 파일
.git
.gitignore
Dockerfile
docker-compose.yml

# 로그

npm-debug.log
*.log

20 changes: 20 additions & 0 deletions part4-mission11/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
NODE_ENV=production

# RDS용
DATABASE_URL="postgresql://appuser:비밀번호@rds-endpoint:5432/appdb?schema=public"

# JWT
ACCESS_TOKEN_SECRET="prod_secret_access"
REFRESH_TOKEN_SECRET="prod_secret_refresh"

# Express 내부 포트 (nginx에서 80 → 여기로 프록시)
PORT=4000

# 프론트 배포 주소
CORS_ORIGIN=https://내-프론트-도메인

# S3
AWS_REGION=ap-northeast-2
AWS_S3_BUCKET=내-버킷-이름
AWS_ACCESS_KEY_ID=발급받은키
AWS_SECRET_ACCESS_KEY=발급받은시크릿
21 changes: 21 additions & 0 deletions part4-mission11/.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)

## 멘토에게
- 셀프 코드 리뷰를 통해 질문 이어가겠습니다.
-
43 changes: 43 additions & 0 deletions part4-mission11/.github/workflows/main-cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Main CI-CD

on:
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

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

- name: Use Node
uses: actions/setup-node@v4
with:
node-version: 18

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm test

deploy:
needs: test
runs-on: ubuntu-latest

steps:
- name: Deploy to EC2 via SSH
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
cd /home/ec2-user/app
git pull origin main
npm ci --only=production --no-audit --no-fund
npm run build
pm2 restart mission11 || pm2 start dist/server.js --name mission11
25 changes: 25 additions & 0 deletions part4-mission11/.github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: PR

on:
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

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

- name: Use Node
uses: actions/setup-node@v4
with:
node-version: 18

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm test
28 changes: 28 additions & 0 deletions part4-mission11/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Node
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Uploads
src/uploads/*
!src/uploads/.gitkeep

# Prisma generated
generated/

# Env
.env
.env.production

# OS
.DS_Store

# Build output
dist/

# Test coverage outputs!
coverage/
*.lcov
lcov.info
.nyc_output/
11 changes: 11 additions & 0 deletions part4-mission11/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:18

COPY . /app

WORKDIR /app

RUN npm ci && npm run build

ENV PORT=3000

ENTRYPOINT [ "npm", "run", "start" ]
28 changes: 28 additions & 0 deletions part4-mission11/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 패키지 설치

npm install

# DB 마이그레이션 및 시딩

npm run db:reset

# 개발 서버 실행

npm run dev

# 빌드 후 실행

npm run build
npm start

# .env 파일 필요.

.env.example 참고해서 .env를 만들어주세요.

# 주요 기능

회원가입 / 로그인 (JWT + 쿠키 기반)
게시글 / 상품 CRUD
댓글 CRUD
좋아요 (게시글/상품/댓글)
페이지네이션 & 검색
33 changes: 33 additions & 0 deletions part4-mission11/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3.8'

services:
db:
image: postgres:16
container_name: codeit-postgres
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: bugloss
POSTGRES_DB: codeit-test
ports:
- '5432:5432'
volumes:
- db-data:/var/lib/postgresql/data

app:
build: .
container_name: codeit-express
restart: always
depends_on:
- db
environment:
NODE_ENV: development
PORT: 3000
DATABASE_URL: postgresql://postgres:bugloss@db:5432/codeit-test?schema=public
volumes:
- ./uploads:/app/dist/uploads
ports:
- '3000:3000'

volumes:
db-data:
92 changes: 92 additions & 0 deletions part4-mission11/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const importPlugin = require('eslint-plugin-import');
const jestPlugin = require('eslint-plugin-jest');
const globals = require('globals');
const tseslint = require('typescript-eslint');

module.exports = [
// 예외(무시) 경로
{ ignores: ['node_modules/**', 'dist/**', 'coverage/**', 'generated/**'] },

// 기본 규칙 세트
{
files: ['**/*.{ts,tsx,js,cjs}'],
languageOptions: {
parser: tseslint.parser,
ecmaVersion: 'latest',
sourceType: 'module',
globals: { ...globals.node, ...globals.es2022 },
parserOptions: {
project: false,
},
},
plugins: {
'@typescript-eslint': tseslint.plugin,
import: importPlugin,
jest: jestPlugin,
},
settings: {
'import/resolver': { typescript: {} },
},
rules: {
// @typescript-eslint 권장 규칙 기반
...tseslint.configs.recommended.rules,
'@typescript-eslint/no-explicit-any': 'error',

// 사용 규칙 커스터마이즈
'no-console': ['warn', { allow: ['warn', 'error'] }],
'import/no-unresolved': 'off',
'import/order': [
'warn',
{
'newlines-between': 'always',
alphabetize: { order: 'asc', caseInsensitive: true },
groups: [
['builtin', 'external'],
['internal', 'parent', 'sibling', 'index'],
],
},
],

// 기본 no-unused-vars는 끄고 TS 버전만 사용
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
},
},

// 테스트 전용 오버라이드 (Jest 전역/규칙)
{
files: ['**/src/tests/**/*', '**/*.test.{ts,tsx,js}'],
languageOptions: {
globals: { ...globals.node, ...globals.jest },
},
rules: {
'no-console': 'off', // 테스트 로그 허용
},
},

// CommonJS 설정 파일(.cjs) 허용
{
files: ['**/*.cjs'],
languageOptions: { sourceType: 'script' },
},

{
files: ['**/*.d.ts'],
rules: {
'@typescript-eslint/no-unused-vars': 'off',
},
},

{
files: ['src/prisma/seed.ts', 'src/middlewares/logger.ts', 'src/app.ts'],
rules: { 'no-console': 'off' },
},
];
18 changes: 18 additions & 0 deletions part4-mission11/infra/ec2/ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
apps: [
{
name: 'part4-mission10',
script: 'dist/server.js',
instances: 1,
exec_mode: 'fork',
watch: false,
env: {
NODE_ENV: 'development',
},
env_production: {
NODE_ENV: 'production',
},
max_memory_restart: '300M',
},
],
};
36 changes: 36 additions & 0 deletions part4-mission11/infra/ec2/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
worker_connections 1024;
}

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

sendfile on;
keepalive_timeout 65;

upstream backend {
server 127.0.0.1:4000;
}

server {
listen 80;
server_name _;

location / {
proxy_pass http://backend;
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;
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading