Update .gitignore #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: BE CI/CD with MySQL and EC2 Deploy | |
on: | |
push: | |
branches: [ "develop" ] | |
pull_request: | |
branches: [ "develop" ] | |
jobs: | |
backend-CI: | |
runs-on: ubuntu-latest | |
services: | |
db: | |
image: mysql:8.0 | |
env: | |
MYSQL_ROOT_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
MYSQL_DATABASE: aimo | |
MYSQL_USER: ${{ secrets.DB_USERNAME }} | |
MYSQL_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
ports: | |
- 3306:3306 | |
options: --health-cmd="mysqladmin ping -h localhost" --health-interval=10s --health-timeout=5s --health-retries=10 | |
steps: | |
# 소스 코드 체크아웃 | |
- uses: actions/checkout@v4 | |
# JDK 17 설정 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# Gradle 실행 권한 설정 | |
- name: Grant execute permission to gradlew | |
run: chmod +x gradlew | |
working-directory: ${{ secrets.WORKING_DIRECTORY }} | |
# Gradle 빌드 및 테스트 실행 (로컬 컨테이너의 MySQL 사용) | |
- name: Build and Test with Gradle | |
run: ./gradlew build -Dspring.profiles.active=ci | |
working-directory: ${{ secrets.WORKING_DIRECTORY }} | |
env: | |
SPRING_DATASOURCE_URL: jdbc:mysql://localhost:3306/aimo | |
SPRING_DATASOURCE_USERNAME: admin | |
SPRING_DATASOURCE_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
# 빌드된 JAR 파일을 EC2로 복사 | |
- name: Copy JAR file to EC2 | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USER }} | |
key: ${{ secrets.EC2_SSH_KEY }} | |
source: ${{ secrets.WORKING_DIRECTORY }}/build/libs/*.jar | |
target: /home/ubuntu/ | |
# EC2에서 애플리케이션 실행 (RDS 연결) | |
- name: Deploy to EC2 | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USER }} | |
key: ${{ secrets.EC2_SSH_KEY }} | |
script: | | |
if pgrep -f "app.jar"; then pkill -f "app.jar"; fi | |
nohup java -jar /home/ubuntu/app.jar --spring.profiles.active=prod > /dev/null 2>&1 & |