Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/pink-boss/joosum-web into main
Browse files Browse the repository at this point in the history
  • Loading branch information
developerQuo committed Nov 17, 2024
2 parents 521cafe + 97d5570 commit a3118cc
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# 문서 파일
LICENSE
README.md

75 changes: 75 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: CI/CD Pipeline

on:
push:
branches:
- main

jobs:
build_and_push_docker_image:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Generate Date
id: date
run: echo "date=$(date +'%y%m%d')" >> $GITHUB_OUTPUT

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install Dependencies
run: npm ci

- name: Create .env
run: |
echo "${{ secrets.ENV }}" > ./.env
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to Docker Registry
uses: docker/login-action@v1
with:
registry: joosum.kr.ncr.ntruss.com
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}

- name: Build and Push Docker Image
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
platforms: linux/amd64
tags: joosum.kr.ncr.ntruss.com/joosum-frontend:${{ steps.date.outputs.date }}
push: true

deploy:
runs-on: ubuntu-latest
needs: build_and_push_docker_image
if: github.ref == 'refs/heads/main'

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Generate Date
id: date
run: echo "date=$(date +'%y%m%d')" >> $GITHUB_OUTPUT

- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.VM_HOST_IP }}
username: root
password: ${{ secrets.VM_PASSWORD }}
script: |
docker pull joosum.kr.ncr.ntruss.com/joosum-frontend:${{ steps.date.outputs.date }}
docker stop frontend || true
docker run --rm -d -p 3000:3000 \
--log-opt max-size=10k --log-opt max-file=3 \
--name frontend joosum.kr.ncr.ntruss.com/joosum-frontend:${{ steps.date.outputs.date }}
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use Node.js LTS version
FROM node:18-alpine

# Set working directory
WORKDIR /app

# Copy package.json and package-lock.json
COPY package.json package-lock.json* ./

# Install dependencies
RUN npm ci

# Copy the rest of the application code
COPY . .

# Expose the port Next.js dev server runs on
EXPOSE 3000

# Start the application in development mode
CMD ["npm", "run", "dev"]
40 changes: 40 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Dockerfile

# Stage 1: Install Dependencies
FROM node:18-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm ci

# Stage 2: Build
FROM node:18-alpine AS builder
WORKDIR /app

# 필요한 파일만 복사
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# .env.prod 파일을 .env.production으로 복사
COPY .env.prod ./.env.production

# 빌드 실행
RUN npm run build

# Stage 3: Production Image
FROM node:18-alpine AS runner
WORKDIR /app

ENV NODE_ENV production

# 프로덕션 의존성만 설치
COPY package.json package-lock.json* ./
RUN npm ci --only=production

# 빌드 결과물 복사
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/next.config.mjs ./

EXPOSE 3000

CMD ["npm", "start"]

0 comments on commit a3118cc

Please sign in to comment.