From 2d0f48ef1e0f0b8b3f1eb28aed386a1778f8cea6 Mon Sep 17 00:00:00 2001 From: eojinny <96863137+eojinny@users.noreply.github.com> Date: Mon, 30 Oct 2023 10:32:10 +0900 Subject: [PATCH] Create gradle.yml --- .github/workflows/gradle.yml | 63 ++++++++++++++++++++++++++++++++++++ 1 file changed, 63 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..0a496ac --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,63 @@ + name: Java CI with Gradle + + on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + + 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: Make application.yml + run: | + mkdir -p src/main/resources + echo "$APPLICATION" > src/main/resources/application.yml + env: + APPLICATION: ${{ secrets.APPLICATION }} + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew build -x test + + - name: Docker build + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -t app . + docker tag app ${{ secrets.DOCKER_USERNAME }}/community:latest + docker push ${{ secrets.DOCKER_USERNAME }}/community:latest + + - name: docker-compose.yml + uses: appleboy/scp-action@master + with: + username: ec2-user + host: ${{ secrets.HOST }} + key: ${{ secrets.PRIVATE_KEY }} + port: ${{ secrets.PORT }} + source: "./docker-compose.yml" + target: "/home/ec2-user/" + + - name: Deploy + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST }} + username: ec2-user + key: ${{ secrets.PRIVATE_KEY }} + script: | + docker pull ${{ secrets.DOCKER_USERNAME }}/community:latest + docker image prune -a -f +