-
Notifications
You must be signed in to change notification settings - Fork 30
[김지선] sprint11 #218
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
The head ref may contain hidden characters: "\uAE40\uC9C0\uC120-sprint11"
[김지선] sprint11 #218
Changes from all commits
f4f132c
dbc8acc
0da72bc
4444e89
8774283
c0a3df9
898df61
2d5b10a
194faf6
93a7954
83ce270
fb346ea
ca8279c
25ad959
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,15 @@ | ||
| node_modules/ | ||
| **/node_modules/ | ||
|
|
||
| files/** | ||
| dist/** | ||
| coverage/** | ||
|
|
||
| REST API test/** | ||
| .env | ||
| .env.test | ||
|
|
||
| README.md | ||
| .gitignore | ||
| .dockerignore | ||
| .github/** |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # 자동화 작업 이름 | ||
| name : Panda Market CI/CD Test | ||
|
|
||
| # 작업 시점 | ||
| on: | ||
| push : # 브랜치에 코드가 푸시될 때 | ||
| branches : # 1차 : "김지선" 브랜치 / 2차(최종) : "main" 브랜치 설정 | ||
| - 김지선-sprint11 # action test용 | ||
| - 김지선 | ||
| - main | ||
| pull_request : # 브랜치에 코드가 머지될 때 | ||
| branches : | ||
| - 김지선-sprint11 # action test용 | ||
| - 김지선 | ||
| - main | ||
|
|
||
| # 작업 내용 | ||
| jobs: | ||
|
|
||
| test: | ||
| # run 환경 | ||
| runs-on: ubuntu-latest | ||
|
|
||
| # DB 환경 | ||
| services: | ||
| postgres: | ||
| image: postgres:15 | ||
| env: | ||
| POSTGRES_USER: ${{ secrets.TEST_DB_USER || 'postgres' }} | ||
| POSTGRES_PASSWORD: ${{ secrets.TEST_DB_PASSWORD || 'passwordnd6!' }} | ||
| POSTGRES_DB: ${{ secrets.TEST_DB_NAME || 'panda_market' }} | ||
| ports: | ||
| - 5432:5432 | ||
| options: >- | ||
| --health-cmd pg_isready | ||
| --health-interval 10s | ||
| --health-timeout 5s | ||
| --health-retries 5 | ||
|
|
||
| # 공통 환경변수 | ||
| env: | ||
| # 테스트용 DB : 정보는 git secrets 저장 | ||
| # PR 전송을 위해 테스트용 DB 연결 정보 추가 | ||
| DATABASE_URL: ${{ secrets.TEST_DATABASE_URL || 'postgresql://postgres:passwordnd6!@localhost:5432/panda_market?schema=public' }} | ||
| NODE_ENV: test | ||
|
|
||
| # 테스트용 임시 키 설정 | ||
| JWT_ACCESS_TOKEN_SECRET: "test_secret_key_12345" | ||
| JWT_REFRESH_TOKEN_SECRET: "test_secret_key_12345" | ||
|
|
||
| # 최종 작업에서는 git secret 사용, 현재는 규격만 맞춤 | ||
| AWS_REGION: "ap-northeast-2" | ||
| AWS_ACCESS_KEY_ID: "dummy_key" | ||
| AWS_SECRET_ACCESS_KEY: "dummy_secret" | ||
| AWS_BUCKET_NAME: "test-bucket" | ||
|
|
||
| # test 작업 순서 | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: 'lts/*' | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install | ||
|
|
||
| - name: Type Check | ||
| run: npm run typecheck | ||
|
|
||
| - name: Run Tests | ||
| run: | | ||
| npx prisma migrate deploy | ||
| npm run test | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # 자동화 작업 이름 | ||
| name : Deploy to EC2 panda-market | ||
|
|
||
| # 작업 시점 | ||
| on: | ||
| push : | ||
| branches : | ||
| - 김지선 # 1차 : 상위 브랜치 | ||
| - main # 2차 : 최종 브랜치 | ||
| # pull_request : | ||
| # branches : | ||
| # - main | ||
|
|
||
| # 작업 내용 | ||
| jobs: | ||
|
|
||
| deploy: | ||
| # run 환경 | ||
| if: github.repository == 'KimDay366/6-sprint-mission' # 현재 개인 레포지토리에만 secret 설정이 되어있어 해당 조건을 추가하였습니다 | ||
|
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. 우선 오류 원인을 파악하시고 secrets 이름으로 분기각 환경에 맞는 식별자를 붙인 GitHub EnvironmentsGithub 레포지토리 설정에서 Environment를 생성하고 환경별로 sercret 값을 설정하는 방법입니다.
Collaborator
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. 오호!!! 해당 방법도 같이 공부 해 보겠습니다~ 감사합니다 😁 |
||
| runs-on: ubuntu-latest | ||
|
|
||
| # 환경변수 | ||
| env: | ||
| # DB 정보 | ||
| DATABASE_URL: ${{ secrets.DATABASE_URL }} | ||
| NODE_ENV: production | ||
|
|
||
| # JWT 설정 | ||
| JWT_ACCESS_TOKEN_SECRET: ${{ secrets.JWT_ACCESS_TOKEN_SECRET }} | ||
| JWT_REFRESH_TOKEN_SECRET: ${{ secrets.JWT_REFRESH_TOKEN_SECRET }} | ||
|
|
||
| # AWS 설정 | ||
| AWS_REGION: ${{ secrets.AWS_REGION }} | ||
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
| AWS_BUCKET_NAME: ${{ secrets.AWS_BUCKET_NAME }} | ||
|
|
||
| # EC2 설정 | ||
| EC2_HOST: ${{ secrets.EC2_HOST }} | ||
| EC2_USER: ${{ secrets.EC2_USER }} | ||
| EC2_PRIVATE_KEY: ${{ secrets.EC2_PRIVATE_KEY }} | ||
|
Comment on lines
+23
to
+41
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.
|
||
|
|
||
|
|
||
| # deploy 작업 순서 | ||
| steps: | ||
| - name: Deploy to EC2 | ||
| uses: appleboy/ssh-action@v0.1.6 | ||
| with: | ||
| host: ${{ env.EC2_HOST }} | ||
| username: ${{ env.EC2_USER }} | ||
| key: ${{ env.EC2_PRIVATE_KEY }} | ||
| port: 22 | ||
| script: | | ||
| cd /home/ec2-user/6-sprint-mission | ||
| git pull origin ${{ github.ref_name }} # 최신 브랜치 자동 인식 | ||
| npm install | ||
| npm run build | ||
| npm run prisma:deploy | ||
| pm2 reload panda-market || pm2 start dist/src/server.js --name "panda-market" | ||
| echo "Deployment successful!" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| ### Action push / pull_request 동작 방식 | ||
|
|
||
| 1. push : 브랜치에 코드가 푸시될 때 | ||
| 2. pull_request : 브랜치에 코드가 머지될 때 | ||
|
|
||
|
|
||
| ### 현재 구현 방식에서의 워크플로우 | ||
|
|
||
| 1. 로컬에서 git 저장 : git add . & git commit -m "..." | ||
| 2. 원격 레포지토리로 로컬 저장 내용을 Push : action.yml에 설정 해 둔 "on.push"에 의해 Action이 실행 | ||
| 3. 공용 레포(학원 레포)로 PR 생성 : action.yml에 설정 해 둔 "on.pull_request"에 의해 Action이 실행 | ||
| 4. 멘토님의 PR 리뷰 후 승인 시, 공용 레포에 머지 -> deploy.yml에 설정 해 둔 "on.push"에 의해 Action이 실행 | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Base Build image | ||
|
|
||
| # node 버전 설정 | ||
| ARG NODE_VERSION=22.19.0 | ||
| FROM node:${NODE_VERSION} | ||
|
|
||
| # 서버 포트 설정 | ||
| ENV SERVER_PORT=3000 | ||
|
|
||
| # 디렉토리 설정 | ||
| WORKDIR /app | ||
|
|
||
| # 복사할 작업 분할(레이어 캐싱) | ||
| # 1) package.json, package-lock.json 복사 | ||
| COPY package*.json ./ | ||
| RUN npm install | ||
|
|
||
| # 2) prisma 복사 | ||
| COPY prisma ./prisma/ | ||
| RUN npx prisma generate | ||
|
|
||
| # 3) 나머지 파일 복사 및 빌드 | ||
| COPY . . | ||
| RUN npm run build | ||
|
|
||
| # 서버 실행 명령어 | ||
| CMD ["node", "dist/src/server.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.
위처럼 작성하면 PR이 생성될때 실행이 되는걸로 알고있었는데 아니였나보군요? 😀
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.
저도 PR로 생각 했는데, PR을 확인 한 뒤 기존 브랜치에 머지 할 때 실행되는 거라고 하네요~ 😉