From 544195730208fc5f7357984b74117a53a1635e0b Mon Sep 17 00:00:00 2001 From: JIMIN HWANG Date: Fri, 2 Aug 2024 17:09:40 +0900 Subject: [PATCH] =?UTF-8?q?Chore:=20gradle.yml=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/gradle.yml | 85 ++++++++++++++++++++++++++++++++++++ 1 file changed, 85 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..43b4130 --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,85 @@ +# github repository Actions 페이지에 나타낼 이름 +name: ACC-hotsix CI/CD + +# event trigger +on: + push: + branches: [ "develop" ] + pull_request: + branches: [ "develop" ] + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-22.04 + steps: + ## jdk setting + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + 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.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: Grant execute permission for gradlew + run: + chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew build -x test + shell: bash + + ## create application-prod.yml + - name: create application-prod.yml + if: contains(github.ref, 'main') + run: | + cd ./src/main + mkdir resources + cd ./resources + touch ./application.yml + ls * + echo "${{ secrets.PROPERTIES_PROD }}" > ./application.yml + shell: bash + + - name: Build With Gradle + if: contains(github.ref, 'main') + run: ./gradlew build -x test + + ## docker build & push to production + - name: Docker build & push to prod + if: contains(github.ref, 'main') + run: | + echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin + docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }} . + docker push ${{ secrets.DOCKER_REPO }} + + + ## deploy to production + - name: Deploy to prod + uses: appleboy/ssh-action@v0.1.6 + id: deploy-prod + if: contains(github.ref, 'main') + with: + host: ${{ secrets.EC2_HOST_PROD }} + username: ${{ secrets.EC2_USERNAME }} + key: ${{ secrets.EC2_PRIVATE_KEY }} + port: 22 + envs: GITHUB_SHA + script: | + echo test1234 > test.txt + sudo docker rm -f $(docker ps -qa) + sudo docker pull ${{ secrets.DOCKER_REPO }} + docker-compose up -d + docker image prune -f