Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 45 additions & 27 deletions .github/workflows/spring-cd.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CD on PR Merged to develop
name: Deploy on PR Merged to develop

on:
pull_request:
Expand All @@ -7,53 +7,71 @@ on:

jobs:
build:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Grant permission to gradlew
run: chmod +x gradlew
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle

- name: Build with Gradle
run: ./gradlew build
- name: Grant permission to gradlew
run: chmod +x gradlew

- name: Upload JAR as artifact
uses: actions/upload-artifact@v3
with:
name: app-jar
path: build/libs/*.jar
- name: Build with Gradle
run: ./gradlew build

- name: Run tests
run: ./gradlew test

deploy:
needs: build
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}

deploy-on-merge:
if: github.event.pull_request.merged == true # ✔ merge된 PR일 때만 실행
runs-on: ubuntu-latest

steps:
- name: Download JAR artifact
uses: actions/download-artifact@v3
- name: Checkout source code
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
name: app-jar
distribution: 'temurin'
java-version: 17

- name: Build with Gradle
run: ./gradlew clean build -x test

- name: Set up SSH Agent
- name: Set up SSH
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.EC2_SSH_KEY }}

- name: Copy JAR to EC2
run: |
scp -o StrictHostKeyChecking=no app-jar/*.jar ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/home/ubuntu/app/app.jar
scp -i ${{secrets.EC2_SSH_KEY}} -o StrictHostKeyChecking=no build/libs/*.jar ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/home/${{ secrets.EC2_USER }}/app/app.jar

- name: Restart App with Docker Compose
run: |
ssh -o StrictHostKeyChecking=no ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
cd /home/ubuntu/app
ssh -i ${{secrets.EC2_SSH_KEY}} -o StrictHostKeyChecking=no ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
cd /home/${{ secrets.EC2_USER }}/app
docker compose up -d --force-recreate
EOF
Loading