From 543d05bc9e7fd85135bdcf14474d5eba3a93c465 Mon Sep 17 00:00:00 2001 From: jiwonkim Date: Sun, 2 Feb 2025 19:05:42 +0900 Subject: [PATCH] =?UTF-8?q?feat=20#33=20:=20CD=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main-cd.yml | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/main-cd.yml diff --git a/.github/workflows/main-cd.yml b/.github/workflows/main-cd.yml new file mode 100644 index 0000000..c1cac26 --- /dev/null +++ b/.github/workflows/main-cd.yml @@ -0,0 +1,50 @@ +name: Backend CD (Deploy to AWS EC2) + +on: + push: + branches: + - main + +jobs: + deploy: + name: Deploy to AWS EC2 + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v3 + with: + java-version: '21' + distribution: 'temurin' + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build Project + run: ./gradlew build --stacktrace + + - name: Package JAR File + run: cp build/libs/*.jar app.jar + + - name: Deploy to AWS EC2 + uses: appleboy/scp-action@v0.1.4 + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USER }} + key: ${{ secrets.SSH_KEY }} + source: "app.jar" + target: "~/backend" + + - name: Restart Backend on EC2 + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USER }} + key: ${{ secrets.SSH_KEY }} + script: | + cd ~/backend + pkill -f 'java -jar' || true + nohup java -jar app.jar > log.txt 2>&1 & \ No newline at end of file