From 7f3c713524243f4f4e55bc8178108fe2a97da6c8 Mon Sep 17 00:00:00 2001 From: jjuuuunnii <129721531+jjuuuunnii@users.noreply.github.com> Date: Thu, 11 Jan 2024 03:16:14 +0900 Subject: [PATCH] Feat: Create gradle.yml --- .github/workflows/gradle.yml | 67 ++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/gradle.yml diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..dc39178 --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,67 @@ +# 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" ] + +jobs: + ci: + 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: make application.yml + run: | + cd ./src/main/resources + touch ./application.yml + echo "${{ secrets.PROPERTIES }}" > ./application.yml + shell: bash + + - name: Run chmod to make gradlew executable + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew build -x test # v2.6.0 + + - name: Docker build & push to hub + run: | + docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} + docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}:latest . + docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}:latest + + cd: + needs: [ci] + runs-on: ubuntu-latest + + steps: + - name: Docker Image Pull and Compose UP + uses: appleboy/ssh-action@v1.0.0 + with: + host: ${{ secrets.HOST }} + username : ${{ secrets.USERNAME }} + password : ${{ secrets.PASSWORD }} + port : 22 + script: | + sudo docker compose down + sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}:latest + docker compose up -d + docker image prune -f + + +