Skip to content

Commit

Permalink
[BE] chore: CD 초기 구축 (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehtjsv2 authored and jinuemong committed Jul 19, 2024
1 parent 11342eb commit 1ab1a77
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 4 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/backend-cd-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: deploy

on:
push:
branches: ['develop']
paths:
- 'backend/**'

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

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

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: 8.1.1

- name: Grant execute permission for gradlew
working-directory: ./backend
run: chmod +x gradlew

- name: Build project using Gradle
working-directory: ./backend
run: ./gradlew build

- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
working-directory: ./backend
name: friendogly-be-develop-jar
path: ./**/friendogly-0.0.1-SNAPSHOT.jar

deploy:
needs: build
runs-on: self-hosted
steps:
- name: change permission
run: |
sudo chown -R ubuntu:ubuntu /home/ubuntu/actions-runner/_work/2024-friendogly
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: friendogly-be-develop-jar
path: ./backend/build/libs

- name: Check if room-esc server is running on port 8080
id: check-server-on-port
run: |
echo "Checking if port 8080 is in use..."
PID=$(lsof -t -i:8080 || true)
if [ -n "$PID" ]; then
echo "server_running=true" >> $GITHUB_ENV
echo "PID=$PID" >> $GITHUB_ENV
else
echo "server_running=false" >> $GITHUB_ENV
fi
- name: Stop server if running
if: env.server_running == 'true'
run: |
echo "Stopping server running on port 8080..."
kill -9 $PID
echo "Preivous running Server stopped."
- name: Start server
run: |
cd backend/build/libs
cd backend/build/libs
sudo nohup java -jar friendogly-0.0.1-SNAPSHOT.jar &
echo "Lastest Backend API Server started."
9 changes: 5 additions & 4 deletions .github/workflows/backend-pull-request-ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: backend-ci

on:
push:
branches: [ "develop" ]
paths:
- 'backend/**'
pull_request:
branches: [ "develop" ]
paths:
Expand Down Expand Up @@ -65,3 +61,8 @@ jobs:
with:
report_paths: './backend/build/test-results/test/TEST-*.xml'
token: ${{ github.token }}

- name: Start server
run: |
sudo nohup java -jar build/libs/friendogly-0.0.1-SNAPSHOT.jar &
echo "Lastest Backend API Server started."

0 comments on commit 1ab1a77

Please sign in to comment.