-
Notifications
You must be signed in to change notification settings - Fork 1
92 lines (76 loc) · 2.57 KB
/
cicd_dev.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
88
89
name: TogetUp-Server-Dev CI/CD
on:
push:
branches: [ "main" ]
env:
S3_BUCKET_NAME: togetup-storage
FILE_PATH: /home/ubuntu/app/
FILE_NAME: TogetUp-0.0.1-SNAPSHOT.jar
jobs:
deploy_dev:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: Get CurrentTime
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00"
- name: Show Current Time
run: echo "CurrentTime=${{steps.current-time.outputs.formattedTime}}"
shell: bash
- name: make application.yml
run: |
## create application.yml
mkdir -p ./src/main/resources
cd ./src/main/resources
touch ./application.yml
echo '${{ secrets.TOGETUP_DEV_APPLICATION }}' >> ./application.yml
cat ./application.yml
shell: bash
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean build
- name: Deliver File
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_HOST_DEV }}
username: ${{ secrets.EC2_USERNAME_DEV }}
key: ${{ secrets.EC2_SSH_KEY_DEV }}
port: 22
source: "build/libs/TogetUp-0.0.1-SNAPSHOT.jar"
target: "/home/ubuntu/app"
strip_components: 2
overwrite: true
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST_DEV }}
username: ${{ secrets.EC2_USERNAME_DEV }}
key: ${{ secrets.EC2_SSH_KEY_DEV }}
port: 22
wait_for_deployment: false
script: |
SOURCE_DIR=/home/ubuntu/app/
FILE_NAME=TogetUp-0.0.1-SNAPSHOT.jar
PID=$(ps aux | grep $FILE_NAME | grep -v grep | awk '{print $2}')
echo "PID : $PID"
if [ -z "$PID" ]; then
echo "#### THERE IS NO PROCESS ####"
else
echo "#### KILL $PID ####"
sudo kill $PID
fi
echo "#### RUNNING $SOURCE_DIR/$FILE_NAME ####"
cd $SOURCE_DIR
sudo nohup java -jar $FILE_NAME > nohup.out 2> nohup.err < /dev/null &
sleep 5
echo "New PID after restart: $(ps aux | grep $FILE_NAME | grep -v grep | awk '{print $2}')"