Skip to content

Commit

Permalink
Update auto-deployment.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
wwingyou authored Mar 25, 2024
1 parent 501b90e commit 87fdd93
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions .github/workflows/auto-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ jobs:

steps:
- uses: actions/checkout@v4.1.2

- name: Show git status
run: git status

- name: Setup Java JDK
uses: actions/setup-java@v4.2.1
with:
Expand All @@ -32,11 +34,13 @@ jobs:
# The architecture of the package (defaults to the action runner's architecture)
architecture: x64
cache: gradle

- name: Build Jar
run: |
chmod 755 gradlew
./gradlew bootJar
working-directory: JWT

- name: Prepare SSH connect
env:
private_key: ${{ secrets.EC2_PRIVATE_KEY }}
Expand All @@ -46,24 +50,35 @@ jobs:
mkdir ~/.ssh
ssh-keyscan -t rsa $host > ~/.ssh/known_hosts
working-directory: JWT

- name: Upload deployment scripts
run: |
scp -i private_key.pem -r deploy "${username}@${host}:~"
sudo chmod 755 deploy/*
working-directory: JWT

- name: Kill current running Spring process
run: |
ssh -i private_key.pem "${username}@${host}"
deploy/shutdown.sh
deploy/backup.sh
working-directory: JWT
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
script: |
sudo chmod 755 deploy/*
deploy/shutdown.sh
deploy/backup.sh
- name: Send jar file to EC2
run: |
jarPath=$(./gradlew -q jarPath)
scp -i private_key.pem $jarPath "${username}@${host}:~/server.jar"
working-directory: JWT

- name: Run new uploaded jar
run: |
ssh -i private_key.pem "${username}@${host}"
deploy/startup.sh
working-directory: JWT
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
script: |
sudo chmod 755 deploy/*
deploy/startup.sh

0 comments on commit 87fdd93

Please sign in to comment.