Skip to content

Update README.md

Update README.md #134

Workflow file for this run

name: Backend CI/CD using GitHub Actions & Docker
# 워크플로우 실행 조건 설정
on:
push:
branches: [ "main" ]
paths:
- 'backend/**'
- 'front/**'
pull_request:
branches: [ "main" ]
paths:
- 'backend/**'
- 'front/**'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# 코드 체크아웃
- uses: actions/checkout@v4
# 백엔드 빌드 환경 설정 (JDK 21)
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
# Docker 환경 변수 설정
- name: Set up Docker Environment
run: |
echo "DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}" >> $GITHUB_ENV
echo "DOCKER_PASSWORD=${{ secrets.DOCKER_PASSWORD }}" >> $GITHUB_ENV
# 백엔드 설정 파일 생성
- name: Create backend configuration files
run: |
mkdir -p ./backend/src/main/resources
cd ./backend/src/main/resources
echo "${{ secrets.APPLICATION_YML }}" > application.yml
# Gradle 설정
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5
# 백엔드 빌드
- name: Build Backend
run: |
cd backend
chmod +x ./gradlew
./gradlew build -x test
# Node.js 설정 (프론트엔드 빌드를 위한 Node.js 22 설치)
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '22'
# 프론트엔드 빌드
- name: Install and Build Frontend
run: |
cd frontend
npm install
npm run build
# Docker 이미지 빌드 및 푸시
- name: Docker build & push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
# 백엔드 이미지 빌드 및 푸시
cd backend
docker build -t ${{ secrets.DOCKER_USERNAME }}/backend:latest .
docker push ${{ secrets.DOCKER_USERNAME }}/backend:latest
# 프론트엔드 이미지 빌드 및 푸시
cd ../frontend
docker build -t ${{ secrets.DOCKER_USERNAME }}/frontend:latest .
docker push ${{ secrets.DOCKER_USERNAME }}/frontend:latest
# 서버에 docker-compose.yml 생성 및 실행
- name: Deploy using Docker Compose
uses: appleboy/[email protected]
with:
host: ${{ secrets.SJ_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SJ_PRIVATE_KEY }}
script: |
# 서버 디렉토리로 이동
mkdir -p ~/sejong-dibb
cd ~/sejong-dibb
# GitHub Secrets에서 docker-compose.yml 생성
echo "${{ secrets.DOCKER_COMPOSE_YML }}" > docker-compose.yml
# 기존 컨테이너 정리 및 새 배포 실행
docker-compose down || true
docker-compose pull
docker-compose up -d