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
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
.next
.git
.env*
*.log
.DS_Store
coverage
dist
19 changes: 17 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,44 @@ jobs:
deploy:
if: github.event.pull_request.merged == true
runs-on: self-hosted
timeout-minutes: 10

steps:
- uses: actions/checkout@v3

- name: Deploy to EC2
run: |
set -e # ์—๋Ÿฌ ์‹œ ์ค‘๋‹จ
set -e

# ๋ฐฐํฌ ๋กœ๊น…
echo "๐Ÿš€ Starting deployment..."
echo "๐Ÿ“ PR: #${{ github.event.pull_request.number }}"
echo "๐Ÿ”„ Commit: ${{ github.sha }}"

# ๋ฉ”๋ชจ๋ฆฌ ์ •๋ฆฌ
echo "๐Ÿงน Cleaning up Docker resources..."
docker system prune -f

# ๋ธŒ๋žœ์น˜๋ณ„ ํ™˜๊ฒฝ ์„ค์ •
if [ "${{ github.event.pull_request.base.ref }}" = "main" ]; then
CONTAINER_NAME="app-prod"
ENV_FILE="app-prod.env"
OTHER_CONTAINER="app-dev"
echo "๐Ÿš€ Deploying to PRODUCTION"
elif [ "${{ github.event.pull_request.base.ref }}" = "develop" ]; then
CONTAINER_NAME="app-dev"
ENV_FILE="app-dev.env"
OTHER_CONTAINER="app-prod"
echo "๐Ÿงช Deploying to DEVELOPMENT"
fi

# ๋ฐฐํฌ ๋””๋ ‰ํ† ๋ฆฌ ์„ค์ •
DEPLOY_DIR="/home/ubuntu/coplan/app"

# ๋ฉ”๋ชจ๋ฆฌ ํ™•๋ณด๋ฅผ ์œ„ํ•ด ๋‹ค๋ฅธ ์ปจํ…Œ์ด๋„ˆ ์ค‘์ง€
echo "โธ๏ธ Stopping other container to free memory..."
docker compose stop ${OTHER_CONTAINER} || true

# rsync๋กœ ํŒŒ์ผ ๋™๊ธฐํ™”
echo "๐Ÿ“‚ Synchronizing files..."
rsync -av \
Expand All @@ -58,12 +69,16 @@ jobs:

# Docker ์ด๋ฏธ์ง€ ๋นŒ๋“œ
echo "๐Ÿ”จ Building Docker image..."
docker compose build ${CONTAINER_NAME}
DOCKER_BUILDKIT=1 docker compose build ${CONTAINER_NAME}

# ์ปจํ…Œ์ด๋„ˆ ๊ต์ฒด (๋ฌด์ค‘๋‹จ ๋ฐฐํฌ)
echo "๐Ÿ”„ Updating container..."
docker compose up -d --no-deps ${CONTAINER_NAME}

# ๋‹ค๋ฅธ ์ปจํ…Œ์ด๋„ˆ ์žฌ์‹œ์ž‘
echo "๐Ÿ”„ Restarting other container..."
docker compose up -d ${OTHER_CONTAINER}

# ํ—ฌ์Šค์ฒดํฌ
echo "๐Ÿฅ Health check..."
sleep 10
Expand Down
34 changes: 21 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
FROM node:18-alpine

# 1๋‹จ๊ณ„: ๋ชจ๋“  ์˜์กด์„ฑ ์„ค์น˜ (์บ์‹œ์šฉ)
FROM node:18-alpine AS deps
WORKDIR /app

# ์˜์กด์„ฑ ํŒŒ์ผ ๋ณต์‚ฌ
COPY package*.json ./
RUN npm ci

# ๋ชจ๋“  ์˜์กด์„ฑ ์„ค์น˜ (dev ํฌํ•จ)
RUN npm ci
# 2๋‹จ๊ณ„: ์†Œ์Šค ๋นŒ๋“œ
FROM node:18-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build

# ์†Œ์Šค ์ฝ”๋“œ ๋ณต์‚ฌ
COPY . .
# 3๋‹จ๊ณ„: ํ”„๋กœ๋•์…˜ ์‹คํ–‰ ํ™˜๊ฒฝ
FROM node:18-alpine AS runner
WORKDIR /app
ENV NODE_ENV production

# Next.js ๋นŒ๋“œ
RUN npm run build
# ํ”„๋กœ๋•์…˜ ์˜์กด์„ฑ๋งŒ ์žฌ์„ค์น˜
COPY package*.json ./
RUN npm ci --only=production

# ํฌํŠธ ์„ค์ •
EXPOSE 3000
# ๋นŒ๋“œ ๊ฒฐ๊ณผ๋ฌผ๋งŒ ๋ณต์‚ฌ
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.mjs ./

# ์„œ๋ฒ„ ์‹คํ–‰
EXPOSE 3000
CMD ["npm", "start"]
Loading