BE CD for Dev #207
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 CD for Dev | |
on: | |
workflow_dispatch: | |
push: | |
branches: [ "develop" ] | |
paths: | |
- backend/** | |
jobs: | |
build: | |
timeout-minutes: 2 | |
runs-on: [ self-hosted, linux, ARM64, dev ] # Self hosted runner 사용 | |
defaults: | |
run: | |
working-directory: ./backend | |
steps: | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
- name: bootJar with Gradle | |
run: ./gradlew bootJar -PcreateRestDocs | |
- name: Change artifact file name | |
run: mv build/libs/*.jar build/libs/app.jar | |
- name: Upload artifact file | |
uses: actions/upload-artifact@v4 | |
with: | |
name: app-artifact | |
path: ./ | |
deploy: | |
needs: build | |
timeout-minutes: 2 | |
runs-on: [ self-hosted, linux, ARM64, dev ] | |
steps: | |
- name: Download artifact file | |
uses: actions/download-artifact@v4 | |
with: | |
name: app-artifact | |
path: ~/app | |
- name: Deploy artifact file | |
run: | | |
cd ~/app || { echo "Build directory not found"; exit 1; } | |
JAR_FILE=$(ls *.jar | head -n 1) | |
if [ -z "$JAR_FILE" ]; then | |
echo "No JAR file found" | |
exit 1 | |
fi | |
PID=$(lsof -t -i:8080) | |
if [ -n "$PID" ]; then | |
echo "Killing process $PID running on port 8080" | |
kill -9 $PID | |
echo "Process $PID has been killed" | |
else | |
echo "No process is running on port 8080" | |
fi | |
nohup java -Dspring.profiles.active=dev -Duser.timezone=Asia/Seoul -Dserver.port=8080 -jar "$JAR_FILE" & |