Skip to content

Commit

Permalink
fix(build): avoid docker cache contamination and invalidation (#4254)
Browse files Browse the repository at this point in the history
* imp(build): reduce docker cache invalidation

Use scoped caching and more file ignores to reduce cache invalidation

* fix(build): add entrypoint.sh as a required file

* fix(build): do not logout if the build takes too long

* Add 'doc comment' about .dockerignore

Co-authored-by: Deirdre Connolly <durumcrustulum@gmail.com>
  • Loading branch information
gustavovalverde and dconnolly authored May 3, 2022
1 parent 93f40fd commit 8b68651
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
29 changes: 23 additions & 6 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
target
Dockerfile
.dockerignore
.git
.github
.gitignore
# Before the docker CLI sends the context to the docker daemon, it looks for a file
# named .dockerignore in the root directory of the context. If this file exists, the
# CLI modifies the context to exclude files and directories that match patterns in it.
#
# You may want to specify which files to include in the context, rather than which
# to exclude. To achieve this, specify * as the first pattern, followed by one or
# more ! exception patterns.
#
# https://docs.docker.com/engine/reference/builder/#dockerignore-file

# Exclude everything:
#
*

# Now un-exclude required files and folders:
#
!.cargo
!*.toml
!*.lock
!tower-*
!zebra-*
!zebrad
!docker/entrypoint.sh
6 changes: 4 additions & 2 deletions .github/workflows/docker-image-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ jobs:
registry: us-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
logout: false

- name: Login to Google Container Registry
uses: docker/login-action@v1.14.1
with:
registry: gcr.io
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
logout: false

# Build and push image to Google Artifact Registry
- name: Build & push
Expand All @@ -121,5 +123,5 @@ jobs:
CHECKPOINT_SYNC=${{ inputs.checkpoint_sync }}
RUST_LOG=${{ inputs.rust_log }}
push: true
cache-from: type=registry,ref=us-docker.pkg.dev/zealous-zebra/zebra/${{ inputs.image_name }}:${{ env.GITHUB_REF_SLUG_URL }}-buildcache
cache-to: type=registry,ref=us-docker.pkg.dev/zealous-zebra/zebra/${{ inputs.image_name }}:${{ env.GITHUB_REF_SLUG_URL }}-buildcache,mode=max
cache-from: type=gha,scope=${{ inputs.image_name }}
cache-to: type=gha,mode=max,scope=${{ inputs.image_name }}

0 comments on commit 8b68651

Please sign in to comment.