From 87fdd9304e3d8231ec280a10aec7f78d793491a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:40:46 +0900 Subject: [PATCH] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 35 +++++++++++++++++++-------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 6662281..5bcc46f 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -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: @@ -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 }} @@ -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