Skip to content

Commit

Permalink
ci: improve buildkit cache
Browse files Browse the repository at this point in the history
  • Loading branch information
yxtay committed Jan 30, 2024
1 parent da3ad77 commit 058c70e
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@ jobs:
GHCR_IMAGE_NAME: ghcr.io/${{ github.repository }}

steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: |
Dockerfile
poetry.lock
- name: Cache buildkit mounts
uses: actions/cache@v4
Expand All @@ -129,9 +133,10 @@ jobs:
var-cache-apt
root-cache-pip
root-cache-pypoetry
key: buildkit-mounts-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
key: buildkit-mounts-${{ runner.os }}-${{ hashFiles('**/Dockerfile', '**/poetry.lock') }}
restore-keys: |
buildkit-mounts-${{ runner.os }}
buildkit-mounts-${{ runner.os }}
- name: Inject var-cache-apt into docker
uses: reproducible-containers/buildkit-cache-dance@v2
Expand All @@ -151,6 +156,9 @@ jobs:
cache-source: root-cache-pypoetry
cache-target: /root/.cache/pypoetry

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build CI image
id: build-ci
env:
Expand All @@ -170,8 +178,7 @@ jobs:
id: docker_metadata
uses: docker/metadata-action@v5
with:
images: |
${{ env.GHCR_IMAGE_NAME }}
images: ${{ env.GHCR_IMAGE_NAME }}

- name: Login to GHCR
if: ${{ github.event_name != 'pull_request' }}
Expand All @@ -192,8 +199,7 @@ jobs:
${{ env.GHCR_IMAGE_NAME }}:dev
${{ env.GHCR_IMAGE_NAME }}:cache
cache-to: type=inline
tags: |
${{ env.GHCR_IMAGE_NAME }}:dev
tags: ${{ env.GHCR_IMAGE_NAME }}:dev
push: ${{ github.event_name != 'pull_request' }}

- name: Build and push prod image
Expand All @@ -205,8 +211,7 @@ jobs:
cache-from: |
${{ env.GHCR_IMAGE_NAME }}:dev
${{ env.GHCR_IMAGE_NAME }}:cache
cache-to: |
type=registry,ref=${{ env.GHCR_IMAGE_NAME }}:cache,mode=max
cache-to: type=registry,ref=${{ env.GHCR_IMAGE_NAME }}:cache,mode=max
tags: ${{ steps.docker_metadata.outputs.tags }}
labels: ${{ steps.docker_metadata.outputs.labels }}
annotations: ${{ steps.docker_metadata.outputs.annotations }}
Expand Down

0 comments on commit 058c70e

Please sign in to comment.