From dd655fae0e79e5316f8c70cb4d0a8f34dd23eae4 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 03:40:58 +0900 Subject: [PATCH] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 76e5746..5afacca 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -15,7 +15,6 @@ jobs: env: host: ${{ secrets.EC2_HOST }} username: ${{ secrets.EC2_USERNAME }} - private_key: ${{ secrets.EC2_PRIVATE_KEY }} steps: - uses: actions/checkout@v4.1.2 @@ -39,10 +38,20 @@ jobs: chmod 755 gradlew ./gradlew bootJar ./gradlew jarDir - - name: Connect to EC2 + - name: Prepare SSH private key + env: + private_key: ${{ secrets.EC2_PRIVATE_KEY }} run: | echo "$private_key" > private_key.pem chmod 400 private_key.pem - ssh -o StrictHostKeyChecking=no -i private_key.pem "${username}@${host}" echo hello - - name: Env Test - run: echo $host + - name: Kill current running Spring process + run: ssh -o StrictHostKeyChecking=no -i private_key.pem "${username}@${host}" 'kill $(sudo lsof -t -i :8080)' + - 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" + - name: Run new uploaded jar + run: | + sudo chmod 755 runner.sh + ./runner.sh server.jar