Make cache keys unique
This commit is contained in:
parent
2aaf0cc5ca
commit
74fcd115ee
1 changed files with 10 additions and 15 deletions
25
.github/workflows/flaskr-ci.yaml
vendored
25
.github/workflows/flaskr-ci.yaml
vendored
|
|
@ -35,14 +35,13 @@ jobs:
|
|||
# Required permission to push images with the built-in GITHUB_TOKEN
|
||||
packages: write
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
CACHE_KEY: flaskr-buildx-${{ github.ref_name }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Job vars and prep
|
||||
- name: Job vars
|
||||
# Use bash string manipulation to create vars
|
||||
# Note runner context isn't available in job.env, so use it here
|
||||
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#context-availability
|
||||
shell: bash
|
||||
run: |
|
||||
echo "SHA_SHORT=${GITHUB_SHA:0:10}" >> ${GITHUB_ENV}
|
||||
echo "REPO_LOWER_CASE=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
|
||||
|
|
@ -56,9 +55,9 @@ jobs:
|
|||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ env.CACHE_DIR }}
|
||||
key: ${{ env.CACHE_KEY }}
|
||||
key: buildx-flaskr-${{ github.sha }}
|
||||
restore-keys: |
|
||||
flaskr-buildx-main
|
||||
buildx-flaskr-
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
|
|
@ -73,16 +72,12 @@ jobs:
|
|||
tags: "ghcr.io/${{ env.REPO_LOWER_CASE }}:${{ env.SHA_SHORT }}"
|
||||
cache-from: type=local,src=${{ env.CACHE_DIR }}
|
||||
cache-to: type=local,dest=${{ env.NEW_CACHE_DIR }}
|
||||
# Only save the latest Docker build layers to the cache, otherwise
|
||||
# the cache will keep growing indefinitely, past the 10GB max
|
||||
# Only save the latest Docker build layers to new cache key, otherwise
|
||||
# new cache keys will keep getting bigger indefinitely
|
||||
# https://github.com/docker/build-push-action/issues/252
|
||||
# https://github.com/moby/buildkit/issues/1896
|
||||
# - name: Only persist the new cache layers
|
||||
# run: |
|
||||
# rm -rf ${CACHE_DIR}
|
||||
# mv ${NEW_CACHE_DIR} ${CACHE_DIR}
|
||||
# Thanks https://evilmartians.com/chronicles/build-images-on-github-actions-with-docker-layer-caching
|
||||
- name: Only persist the new cache layers
|
||||
uses: actions/cache/save@v3
|
||||
with:
|
||||
path: ${{ env.NEW_CACHE_DIR }}
|
||||
key: ${{ env.CACHE_KEY }}
|
||||
run: |
|
||||
rm -rf ${CACHE_DIR}
|
||||
mv ${NEW_CACHE_DIR} ${CACHE_DIR}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue