Skip to content

Spring Code deploy

Spring Code deploy #34

Workflow file for this run

name: Spring Code deploy
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
- name: Gradle Caching
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: injection file
run: |
touch src/main/resources/application-dev.yml
echo "${{ secrets.DEV_YML }}" > src/main/resources/application-dev.yml
shell: bash
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew build -x test
- name: Deliver JAR File
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
source: "build/libs/*.jar"
target: "source"
overwrite: true
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
SOURCE_DIR=source/build/libs
FILE_NAME=`find $SOURCE_DIR/*.jar -printf "%f\n"`
PID=$(sudo lsof -Fp -i TCP:8080 | grep -Po 'p[0-9]+' | grep -Po '[0-9]+')
if [ -z "$PID" ]; then
echo "#### THERE IS NO PROCESS ####"
else
echo "#### KILL $PID ####"
sudo kill -9 $PID
fi
echo "#### RUN $SOURCE_DIR/$FILE_NAME ####"
sudo nohup java -jar $SOURCE_DIR/$FILE_NAME -Dspring.profiles.active="dev" 1>$SOURCE_DIR/stdout.out 2>$SOURCE_DIR/stderr.out &