diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab9ea63..d738575 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,8 +18,26 @@ jobs: java-version: '21' cache: gradle + - name: Cache Gradle packages + 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: Cache Gradle Build + uses: actions/cache@v3 + with: + path: build + key: ${{ runner.os }}-gradle-build-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-gradle-build- + - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle - run: ./gradlew clean build + run: ./gradlew clean build --build-cache diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index ddb1362..dd54767 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -11,12 +11,40 @@ jobs: - name: Checkout code uses: actions/checkout@v4.1.7 + - name: Set up JDK 21 + uses: actions/setup-java@v4.2.2 + with: + distribution: 'temurin' + java-version: '21' + cache: gradle + + - name: Cache Gradle packages + 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: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log in to Docker Hub uses: docker/login-action@v3.3.0 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + - name: Build and Push Docker image if: github.ref == 'refs/heads/main' uses: docker/build-push-action@v6.7.0 @@ -26,11 +54,17 @@ jobs: push: true tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.PROD_IMAGE_NAME }}:latest platforms: linux/amd64 + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max + + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache deploy: runs-on: ubuntu-latest needs: build - steps: - name: SSH to Server and Deploy if: github.ref == 'refs/heads/main'