Use GitHub Actions Cache for image cache

This commit is contained in:
BtbN 2021-11-13 17:11:15 +01:00
parent 4b7c1ac9f9
commit 482c7d7987

View file

@ -20,6 +20,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install buildx
uses: docker/setup-buildx-action@v1
with:
config: .github/buildkit.toml
- name: Login to Docker
uses: docker/login-action@v1
with:
@ -29,12 +33,17 @@ jobs:
- name: Image Name
id: imagename
run: echo "::set-output name=name::ghcr.io/${GITHUB_REPOSITORY,,}/base:latest"
- name: Build base image
run: |
T="$(echo -n ${{ github.token }} | sha256sum | head -c 64)" && echo -e "::add-mask::${T}\n::stop-commands::${T}"
docker build --pull --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from ${{ steps.imagename.outputs.name }} --tag ${{ steps.imagename.outputs.name }} images/base
- name: Push base image
run: docker push ${{ steps.imagename.outputs.name }}
- name: Stop Commands
run: T="$(echo -n ${{ github.token }} | sha256sum | head -c 64)" && echo -e "::add-mask::${T}\n::stop-commands::${T}"
- name: Build target base image
uses: docker/build-push-action@v2
with:
context: images/base
pull: true
push: true
tags: ${{ steps.imagename.outputs.name }}
cache-to: type=gha,mode=max
cache-from: type=gha
build_target_bases:
name: Build target base image
needs: build_base
@ -46,6 +55,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install buildx
uses: docker/setup-buildx-action@v1
with:
config: .github/buildkit.toml
- name: Login to Docker
uses: docker/login-action@v1
with:
@ -55,12 +68,17 @@ jobs:
- name: Image Name
id: imagename
run: echo "::set-output name=name::ghcr.io/${GITHUB_REPOSITORY,,}/base-${{ matrix.target }}:latest"
- name: Stop Commands
run: T="$(echo -n ${{ github.token }} | sha256sum | head -c 64)" && echo -e "::add-mask::${T}\n::stop-commands::${T}"
- name: Build target base image
run: |
T="$(echo -n ${{ github.token }} | sha256sum | head -c 64)" && echo -e "::add-mask::${T}\n::stop-commands::${T}"
docker build --pull --build-arg BUILDKIT_INLINE_CACHE=1 --build-arg GH_REPO=${GITHUB_REPOSITORY,,} --cache-from ${{ steps.imagename.outputs.name }} --tag ${{ steps.imagename.outputs.name }} images/base-${{ matrix.target }}
- name: Push target base image
run: docker push ${{ steps.imagename.outputs.name }}
uses: docker/build-push-action@v2
with:
context: images/base-${{ matrix.target }}
pull: true
push: true
tags: ${{ steps.imagename.outputs.name }}
cache-to: type=gha,mode=max
cache-from: type=gha
build_targets:
name: Build target-variant image
needs: build_target_bases
@ -77,30 +95,30 @@ jobs:
uses: docker/setup-buildx-action@v1
with:
config: .github/buildkit.toml
- name: Generate Dockerfile
run: ./generate.sh ${{ matrix.target }} ${{ matrix.variant }}
- name: Login to Docker
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Generate Dockerfile
run: ./generate.sh ${{ matrix.target }} ${{ matrix.variant }}
- name: Image Name
id: imagename
run: |
IMG="ghcr.io/${GITHUB_REPOSITORY,,}/${{ matrix.target }}-${{ matrix.variant }}"
echo "::set-output name=name::${IMG/ /-}:latest"
echo "::set-output name=cache_name::${IMG/ /-}:cache"
- name: Build variant image
run: |
T="$(echo -n ${{ github.token }} | sha256sum | head -c 64)" && echo -e "::add-mask::${T}\n::stop-commands::${T}"
docker buildx build \
--pull \
--tag ${{ steps.imagename.outputs.name }} \
--cache-to=type=registry,mode=max,ref=${{ steps.imagename.outputs.cache_name }} \
--cache-from=type=registry,ref=${{ steps.imagename.outputs.cache_name }} \
--output=type=image,push=true,name=${{ steps.imagename.outputs.name }} \
.
- name: Stop Commands
run: T="$(echo -n ${{ github.token }} | sha256sum | head -c 64)" && echo -e "::add-mask::${T}\n::stop-commands::${T}"
- name: Build target base image
uses: docker/build-push-action@v2
with:
context: .
pull: true
push: true
tags: ${{ steps.imagename.outputs.name }}
cache-to: type=gha,mode=max
cache-from: type=gha
build_ffmpeg:
name: Build ffmpeg
needs: build_targets