From 482c7d79872cd32a576010669149a47c3d32c775 Mon Sep 17 00:00:00 2001 From: BtbN Date: Sat, 13 Nov 2021 17:11:15 +0100 Subject: [PATCH] Use GitHub Actions Cache for image cache --- .github/workflows/build.yml | 66 +++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index efed780..b6997d0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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