[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-04-21。"],[[["\u003cp\u003eBuildpacks cache images can be used to reuse results from previous builds, reducing the overall build time when using Google Cloud's buildpacks, including in ephemeral environments like Cloud Build.\u003c/p\u003e\n"],["\u003cp\u003eTo use cache images with Cloud Build, a build configuration file (e.g., \u003ccode\u003ecloudbuild.yaml\u003c/code\u003e) must be created to instruct the \u003ccode\u003epack\u003c/code\u003e CLI to publish a build image to a remote repository.\u003c/p\u003e\n"],["\u003cp\u003eThe initial build with the new configuration file creates and pushes the build image cache, and subsequent builds will benefit from the performance improvements provided by the cache.\u003c/p\u003e\n"],["\u003cp\u003eA build configuration file is a YAML file that defines a build step using the \u003ccode\u003epack\u003c/code\u003e CLI, and the provided example shows how to create a cache image and push it to a repository.\u003c/p\u003e\n"],["\u003cp\u003eTo run a build remotely, you must include the \u003ccode\u003e--config\u003c/code\u003e command flag and specify your build configuration file.\u003c/p\u003e\n"]]],[],null,["# Speed up builds with cache images\n\nYou can take advantage of buildpacks [cache images](https://buildpacks.io/docs/app-developer-guide/using-cache-image/) to reuse results from a previous build. This reduces the overall duration of time when you build images with Google Cloud's buildpacks, including when you build images in ephemeral environments such as Cloud Build.\n\n\u003cbr /\u003e\n\nThe following steps in this guide focus on remote builds with Cloud Build.\nFor local builds, refer to both the\n[cache image](https://buildpacks.io/docs/app-developer-guide/using-cache-image/)\ninstructions and\n[`pack` command reference](https://buildpacks.io/docs/tools/pack/cli/pack_build/)\npage.\n\nUsing cache images with Cloud Build\n-----------------------------------\n\nYou must create a\n[build configuration file](/build/docs/configuring-builds/create-basic-configuration),\nfor example `cloudbuild.yaml`, to enable buildpacks cache images in\nCloud Build. Your build configuration file instructs the `pack` CLI to\npublish a build image to a specified remote repository. This build image then\ngets used as your \"cache image\" for subsequent builds.\n\nNote that the first build that you run with your new build configuration file\nuses the `pack` command to create and then push the initial build image cache\nto your repository. Your build performance improvements are seen only after the\ninitial cache image is available to your builds.\n\nCreating a build configuration file\n-----------------------------------\n\nTo define a Cloud Build configuration file you must write a YAML\nfile with a build step that uses the `pack` CLI create your image.\n\nIn the following example `cloudbuild.yaml`, the build creates an image for your\napplication or function using buildpacks, creates the initial build\ncache image, and pushes it to a repository: \n\n```yaml\noptions:\n logging: CLOUD_LOGGING_ONLY\n pool: {}\nprojectId: PROJECT_ID\nsteps:\n- name: gcr.io/k8s-skaffold/pack\n entrypoint: pack\n args:\n - build\n - LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/IMAGE_NAME\n - --builder\n - gcr.io/buildpacks/builder:latest\n - --cache-image\n - LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/CACHE_IMAGE_NAME:latest\n - --publish \n```\n\nReplace:\n\n- `LOCATION` with the region name of your container repository. Example: `us-west2`\n- `PROJECT_ID` with the ID of your Google Cloud project.\n- `REPO_NAME` with the name of your Docker repository.\n- `IMAGE_NAME` with the name of your application or function container image.\n- `CACHE_IMAGE_NAME` with the name of your build cache image.\n\nAlso see the other supported aurgements that you can define in your build\nconfiguration file in the\n[`pack build` command reference](https://buildpacks.io/docs/tools/pack/cli/pack_build/).\n\nBuilding remotely with cache images\n-----------------------------------\n\nTo run a build, you include the `--config` command flag and specify your\nconfiguration file. For example, to use a file named `cloudbuild.yaml` you\nmight run: \n\n gcloud builds submit --config cloudbuild.yaml --pack image=example-docker.pkg.dev/my-project-id/repo/example-image\n\nFor more information about remote builds, see\n[Build an application](/docs/buildpacks/build-application#remote_builds) or\n[Build a function](/docs/buildpacks/build-function#remote_builds)."]]