Use a specific builder

Builders are versioned images that contain all the components necessary to create a runnable container. Each builder uses a specific OS distribution as the base image, like Ubuntu 22, and supports multiple programming language versions.

You might need to customize the version of builder if you require:

  • A OS-specific dependency that is available only in a specific builder version.
  • A specific version of programing language that is available only in a specific builder version.

Local builds

For local builds, you must have the Pack CLI and Docker installed.

Before you begin

  1. Install Docker Community Edition (CE) on your workstation. Docker is used by pack as an OCI image builder.
  2. Install Pack CLI.
  3. Install the Git source control tool to fetch the sample application from GitHub.

Specifying the builder version with pack

You can append the --builder flag to the pack command to specify the version of builder you want to use:

pack build SERVICE_IMAGE_NAME --builder=BUILDER_IMAGE_URL

Replace:

  • BUILDER_IMAGE_URL with the URL of the builder. Example: gcr.io/buildpacks/builder:google-22
  • SERVICE_IMAGE_NAME with the name that you choose for your application image.

To learn more about the pack command, see the CLI documentation

Specifying the builder version with project.toml

You can use a buildpacks project descriptor (project.toml) to set the builder when building with pack

  1. In your application root directory, create a file named project.toml with the following configuration:
    [build]
    builder = "BUILDER_IMAGE_URL"
  2. Build your application by running the `pack` command:
    pack build SERVICE_IMAGE_NAME

Replace:

  • BUILDER_IMAGE_URL with the URL of the builder, for example, gcr.io/buildpacks/builder:google-22
  • SERVICE_IMAGE_NAME with the name that you choose for your application image.

Remote builds

You can use a specific builder with Cloud Build by appending the --pack flag when submitting your project.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Cloud Build and Artifact Registry APIs.

    Enable the APIs

  5. Install the Google Cloud CLI.
  6. To initialize the gcloud CLI, run the following command:

    gcloud init
  7. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  8. Make sure that billing is enabled for your Google Cloud project.

  9. Enable the Cloud Build and Artifact Registry APIs.

    Enable the APIs

  10. Install the Google Cloud CLI.
  11. To initialize the gcloud CLI, run the following command:

    gcloud init
  12. Ensure that your Google Cloud project has access to a container image repository.

    To configure access to a Docker repository in Artifact Registry:

    1. Create a new Docker repository in the same location of your Google Cloud project.
      gcloud artifacts repositories create REPO_NAME \
      --repository-format=docker \
      --location=REGION --description="DESCRIPTION"
      Replace:
      • REPO_NAME with the name that you choose for your Docker repository.
      • REGION with the location in or nearest to the location of your Google Cloud project.
      • DESCRIPTION with a description of your choice.

      For example, to create a docker repository in us-west2 with the description "Docker repository", you run:

      gcloud artifacts repositories create buildpacks-docker-repo --repository-format=docker \
      --location=us-west2 --description="Docker repository"
    2. Verify that your repository was created:
      gcloud artifacts repositories list

      You should see name that you choose for your Docker repository in the list.

Build the application using a specific builder

  1. Use gcloud to submit the application source code to Cloud Build:
    gcloud builds submit --pack builder=BUILDER_IMAGE_URL,image=LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/SERVICE_IMAGE_NAME

    Replace:

    • BUILDER_IMAGE_URL with the url of the builder. Example: gcr.io/buildpacks/builder:google-22
    • LOCATION with the region name of your container repository. Example: us-west2-docker.pkg.dev
    • PROJECT_ID with the ID of your Google Cloud project.
    • REPO_NAME with the name of your Docker repository.
    • SERVICE_IMAGE_NAME with the name of your container image that you created.

    To learn more about the submit command, see the Cloud Build documentation.

  2. Verify that the sample application was successfully published to REPO_NAME:
    gcloud artifacts docker images list LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME

    Replace:

    • LOCATION with the region name of your container repository. Example: us-west2-docker.pkg.dev
    • PROJECT_ID with the ID of your Google Cloud project.
    • REPO_NAME with the name of your Docker repository.

Deploy from Source with Cloud Run

You can use a buildpacks project descriptor file e.g. project.toml to set the builder when deploying from source with Cloud Run

  1. Initialize a project.toml file at the root of your application directory and paste the following configuration into it:
    [build]
    builder = "BUILDER_IMAGE_URL"
  2. Deploy your application from source
    gcloud run deploy --source . SERVICE_IMAGE_NAME

Replace:

  • BUILDER_IMAGE_URL with the URL of the builder. Example: gcr.io/buildpacks/builder:google-22
  • SERVICE_IMAGE_NAME with the name of your container image that you created.