-
Notifications
You must be signed in to change notification settings - Fork 33
[김혜연] Sprint Mission 11 #264
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\uD61C\uC5F0"
Changes from all commits
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,43 @@ | ||
| name: CD - Deploy to EC2 | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ "main" ] | ||
|
|
||
| jobs: | ||
| deploy: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Login to Docker Hub | ||
| uses: docker/login-action@v2 | ||
| with: | ||
| username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
| password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
|
||
| - name: Build and Push Docker image | ||
| uses: docker/build-push-action@v4 | ||
| with: | ||
| context: ./mission9 | ||
| file: ./Dockerfile | ||
| push: true | ||
| tags: ${{ secrets.DOCKERHUB_USERNAME }}/express-app:latest | ||
| platforms: linux/amd64 | ||
|
|
||
| - name: Copy SSH key | ||
| run: | | ||
| echo "${{ secrets.EC2_KEY }}" > key.pem | ||
| chmod 600 key.pem | ||
|
|
||
| - name: Deploy on EC2 | ||
| run: | | ||
| ssh -o StrictHostKeyChecking=no -i key.pem ec2-user@${{ secrets.EC2_HOST }} << 'EOF' | ||
| docker pull ${{ secrets.DOCKERHUB_USERNAME }}/express-app:latest | ||
| docker stop express-app || true | ||
| docker rm express-app || true | ||
| docker run -d -p 3000:3000 --name express-app ${{ secrets.DOCKERHUB_USERNAME }}/express-app:latest | ||
| EOF | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| name: CI - Test on PR | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [ "main" ] | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: 20 | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install | ||
| working-directory: ./mission9 | ||
|
|
||
| - name: Run tests | ||
| run: npm test | ||
| working-directory: ./mission9 | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| FROM node:20 | ||
|
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. 현재 단일 스테이지로 구성되어 있어 최종 이미지에 개발 의존성과 소스 코드가 모두 포함됩니다. 멀티 스테이지 빌드를 적용해 주세요! |
||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY package*.json ./ | ||
| COPY prisma ./prisma | ||
|
|
||
| RUN npm install | ||
|
|
||
| COPY . . | ||
|
|
||
| VOLUME /app/uploads | ||
|
|
||
| EXPOSE 3000 | ||
|
|
||
| CMD ["npm", "run", "start"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| version: '3.8' | ||
|
|
||
| services: | ||
| app: | ||
| image: kimdolmeng/express-app:latest | ||
| container_name: express-app | ||
| ports: | ||
| - 3000:3000 | ||
| volumes: | ||
| - upload_data:/app/uploads | ||
| environment: | ||
| DB_HOST: postgres | ||
| DB_USER: user_mbti | ||
| DB_PASSWORD: pw_mbti | ||
| DB_NAME: db_mbti | ||
| depends_on: | ||
| - db | ||
|
|
||
| postgres: | ||
|
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. 로컬 개발 환경에서 DB 접속이 필요할 경우를 위해 포트 매핑을 추가하는 것이 좋을 것 같아요! |
||
| image: postgres:15-alpine | ||
| container_name: postgres-db | ||
| volumes: | ||
| - postgres_data:/var/lib/postgresql/data | ||
| environment: | ||
| POSTGRES_DB: db_mbti | ||
| POSTGRES_USER: user_mbti | ||
| POSTGRES_PASSWORD: pw_mbti | ||
|
|
||
| volumes: | ||
|
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. Named Volume을 사용하여 데이터 영속성을 보장한 점이 좋습니다~ |
||
| upload_data: | ||
| postgres_data: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| node_modules | ||
|
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. 현재 |
||
| npm-debug.log | ||
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.
Dockerhub를 이용해서 cd파이프 라인 잘 구현하셨네요!
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.
버전 추적을 용이하게 하려면 github.sha활용해서 버전 태깅 넣어보시는것도 추천드릴게요!