feat: replace registry cache with inline cache(s)

A simpler, leaner and more scalable approach to the cache.  Scopes the cache by architecture as well as branch.

PR: #56
This commit is contained in:
innovaker 2021-05-22 15:04:22 +01:00
parent 3a6b0f0d23
commit 0042254202

View File

@ -4,7 +4,6 @@ env:
zephyr-version: 2.4.0 zephyr-version: 2.4.0
zephyr-sdk-version: 0.11.4 zephyr-sdk-version: 0.11.4
run-unit-tests: ${{ secrets.RUN_UNIT_TESTS != null }} run-unit-tests: ${{ secrets.RUN_UNIT_TESTS != null }}
cache-repository-name: zmk-docker-cache
docker-hub-credentials: ${{ secrets.DOCKER_HUB_USERNAME != null && secrets.DOCKER_HUB_TOKEN != null }} docker-hub-credentials: ${{ secrets.DOCKER_HUB_USERNAME != null && secrets.DOCKER_HUB_TOKEN != null }}
ghcr-credentials: ${{ secrets.GHCR_USERNAME != null && secrets.GHCR_TOKEN != null }} ghcr-credentials: ${{ secrets.GHCR_USERNAME != null && secrets.GHCR_TOKEN != null }}
docker-hub-namespace: ${{ secrets.DOCKER_HUB_NAMESPACE || github.repository_owner }} docker-hub-namespace: ${{ secrets.DOCKER_HUB_NAMESPACE || github.repository_owner }}
@ -83,9 +82,9 @@ jobs:
max-parallel: 1 # takes advantage of caching between jobs max-parallel: 1 # takes advantage of caching between jobs
matrix: matrix:
architecture: ${{ fromJSON(needs.architectures.outputs.json) }} architecture: ${{ fromJSON(needs.architectures.outputs.json) }}
target: # ordered from biggest to smallest to take advantage of the registry cache target: # ordered from smallest to biggest to take advantage of the inline cache
- dev
- build - build
- dev
include: include:
- architecture: arm - architecture: arm
board: nice_nano board: nice_nano
@ -106,10 +105,13 @@ jobs:
registry: ghcr.io registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }} username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_TOKEN }} password: ${{ secrets.GHCR_TOKEN }}
- name: Define repository - name: Define repositories
id: repository id: repositories
shell: bash shell: bash
run: echo ::set-output name=name::zmk-${{ matrix.target }}-${{ matrix.architecture }} run: |
echo ::set-output name=build::zmk-build-${{ matrix.architecture }}
echo ::set-output name=dev::zmk-dev-${{ matrix.architecture }}
echo ::set-output name=target::zmk-${{ matrix.target }}-${{ matrix.architecture }}
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v1 uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx - name: Set up Docker Buildx
@ -127,13 +129,16 @@ jobs:
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }} org.opencontainers.image.revision=${{ github.sha }}
tags: | tags: |
docker.io/${{ env.docker-hub-namespace }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.candidate }} docker.io/${{ env.docker-hub-namespace }}/${{ steps.repositories.outputs.target }}:${{ needs.tags.outputs.candidate }}
cache-from: type=registry,ref=docker.io/${{ env.docker-hub-namespace }}/${{ env.cache-repository-name }}:${{ needs.tags.outputs.branch }} docker.io/${{ env.docker-hub-namespace }}/${{ steps.repositories.outputs.target }}:${{ needs.tags.outputs.branch }}
cache-to: ${{ (steps.docker-hub-login.outcome == 'success') && (matrix.target == 'dev') && format('type=registry,ref=docker.io/{0}/{1}:{2},mode=max', env.docker-hub-namespace, env.cache-repository-name, needs.tags.outputs.branch) || null }} cache-from: |
type=registry,ref=docker.io/${{ env.docker-hub-namespace }}/${{ steps.repositories.outputs.build }}:${{ needs.tags.outputs.branch }}
type=registry,ref=docker.io/${{ env.docker-hub-namespace }}/${{ steps.repositories.outputs.dev }}:${{ needs.tags.outputs.branch }}
cache-to: type=inline
load: true load: true
- name: Create and run container from candidate image - name: Create and run container from candidate image
shell: bash shell: bash
run: docker run -d -it --name candidate ${{ env.docker-args }} docker.io/${{ env.docker-hub-namespace }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.candidate }} run: docker run -d -it --name candidate ${{ env.docker-args }} docker.io/${{ env.docker-hub-namespace }}/${{ steps.repositories.outputs.target }}:${{ needs.tags.outputs.candidate }}
- name: Checkout ZMK - name: Checkout ZMK
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
@ -220,7 +225,8 @@ jobs:
if: ${{ steps.docker-hub-login.outcome == 'success' }} if: ${{ steps.docker-hub-login.outcome == 'success' }}
shell: bash shell: bash
run: | run: |
docker image push docker.io/${{ env.docker-hub-namespace }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.candidate }} docker image push docker.io/${{ env.docker-hub-namespace }}/${{ steps.repositories.outputs.target }}:${{ needs.tags.outputs.candidate }}
docker image push docker.io/${{ env.docker-hub-namespace }}/${{ steps.repositories.outputs.target }}:${{ needs.tags.outputs.branch }}
releases: releases:
needs: needs:
- architectures - architectures