-
Notifications
You must be signed in to change notification settings - Fork 23
[이보라] Sprint11 #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 이보라
Are you sure you want to change the base?
[이보라] Sprint11 #161
Changes from all commits
dc5046d
ab51c9e
42ef1fb
8933124
d377469
208a71d
174473b
f313396
1f3af29
29234e9
e123847
26855ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
|
|
||
| ## 요구사항 | ||
|
|
||
| ### 기본 | ||
| - [x] 기본 항목 1 | ||
| - [ ] 기본 항목 2 | ||
|
|
||
| ### 심화 | ||
| - [ ] 심화 항목 1 | ||
| - [ ] 심화 항목 2 | ||
|
|
||
| ## 주요 변경사항 | ||
| - | ||
| - | ||
|
|
||
| ## 스크린샷 | ||
|  | ||
|
|
||
| ## 멘토에게 | ||
| - 셀프 코드 리뷰를 통해 질문 이어가겠습니다. | ||
| - |
| 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 "배포가 완료되었습니다!" | ||
| 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| 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"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| name: panda-market-sprint11 | ||
|
|
||
| services: | ||
| db: | ||
| image: postgres:latest | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 최신 버전(latest)의 postgres 이미지를 이용하고 계시네요! (
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 단순히 |
||
|
|
||
| volumes: | ||
| postgres_data: | ||
| 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 | ||
| } |
| 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' | ||
| } | ||
| }] | ||
| }; |
| 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 { | ||
| # } | ||
| # } | ||
| } |
| 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 |
There was a problem hiding this comment.
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...)
작성하신 스크립트로는 새로운 코드가 서버에 적용되지 않을거같은데 어떻게 해결할 수 있을까요?? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
새로운 폴더에 맞춰서 스크립트를 변경하면 되지 않을까요?!😭.. 현재는 새 미션마다 폴더를 새로 생성해서 작업중이라 저렇게 했었습니다! ㅠㅠ