From fb66582620a0f05073742cba0d8f4cc9c95685f1 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 04:03:21 +0900 Subject: [PATCH] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 5afacca..b6ac48d 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -38,20 +38,30 @@ jobs: chmod 755 gradlew ./gradlew bootJar ./gradlew jarDir - - name: Prepare SSH private key + - name: Prepare SSH connect env: private_key: ${{ secrets.EC2_PRIVATE_KEY }} run: | echo "$private_key" > private_key.pem chmod 400 private_key.pem + eval "$(ssh-agent)" + ssh-add private_key.pem + ssh-keyscan -t rsa $host > ~/.ssh/known_hosts + - name: Upload deployment scripts + run: scp -r deploy "${username}@${host}:~/deploy" - name: Kill current running Spring process - run: ssh -o StrictHostKeyChecking=no -i private_key.pem "${username}@${host}" 'kill $(sudo lsof -t -i :8080)' + run: | + ssh "${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 -i private_key.pem $jarPath "${username}@${host}:~/server.jar" - scp -i private_key.pem "deployment/runner.sh" "${username}@${host}:~/runner.sh" + scp $jarPath "${username}@${host}:~/server.jar" - name: Run new uploaded jar run: | - sudo chmod 755 runner.sh - ./runner.sh server.jar + ssh "${username}@${host}" << EOF + sudo chmod 755 deploy/runner.sh + ./deploy/runner.sh server.jar + EOF