diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..a16bd769 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +node_modules +npm-debug.log +build +.git +.gitignore +README.md +.env +.DS_Store diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..6ca5ebb3 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..4c621e6c --- /dev/null +++ b/.github/workflows/test.yml @@ -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 diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 97f0e81d..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "prisma.pinToPrisma6": true -} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..3813c95b --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..49ec255d --- /dev/null +++ b/docker-compose.yml @@ -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 + 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 diff --git a/infra/ec2/ecosystem.config.js b/infra/ec2/ecosystem.config.js index dc709bc7..142fb913 100644 --- a/infra/ec2/ecosystem.config.js +++ b/infra/ec2/ecosystem.config.js @@ -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: { diff --git a/package.json b/package.json index f6956ad8..da2abe29 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/types/notification.ts b/src/types/Notification.ts similarity index 100% rename from src/types/notification.ts rename to src/types/Notification.ts