Merge pull request #177 from ITZipProject/feature/resume #15
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: Java CI with Gradle Build & Deploy | |
on: | |
push: | |
branches: [ "main" ] | |
jobs: | |
build_and_deploy: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
- name: Secret Prod Env File Download | |
run: | | |
mkdir -p ./src/main/resources/properties | |
echo "${{ secrets.PROD_ENV_FILE }}" > ./src/main/resources/properties/env.properties | |
- name: Secret Test Env File Download | |
run: | | |
mkdir -p ./src/test/resources/properties | |
echo "${{ secrets.TEST_ENV_FILE }}" > ./src/test/resources/properties/test-env.properties | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 | |
- name: Build with Gradle Wrapper | |
id: build | |
run: ./gradlew build | |
- name: Login Dokcer | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build with Docker Push | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
file: Dockerfile | |
push: true | |
tags: | | |
${{ secrets.DOCKER_USERNAME }}/jdk-21-spring-boot-3.3.1:${{ github.sha }} | |
${{ secrets.DOCKER_USERNAME }}/jdk-21-spring-boot-3.3.1:latest | |
- name: SSH to Remote Server and Deploy | |
uses: appleboy/ssh-action@v1.0.3 | |
with: | |
host: ${{ secrets.REMOTE_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
port: ${{ secrets.SSH_PORT }} | |
script: | | |
docker-compose -f /home/ubuntu/itzip/docker-compose.yml down | |
docker-compose -f /home/ubuntu/itzip/docker-compose.yml pull | |
docker-compose -f /home/ubuntu/itzip/docker-compose.yml up -d | |
docker system prune -a -f | |
- name: Send Success Discord Notification | |
if: success() | |
run: | | |
curl -H "Content-Type: application/json" \ | |
-d '{"content": "**배포 성공!** :rocket: \n빌드 및 배포 과정이 성공적으로 완료되었습니다."}' \ | |
${{ secrets.DISCORD_WEBHOOK_URL }} | |
- name: Send Failure Discord Notification | |
if: failure() | |
run: | | |
outcome_message="" | |
if [ "${{ steps.build.outcome }}" == "failure" ]; then | |
outcome_message+="빌드 단계에서 오류 발생. " | |
fi | |
if [ "${{ steps.docker_build.outcome }}" == "failure" ]; then | |
outcome_message+="Docker 빌드 단계에서 오류 발생. " | |
fi | |
if [ "${{ steps.deploy.outcome }}" == "failure" ]; then | |
outcome_message+="배포 단계에서 오류 발생. " | |
fi | |
curl -H "Content-Type: application/json" \ | |
-d '{"content": "**배포 실패!** :x: \n빌드 및 배포 과정에서 오류가 발생했습니다. \n오류 내용: '"${outcome_message}"'"}' \ | |
${{ secrets.DISCORD_WEBHOOK_URL }} |