-
Notifications
You must be signed in to change notification settings - Fork 1
99 lines (84 loc) ยท 2.88 KB
/
gradle.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
90
91
92
93
94
95
96
97
98
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: Java CI with Gradle
on:
push:
branches: [ "CHAT-63-DevOps-ToolChain" ]
pull_request:
branches: [ "CHAT-63-DevOps-ToolChain" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build with Gradle
run: ./gradlew --warning-mode all build -i
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v3 # Checkout ์ก์
๋ฒ์ ์ v3์ผ๋ก ์ผ์น
- name: Set up SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.HOST }} >> ~/.ssh/known_hosts
- name: Check if JAR file exists
run: |
if [ -f "./build/libs/chatdiary-0.0.1-SNAPSHOT-plain.jar" ]; then
echo "JAR file exists"
else
echo "JAR file does not exist"
fi
- name: Copy jar file to remote
uses: appleboy/scp-action@master
with:
username: ec2-user
host: ${{ secrets.HOST }}
key: ${{ secrets.PRIVATE_KEY }}
source: "./build/libs/chatdiary-0.0.1-SNAPSHOT-plain.jar"
target: "/home/ec2-user/cicd"
- name: Check deploy script exists
run: |
if [ -f deploy.sh ]; then
echo "deploy.sh exists"
else
echo "deploy.sh does not exist"
exit 1
fi
- name: Copy deploy script file to remote
uses: appleboy/scp-action@master
with:
username: ec2-user
host: ${{ secrets.HOST }}
key: ${{ secrets.PRIVATE_KEY }}
source: "deploy.sh"
target: "/home/ec2-user/cicd"
- name: Execute deploy script
env:
DEPLOY_SERVER: ${{ secrets.HOST }}
DEPLOY_USER: ec2-user
DEPLOY_KEY: ${{ secrets.PRIVATE_KEY }}
DEPLOY_TARGET_DIR: /home/ec2-user/app
uses: appleboy/ssh-action@master
with:
username: ec2-user
host: ${{ secrets.HOST }}
key: ${{ secrets.PRIVATE_KEY }}
script: |
chmod +x /home/ec2-user/cicd/deploy.sh
sh /home/ec2-user/cicd/deploy.sh