Skip to content

Spring Code deploy

Spring Code deploy #70

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 17
uses: actions/setup-java@v3
with:
java-version: '17'
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: Setup redis
uses: shogo82148/actions-setup-redis@v1.30.1
with:
redis-version: 6.2.0
redis-port: 6379
auto-start: true
- name: injection application.yml
run: |
touch src/main/resources/application-prod.yml
touch src/main/resources/application-dev.yml
touch src/main/resources/application-test.yml
touch src/main/resources/application-prod-log.properties
touch src/main/resources/application-dev-log.properties
echo "${{ secrets.PROD_YML }}" > src/main/resources/application-prod.yml
echo "${{ secrets.DEV_YML }}" > src/main/resources/application-dev.yml
echo "${{ secrets.TEST_YML }}" > src/main/resources/application-test.yml
echo "${{ secrets.DEV_LOG_PROPERTIES }}" > src/main/resources/application-dev-log.properties
echo "${{ secrets.PROD_LOG_PROPERTIES }}" > src/main/resources/application-prod-log.properties
shell: bash
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew clean build
- 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"
rm: 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 -Dspring.profiles.active="prod" $SOURCE_DIR/$FILE_NAME 1>$SOURCE_DIR/stdout.out 2>$SOURCE_DIR/stderr.out 2>&1 &