Correctly setup cache to be able to make use of different restore keys (#11248)

Motivation:

We should setup the caching so it will be able to use different restore keys and so almost never need to start from scratch

Modifications:

Adjust caching config to make use of different restore keys for maven caching but also docker caching

Result:

Better cache usage
This commit is contained in:
Norman Maurer 2021-05-12 11:41:03 +02:00 committed by GitHub
parent d984d4422c
commit c83601167f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 16 deletions

View File

@ -29,17 +29,19 @@ jobs:
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
key: ${{ runner.os }}-maven-${{ matrix.setup }}-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-${{ matrix.setup }}-
${{ runner.os }}-maven-
# Enable caching of Docker layers
- uses: satackey/action-docker-layer-caching@v0.0.11
continue-on-error: true
with:
key: build-${{ matrix.setup }}-docker-cache-{hash}
key: build-docker-cache-${{ matrix.setup }}-{hash}
restore-keys: |
build-${{ matrix.setup }}-docker-cache-
build-docker-cache-${{ matrix.setup }}-
build-docker-cache-
- name: Build docker image
run: docker-compose ${{ matrix.docker-compose-build }}

View File

@ -32,8 +32,9 @@ jobs:
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
key: ${{ runner.os }}-maven-${{ matrix.setup }}-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-${{ matrix.setup }}-
${{ runner.os }}-maven-
# Enable caching of Docker layers
@ -79,8 +80,9 @@ jobs:
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
key: ${{ runner.os }}-maven-deploy-staged-snapshots-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-deploy-staged-snapshots-
${{ runner.os }}-maven-
# Setup some env to re-use later.

View File

@ -21,8 +21,9 @@ jobs:
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
key: ${{ runner.os }}-maven-verify-pr-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-verify-pr-
${{ runner.os }}-maven-
- name: Verify with Maven
run: mvn verify -B --file pom.xml -Pci -DskipTests=true
@ -40,8 +41,9 @@ jobs:
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
key: ${{ runner.os }}-maven-build-pr-aarch64-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-build-pr-aarch64-
${{ runner.os }}-maven-
- uses: uraimo/run-on-arch-action@v2.0.9
@ -99,17 +101,19 @@ jobs:
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
key: ${{ runner.os }}-maven-${{ matrix.setup }}-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-${{ matrix.setup }}-
${{ runner.os }}-maven-
# Enable caching of Docker layers
- uses: satackey/action-docker-layer-caching@v0.0.11
continue-on-error: true
with:
key: build-${{ matrix.setup }}-docker-cache-{hash}
key: build-docker-cache-${{ matrix.setup }}-{hash}
restore-keys: |
build-${{ matrix.setup }}-docker-cache-
build-docker-cache-${{ matrix.setup }}-
build-docker-cache-
- name: Build docker image
run: docker-compose ${{ matrix.docker-compose-build }}

View File

@ -34,8 +34,9 @@ jobs:
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
key: ${{ runner.os }}-maven-prepare-release-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-prepare-release-
${{ runner.os }}-maven-
- name: Prepare release with Maven
@ -95,13 +96,12 @@ jobs:
# Enable caching of Docker layers
- uses: satackey/action-docker-layer-caching@v0.0.11
env:
docker-cache-name: staging-${{ matrix.setup }}-cache-docker
continue-on-error: true
with:
key: ${{ runner.os }}-staging-${{ env.docker-cache-name }}-{hash}
key: ${{ runner.os }}-staging-docker-cache-${{ matrix.setup }}-{hash}
restore-keys: |
${{ runner.os }}-staging-${{ env.docker-cache-name }}-
${{ runner.os }}-staging-docker-cache-${{ matrix.setup }}-
${{ runner.os }}-staging-docker-cache-
- uses: s4u/maven-settings-action@v2.2.0
with:
@ -112,6 +112,16 @@ jobs:
"password": "${{ secrets.SONATYPE_PASSWORD }}"
}]
# Cache .m2/repository
- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ matrix.setup }-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-${{ matrix.setup }-
${{ runner.os }}-maven-
- name: Create local staging directory
run: mkdir -p ~/local-staging
@ -196,6 +206,16 @@ jobs:
"password": "${{ secrets.SONATYPE_PASSWORD }}"
}]
# Cache .m2/repository
- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-deploy-staged-release-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-deploy-staged-release-
${{ runner.os }}-maven-
- name: Deploy local staged artifacts
working-directory: ./prepare-release-workspace/
# If we don't want to close the repository we can add -DskipStagingRepositoryClose=true

View File

@ -41,8 +41,9 @@ jobs:
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
key: ${{ runner.os }}-maven-${{ matrix.language }} ${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-${{ matrix.language }}
${{ runner.os }}-maven-
# If this run was triggered by a pull request event, then checkout