-
Notifications
You must be signed in to change notification settings - Fork 1
65 lines (59 loc) · 1.87 KB
/
auto-deployment.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
name: AWS EC2 자동 배포
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
env:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
steps:
- uses: actions/[email protected]
- name: Show git status
run: git status
- name: Setup Java JDK
uses: actions/[email protected]
with:
# The Java version to set up. Takes a whole or semver Java version. See examples of supported syntax in README file
java-version: 17
# Java distribution. See the list of supported distributions in README file
distribution: temurin
# The package type (jdk, jre, jdk+fx, jre+fx)
java-package: jdk
# The architecture of the package (defaults to the action runner's architecture)
architecture: x64
cache: gradle
- name: Build Jar
run: |
cd JWT
chmod 755 gradlew
./gradlew bootJar
- name: Prepare SSH connect
env:
private_key: ${{ secrets.EC2_PRIVATE_KEY }}
run: |
echo "$private_key" > private_key.pem
chmod 400 private_key.pem
mkdir ~/.ssh
ssh-keyscan -t rsa $host > ~/.ssh/known_hosts
- name: Upload deployment scripts
run: scp -i private_key.pem -r deploy "${username}@${host}:~"
- name: Kill current running Spring process
run: |
ssh -i private_key.pem "${username}@${host}" << EOF
sudo chmod 755 deploy/shutdown.sh
./deploy/shutdown.sh
EOF
- name: Send jar file to EC2
run: |
jarPath=$(./gradlew -q jarPath)
scp $jarPath "${username}@${host}:~/server.jar"
- name: Run new uploaded jar
run: |
ssh -i private_key.pem "${username}@${host}" << EOF
sudo chmod 755 deploy/runner.sh
./deploy/runner.sh server.jar
EOF