From 6b7fe5b5b8174c726993f6ed0853b20d7cea1a1b Mon Sep 17 00:00:00 2001 From: Ju Minji Date: Thu, 12 Oct 2023 22:43:36 +0900 Subject: [PATCH] =?UTF-8?q?chore=20:=20Github-Actions=20=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A6=BD=ED=8A=B8=20=EC=9E=91=EC=84=B1=20(#26)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 4Week_Mission/.github/workflows/gradle.yml | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 4Week_Mission/.github/workflows/gradle.yml diff --git a/4Week_Mission/.github/workflows/gradle.yml b/4Week_Mission/.github/workflows/gradle.yml new file mode 100644 index 0000000..3a66d59 --- /dev/null +++ b/4Week_Mission/.github/workflows/gradle.yml @@ -0,0 +1,65 @@ + + +# 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: Java CI with Gradle + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew build -x test + + - name: Docker build and push + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + + docker build -t spring-boot-app . + docker tag app ${{ secrets.DOCKER_USERNAME }}/spring-boot-app:latest + + docker push ${{ secrets.DOCKER_USERNAME }}/spring-boot-app:latest + + - name: Deploy (remote ssh commands using pwd) + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST }} + username: ec2-user + key: ${{ secrets.PRIVATE_KEY }} + # 도커 작업 + script: | + docker pull ${{ secrets.DOCKER_USERNAME }}/spring-boot-app:latest + + docker stop $(docker ps -a -q) + docker run -d --log-driver=syslog -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/spring-boot-app:latest + docker rm $(docker ps --filter 'status=exited' -a -q) + docker image prune -a -f + + docker-compose down + docker-compose up \ No newline at end of file