Skip to content

Kerdy Backend Dev Server CI/CD #77

Kerdy Backend Dev Server CI/CD

Kerdy Backend Dev Server CI/CD #77

name: Kerdy Backend Dev Server CI/CD
on:
workflow_dispatch:
permissions:
contents: read
jobs:
build-and-upload:
runs-on: ubuntu-22.04
defaults:
run:
working-directory: backend/emm-sale
services:
mysql:
image: mysql:8.0.28
env:
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: 1234
MYSQL_DATABASE: kerdy
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: 선택된 브랜치로 checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.SUBMODULE_TOKEN }}
submodules: true
- name: JDK 11로 설정
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'temurin'
- name: Gradle에 실행 권한 부여
run: chmod +x gradlew
- name: Gradle 캐싱
id: cache-gradle
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: gradle 빌드
run: ./gradlew build && ./gradlew build
- name: jar artifact에 업로드
uses: actions/upload-artifact@v3
with:
name: BackendApplicationJar
path: backend/emm-sale/build/libs/*.jar
deploy:
runs-on: self-hosted
needs: build-and-upload
steps:
- name: 구버전 jar 삭제
run: rm -rf /home/ubuntu/backend/build/emm-sale-*.jar
- name: artifact에서 jar파일 다운 받기
uses: actions/download-artifact@v3
with:
name: BackendApplicationJar
path: /home/ubuntu/backend/build/
- name: 권한부여
run: chmod +x /home/ubuntu/backend/build/emm-sale-*.jar
- name: 배포하기
run: /home/ubuntu/backend/build/deploy.sh
- name: 슬랙 메시지 보내기
uses: 8398a7/action-slack@v3
with:
mention: 'here'
if_mention: failure
status: ${{ job.status }}
fields: workflow,job,commit,message,ref,author,took
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()