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
51 changes: 51 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Deploy to EC2

on:
pull_request:
types: [closed]
branches: [main, develop]

jobs:
deploy:
if: github.event.pull_request.merged == true
runs-on: self-hosted

steps:
- uses: actions/checkout@v3

- name: Deploy to EC2
run: |
set -e # μ—λŸ¬ μ‹œ 쀑단

# 배포 λ‘œκΉ…
echo "πŸš€ Starting deployment..."
echo "πŸ“ PR: #${{ github.event.pull_request.number }}"

# λΈŒλžœμΉ˜λ³„ ν™˜κ²½ μ„€μ •
if [ "${{ github.event.pull_request.base.ref }}" = "main" ]; then
CONTAINER_NAME="coplan-prod"
echo "πŸš€ Deploying to PRODUCTION"
elif [ "${{ github.event.pull_request.base.ref }}" = "develop" ]; then
CONTAINER_NAME="coplan-dev"
echo "πŸ§ͺ Deploying to DEVELOPMENT"
fi

# μ½”λ“œ 볡사
cp -r . /home/ubuntu/coplan/app/
cd /home/ubuntu/coplan

# ν™˜κ²½λ³€μˆ˜ 파일 볡사 (μžˆλŠ” 경우만)
if [ -f "/home/ubuntu/env/${CONTAINER_NAME}.env" ]; then
echo "πŸ“‹ Copying environment variables..."
cp /home/ubuntu/env/${CONTAINER_NAME}.env ./app/.env.production
fi

# λΉŒλ“œ 및 배포
docker compose build $CONTAINER_NAME
docker compose up -d --no-deps --build $CONTAINER_NAME

# κ°„λ‹¨ν•œ ν—¬μŠ€μ²΄ν¬
sleep 10
docker ps | grep $CONTAINER_NAME

echo "βœ… Deployment completed!"
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:18-alpine

WORKDIR /app

# μ˜μ‘΄μ„± 파일 볡사
COPY package*.json ./

# μ˜μ‘΄μ„± μ„€μΉ˜
RUN npm ci --only=production

# μ†ŒμŠ€ μ½”λ“œ 볡사
COPY . .

# Next.js λΉŒλ“œ
RUN npm run build

# 포트 μ„€μ •
EXPOSE 3000

# μ„œλ²„ μ‹€ν–‰
CMD ["npm", "start"]
Loading