-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (74 loc) · 2.94 KB
/
server-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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 &