{"id":18772546,"url":"https://github.com/urcomputeringpal/cloudbuild-branch-based-caching","last_synced_at":"2025-10-25T14:35:33.582Z","repository":{"id":97879946,"uuid":"146595388","full_name":"urcomputeringpal/cloudbuild-branch-based-caching","owner":"urcomputeringpal","description":"A Google Cloud Build configuration file that you can drop into your repository to speed up Docker builds by leveraging Google Container Registry as a remote build cache","archived":false,"fork":false,"pushed_at":"2018-09-17T17:53:31.000Z","size":17,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-29T08:20:28.715Z","etag":null,"topics":["build","cloud-build","docker","google-cloud-platform","google-containers"],"latest_commit_sha":null,"homepage":"","language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/urcomputeringpal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-29T12:18:32.000Z","updated_at":"2021-10-16T09:54:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"43e0cd16-be91-45a4-bac8-1e474b34e595","html_url":"https://github.com/urcomputeringpal/cloudbuild-branch-based-caching","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/urcomputeringpal%2Fcloudbuild-branch-based-caching","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/urcomputeringpal%2Fcloudbuild-branch-based-caching/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/urcomputeringpal%2Fcloudbuild-branch-based-caching/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/urcomputeringpal%2Fcloudbuild-branch-based-caching/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/urcomputeringpal","download_url":"https://codeload.github.com/urcomputeringpal/cloudbuild-branch-based-caching/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239681018,"owners_count":19679508,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["build","cloud-build","docker","google-cloud-platform","google-containers"],"created_at":"2024-11-07T19:29:28.124Z","updated_at":"2025-10-25T14:35:28.564Z","avatar_url":"https://github.com/urcomputeringpal.png","language":"Dockerfile","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cloud Build branch-based caching\n\nThis repository contains a [Google Cloud Build](https://github.com/apps/google-cloud-build) configuration file ([`cloudbuild.yaml`](./cloudbuild.yaml)) that you can drop into your repository to speed up Docker builds by leveraging Google Container Registry as a remote build cache.\n\n### How it works\n\nDocker's local experience includes a delightful \"incremental build\" feature, wherein a well-crafted Dockerfile doesn't have to be rebuilt from scratch each time if only certain parts of a repository change. To accomplsih this, Docker uses the layers from images you've previously built as a \"build cache\" that it refers to in the course performing builds. You may recall seeing something like this the output of `docker build` commands:\n\n```\nStep 4/6 : RUN apk update \u0026\u0026 apk add ca-certificates \u0026\u0026 rm -rf /var/cache/apk/*\n---\u003e Using cache\n---\u003e 6f6ccb9df263\n```\n\nThe `Using cache` line means that Docker has found a layer in its cache that it can re-use instead of performing that operation. From Docker's [docs](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#leverage-build-cache) on this topic:\n\n\u003e When building an image, Docker steps through the instructions in your Dockerfile, executing each in the order specified. As each instruction is examined, Docker looks for an existing image in its cache that it can reuse, rather than creating a new (duplicate) image.\n\nThat's rad!\n\n#### How this config uses GCR as a remote build cache\n\nOn each push to a branch:\n\n1. Cloud Build will pull images tagged with `master` and `$BRANCH` from your GCP Project's Container Registry, ignoring failures.\n1. Cloud Build will attempt to build an image using the `Dockerfile` in your repository, passing the names of the images from step one to the `--cache-from` argument on `docker build`. Layers from these images are reused if possible rather than executing the `RUN`, `ADD`, or `COPY` command in your Dockerfile.\n1. Cloud Build pushes the image built in step two to GCR, tagged with `$BRANCH` so that subsequent pushes can re-use it in step one.\n\nHere are some example PRs that show how it works in practice!\n\n* [#2](https://github.com/urcomputeringpal/cloudbuild-branch-based-caching/pull/2) updates [`run.sh`](./run.sh), a file used in at the very end of our [`Dockerfile`](./Dockerfile). Much of the build is cached as a result.\n* [#3](https://github.com/urcomputeringpal/cloudbuild-branch-based-caching/pull/2) updates [`README.md`](./README.md), a file used early on in our [`Dockerfile`](./Dockerfile). All steps after the one involving the readme are invalidated, resulting in most of the build steps being executed again.\n* [#3 (comment)](https://github.com/urcomputeringpal/cloudbuild-branch-based-caching/pull/3#issuecomment-416950408) demonstrates how a subsequent change made on the branch for [#3](https://github.com/urcomputeringpal/cloudbuild-branch-based-caching/pull/2) uses a branch-specific image for its build cache to avoid re-evaluating the steps that differ between it and `master` each time.\n\n## TODO\n\n- GC state images?\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Furcomputeringpal%2Fcloudbuild-branch-based-caching","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Furcomputeringpal%2Fcloudbuild-branch-based-caching","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Furcomputeringpal%2Fcloudbuild-branch-based-caching/lists"}