From 0522e1e9f8e7479ceb0279f8e912b61b8aabb84b Mon Sep 17 00:00:00 2001 From: yuntasha <97961558+yuntasha@users.noreply.github.com> Date: Fri, 6 Oct 2023 13:24:54 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B0=9C=EB=B0=9C=EC=9A=A9=20CICD?= =?UTF-8?q?=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit develop브랜치를 업데이트할때 개발용 서버에 자동으로 적용됩니다 --- .github/workflows/gradle.yml | 79 ++++++++++++++++++++++++++++++++++++ 1 file changed, 79 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..7450875 --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,79 @@ +# 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: + - develop + pull_request: + branches: + - develop +permissions: + contents: read + +jobs: + CI-CD: + runs-on: ubuntu-latest + steps: + + ## jdk setting + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' # https://github.com/actions/setup-java + + ## gradle caching + - name: Gradle Caching + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.yml') }} + restore-keys: | + ${{ runner.os }}-gradle- + + + ## create application-dev.yml + - name: make application-dev.yml + if: contains(github.ref, 'develop') + run: | + cd ./src/main/resources + touch ./application-dev.yml + echo "${{ secrets.YML_DEV }}" > ./application-dev.yml + shell: bash + + ## gradle build + - name: Build with Gradle + run: ./gradlew build -x test + + ## docker build & push to develop + - name: Docker build & push to dev + if: contains(github.ref, 'develop') + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -f Dockerfile-dev -t ${{ secrets.DOCKER_REPO }}/fairytale-dev . + docker push ${{ secrets.DOCKER_REPO }}/fairytale-dev + + ## deploy to develop + - name: Deploy to dev + uses: appleboy/ssh-action@master + id: deploy-dev + if: contains(github.ref, 'develop') + with: + host: ${{ secrets.HOST_DEV }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.PRIVATE_KEY }} + port: 22 + script: | + sudo docker rm -f $(docker ps -qa) + sudo docker pull ${{ secrets.DOCKER_REPO }}/fairytale-dev + docker run -itd -p 8080:8080 ${{ secrets.DOCKER_REPO }}/fairytale-dev