diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..13ed553 --- /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/ilmo.kang03" + 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/ilmo.kang03" + 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/ilmo.kang03 && sudo chmod +x deploy.sh && sudo ./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