From 0ad4f8db2e2a1f8a9e43f6bc1fdd1852761ad1a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=9D=BC=EB=AA=A8?= <96767857+OneEpitome@users.noreply.github.com> Date: Mon, 10 Apr 2023 16:11:44 +0900 Subject: [PATCH 1/4] Create main.yml --- .github/workflows/main.yml | 76 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..bf1092e --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,76 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle + +name: Deployment + +on: + workflow_dispatch: + push: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + - name: Build with Gradle + uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 + with: + arguments: build + - uses: actions/upload-artifact@v3 + with: + name: jar + path: build/libs + + send-jar: + needs: build + runs-on: ubuntu-latest + steps: + - name: Download jar + uses: actions/download-artifact@v3 + with: + name: jar + - name: Send jar to remote server + uses: appleboy/scp-action@master + with: + host: 34.64.253.120 + username: ilmo.kang03 + source: "real_coding_server-0.0.1-SNAPSHOT.jar" + target: "/home/adulkid.kaya" + key: ${{ secrets.PRIVATE_KEY }} + + run-app: + needs: send-jar + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Move deploy.sh + uses: appleboy/scp-action@master + with: + host: 34.64.253.120 + username: ilmo.kang03 + source: "deploy.sh" + target: "/home/{나의 userName}" + key: ${{ secrets.PRIVATE_KEY }} + - name: Execute script + uses: appleboy/ssh-action@master + with: + username: 34.64.253.120 + host: ilmo.kang03 + key: ${{ secrets.PRIVATE_KEY }} + script_stop: true + script: cd /home/{나의 userName} && chmod +x deploy.sh && ./deploy.sh From 98618112e0478877599ee75a54b3c9d560f52867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=9D=BC=EB=AA=A8?= <96767857+OneEpitome@users.noreply.github.com> Date: Mon, 10 Apr 2023 16:14:32 +0900 Subject: [PATCH 2/4] Update main.yml --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bf1092e..c63e21a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -49,7 +49,7 @@ jobs: host: 34.64.253.120 username: ilmo.kang03 source: "real_coding_server-0.0.1-SNAPSHOT.jar" - target: "/home/adulkid.kaya" + target: "/home/ilmo.kang03" key: ${{ secrets.PRIVATE_KEY }} run-app: @@ -64,7 +64,7 @@ jobs: host: 34.64.253.120 username: ilmo.kang03 source: "deploy.sh" - target: "/home/{나의 userName}" + target: "/home/ilmo.kang03" key: ${{ secrets.PRIVATE_KEY }} - name: Execute script uses: appleboy/ssh-action@master @@ -73,4 +73,4 @@ jobs: host: ilmo.kang03 key: ${{ secrets.PRIVATE_KEY }} script_stop: true - script: cd /home/{나의 userName} && chmod +x deploy.sh && ./deploy.sh + script: cd /home/ilmo.kang03 && chmod +x deploy.sh && ./deploy.sh From ea30343cdb8632564c69cdd2cc61835cd937c15d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=9D=BC=EB=AA=A8?= <96767857+OneEpitome@users.noreply.github.com> Date: Mon, 10 Apr 2023 16:15:08 +0900 Subject: [PATCH 3/4] Create deploy.sh --- deploy.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 deploy.sh diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..f2d9e47 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +SERVER_HOME=$(pwd) +APPLICATION=real_coding_server-0.0.1-SNAPSHOT.jar + +if [ -f $SERVER_HOME/application.pid ];then + kill -9 $(cat $SERVER_HOME/application.pid) + rm $SERVER_HOME/application.pid +fi + +sleep 1s + +nohup java -jar $APPLICATION >> spring.out 2>&1 & echo $! > application.pid From e1eb1853af802e5af74ac26f33f9dab20b802e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=9D=BC=EB=AA=A8?= <96767857+OneEpitome@users.noreply.github.com> Date: Mon, 10 Apr 2023 16:35:05 +0900 Subject: [PATCH 4/4] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c63e21a..13ed553 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -73,4 +73,4 @@ jobs: host: ilmo.kang03 key: ${{ secrets.PRIVATE_KEY }} script_stop: true - script: cd /home/ilmo.kang03 && chmod +x deploy.sh && ./deploy.sh + script: cd /home/ilmo.kang03 && sudo chmod +x deploy.sh && sudo ./deploy.sh