Skip to content
Merged
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
43 changes: 43 additions & 0 deletions .github/workflows/cd.yml
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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dockerhub를 이용해서 cd파이프 라인 잘 구현하셨네요!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

버전 추적을 용이하게 하려면 github.sha활용해서 버전 태깅 넣어보시는것도 추천드릴게요!

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

27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
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

16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:20
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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"]
31 changes: 31 additions & 0 deletions docker-compose.yaml
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:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Named Volume을 사용하여 데이터 영속성을 보장한 점이 좋습니다~

upload_data:
postgres_data:
2 changes: 2 additions & 0 deletions mission9/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 .env 파일이 제외되지 않아 Docker 이미지에 환경 변수 파일이 포함될 수 있습니다. 보안을 위해 반드시 .env를 추가해주세요.

npm-debug.log