From 274d5a94b20a4e2e84b060681c0feae57a13f853 Mon Sep 17 00:00:00 2001 From: thisiswooyeol Date: Mon, 20 Nov 2023 20:48:36 +0900 Subject: [PATCH] fix: remove cd from execution command fix: ec2 target directory fix: fix host key verification failed <- add remote server to known hosts refactor: rename springboot action names fix: add ssh script to run springboot app & add comments --- .github/workflows/springboot-on-pr.yaml | 2 +- .github/workflows/springboot-on-push.yaml | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.github/workflows/springboot-on-pr.yaml b/.github/workflows/springboot-on-pr.yaml index 67134163..737aa350 100644 --- a/.github/workflows/springboot-on-pr.yaml +++ b/.github/workflows/springboot-on-pr.yaml @@ -1,4 +1,4 @@ -name: Springboot CI +name: Springboot CI on PR on: pull_request: diff --git a/.github/workflows/springboot-on-push.yaml b/.github/workflows/springboot-on-push.yaml index 94f1cb73..eecf3321 100644 --- a/.github/workflows/springboot-on-push.yaml +++ b/.github/workflows/springboot-on-push.yaml @@ -1,4 +1,4 @@ -name: Springboot CI +name: Springboot CI on Push on: push: @@ -25,6 +25,7 @@ jobs: distribution: 'temurin' cache: gradle + # Build & Test - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle @@ -32,17 +33,26 @@ jobs: - name: Test with Gradle run: ./gradlew test - - name: Set up SSH + # Setup SSH + - name: Set up SSH agent with private key uses: webfactory/ssh-agent@v0.5.4 with: ssh-private-key: ${{ secrets.SPRINGBOOT_EC2_SSH_KEY }} + - name: Add remote server to known hosts + run: | + mkdir -p ~/.ssh + ssh-keyscan -H ${{ secrets.SPRINGBOOT_HOST_DNS }} >> ~/.ssh/known_hosts + + # Deploy - name: SCP jar file to server run: | - scp *jar ${{ secrets.SPRINGBOOT_USERNAME }}@${{ secrets.SPRINGBOOT_HOST_DNS }}:~/\ + scp *jar ${{ secrets.SPRINGBOOT_USERNAME }}@${{ secrets.SPRINGBOOT_HOST_DNS }}:\ ${{ secrets.SPRINGBOOT_TARGET_DIR }} working-directory: ./springboot/build/libs - name: Execute remote commands run: | - ssh ${{ secrets.SPRINGBOOT_USERNAME }}@${{ secrets.SPRINGBOOT_HOST_DNS }}\ - "fuser -k 8080/tcp" - ssh ${{ secrets.SPRINGBOOT_USERNAME }}@${{ secrets.SPRINGBOOT_HOST_DNS }}\ + ssh -v ${{ secrets.SPRINGBOOT_USERNAME }}@${{ secrets.SPRINGBOOT_HOST_DNS }}\ + "fuser -k 8080/tcp || true" + ssh -v ${{ secrets.SPRINGBOOT_USERNAME }}@${{ secrets.SPRINGBOOT_HOST_DNS }}\ + "sudo nohup /usr/bin/java -jar ${{ secrets.SPRINGBOOT_TARGET_DIR }}/build/libs/*.jar\ + > {{ secrets.SPRINGBOOT_TARGET_DIR }}/app.log 2>&1 &"