Fix cache save
This commit is contained in:
parent
6703438c62
commit
d32b6cfcf6
1 changed files with 13 additions and 12 deletions
25
.github/workflows/flaskr-ci.yaml
vendored
25
.github/workflows/flaskr-ci.yaml
vendored
|
|
@ -35,6 +35,8 @@ jobs:
|
||||||
# Required permission to push images with the built-in GITHUB_TOKEN
|
# Required permission to push images with the built-in GITHUB_TOKEN
|
||||||
packages: write
|
packages: write
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
CACHE_KEY: flaskr-buildx-${{ github.ref_name }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Job vars and prep
|
- name: Job vars and prep
|
||||||
|
|
@ -44,18 +46,17 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
echo "SHA_SHORT=${GITHUB_SHA:0:10}" >> ${GITHUB_ENV}
|
echo "SHA_SHORT=${GITHUB_SHA:0:10}" >> ${GITHUB_ENV}
|
||||||
echo "REPO_LOWER_CASE=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
|
echo "REPO_LOWER_CASE=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
|
||||||
CACHE="${{ runner.temp }}/.buildx-cache"
|
CACHE_DIR="${{ runner.temp }}/.buildx-cache"
|
||||||
echo "CACHE=${CACHE}" >> ${GITHUB_ENV}
|
echo "CACHE_DIR=${CACHE_DIR}" >> ${GITHUB_ENV}
|
||||||
echo "NEW_CACHE=${CACHE}-new" >> ${GITHUB_ENV}
|
echo "NEW_CACHE_DIR=${CACHE_DIR}-new" >> ${GITHUB_ENV}
|
||||||
mkdir -p ${CACHE}
|
|
||||||
- name: Setup Docker Buildx
|
- name: Setup Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v1
|
||||||
- name: Setup cache for Docker Buildx
|
- name: Setup cache for Docker Buildx
|
||||||
id: setup-cache
|
id: setup-cache
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v2
|
||||||
with:
|
with:
|
||||||
path: ${{ env.CACHE }}
|
path: ${{ env.CACHE_DIR }}
|
||||||
key: flaskr-buildx-${{ github.ref_name }}
|
key: ${{ env.CACHE_KEY }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
flaskr-buildx-main
|
flaskr-buildx-main
|
||||||
- name: Login to GitHub Container Registry
|
- name: Login to GitHub Container Registry
|
||||||
|
|
@ -70,18 +71,18 @@ jobs:
|
||||||
context: examples/tutorial
|
context: examples/tutorial
|
||||||
push: true
|
push: true
|
||||||
tags: "ghcr.io/${{ env.REPO_LOWER_CASE }}:${{ env.SHA_SHORT }}"
|
tags: "ghcr.io/${{ env.REPO_LOWER_CASE }}:${{ env.SHA_SHORT }}"
|
||||||
cache-from: type=local,src=${{ env.CACHE }}
|
cache-from: type=local,src=${{ env.CACHE_DIR }}
|
||||||
cache-to: type=local,dest=${{ env.NEW_CACHE }}
|
cache-to: type=local,dest=${{ env.NEW_CACHE_DIR }}
|
||||||
# Only save the latest Docker build layers to the cache, otherwise
|
# Only save the latest Docker build layers to the cache, otherwise
|
||||||
# the cache will keep growing indefinitely, past the 10GB max
|
# the cache will keep growing indefinitely, past the 10GB max
|
||||||
# https://github.com/docker/build-push-action/issues/252
|
# https://github.com/docker/build-push-action/issues/252
|
||||||
# https://github.com/moby/buildkit/issues/1896
|
# https://github.com/moby/buildkit/issues/1896
|
||||||
# - name: Only persist the new cache layers
|
# - name: Only persist the new cache layers
|
||||||
# run: |
|
# run: |
|
||||||
# rm -rf ${CACHE}
|
# rm -rf ${CACHE_DIR}
|
||||||
# mv ${NEW_CACHE} ${CACHE}
|
# mv ${NEW_CACHE_DIR} ${CACHE_DIR}
|
||||||
- name: Only persist the new cache layers
|
- name: Only persist the new cache layers
|
||||||
uses: actions/cache/save@v3
|
uses: actions/cache/save@v3
|
||||||
with:
|
with:
|
||||||
path: ${{ env.NEW_CACHE }}
|
path: ${{ env.NEW_CACHE_DIR }}
|
||||||
key: ${{ steps.setup-cache.outputs.cache-primary-key }}
|
key: key: ${{ env.CACHE_KEY }}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue