From 74b1150a2346835d55c6eef983fbebb5f258df1e Mon Sep 17 00:00:00 2001 From: Lee Eun Seob <107783650+MinchoGreenT@users.noreply.github.com> Date: Fri, 20 Oct 2023 02:21:57 +0900 Subject: [PATCH] Create gradle.yml --- .github/workflows/gradle.yml | 91 ++++++++++++++++++++++++++++++++++++ 1 file changed, 91 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..ebd4d33 --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,91 @@ +# 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 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + - name: Copy application.yml + env: + OCCUPY_DEPLOY: ${{ secrets.OCCUPY_DEPLOY }} + OCCUPY_DEPLOY_DIR: src/main/resources + OCCUPY_DEPLOY_TEST_DIR: src/test/resources + OCCUPY_DEPLOY_DIR_FILE_NAME: application.yml + run: | + cd ./src/main + mkdir resources + cd ./resources + touch ./application.yml + echo "$OCCUPY_DEPLOY" > ./application.yml + + - name: Build with Gradle + uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0 + with: + arguments: clean build + + ## docker build & push to production + - name: Docker build & push to prod + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -f Dockerfile -t minchogt/fu-eureka . + docker push minchogt/fu-eureka + + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: cicdsample + path: build/libs/*.jar + + deploy: + needs: build + runs-on: ubuntu-latest + steps: + - name: Download artifact + uses: actions/download-artifact@v2 + with: + name: cicdsample + + - name: Setup SSH + uses: webfactory/ssh-agent@v0.5.4 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + + ## deploy to production + - name: Deploy to prod + uses: appleboy/ssh-action@master + id: deploy-prod + with: + host: ${{ secrets.SERVER_IP }} + username: ${{ secrets.SSH_USER }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + envs: GITHUB_SHA + script: | + sudo docker rm fu-eureka + sudo docker pull minchogt/fu-eureka + docker-compose up -d fu-eureka + docker image prune -f +