Skip to content

Commit

Permalink
Use GitHub Actions Cache for image cache
Browse files Browse the repository at this point in the history
  • Loading branch information
BtbN committed Nov 13, 2021
1 parent 4b7c1ac commit 482c7d7
Showing 1 changed file with 42 additions and 24 deletions.
66 changes: 42 additions & 24 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 482c7d7

Please sign in to comment.