diff --git a/.github/workflows/cd_builder.yml b/.github/workflows/cd_builder.yml index 2732572..15ab43b 100644 --- a/.github/workflows/cd_builder.yml +++ b/.github/workflows/cd_builder.yml @@ -25,6 +25,7 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Log in to GitHub Container Registry + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} @@ -51,8 +52,14 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha,scope=cd-builder - cache-to: type=gha,mode=max,scope=cd-builder + cache-from: | + type=gha,scope=cd-builder-${{ github.head_ref || github.ref_name }} + type=registry,ref=ghcr.io/${{ github.repository }}:buildcache + type=gha,scope=cd-builder-develop + type=gha,scope=cd-builder-main + cache-to: | + type=gha,mode=max,scope=cd-builder-${{ github.head_ref || github.ref_name }} + ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop') && format('type=registry,ref=ghcr.io/{0}:buildcache,mode=max', github.repository) || '' }} - name: Generate artifact attestation uses: actions/attest-build-provenance@v3 diff --git a/.github/workflows/ci_docker-test.yml b/.github/workflows/ci_docker-test.yml index f48c894..d403655 100644 --- a/.github/workflows/ci_docker-test.yml +++ b/.github/workflows/ci_docker-test.yml @@ -15,6 +15,13 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Log in to GHCR (for registry cache) + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build Docker image with cache uses: docker/build-push-action@v6 with: @@ -23,8 +30,12 @@ jobs: push: false load: true tags: ghcr.io/${{ github.repository }}:latest - cache-from: type=gha,scope=docker-test - cache-to: type=gha,mode=max,scope=docker-test + cache-from: | + type=gha,scope=docker-test-${{ github.head_ref || github.ref_name }} + type=registry,ref=ghcr.io/${{ github.repository }}:buildcache + type=gha,scope=docker-test-develop + type=gha,scope=docker-test-main + cache-to: type=gha,mode=max,scope=docker-test-${{ github.head_ref || github.ref_name }} - name: Setup environment run: |