Como usar builders de contribuições da comunidade e builders personalizados
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Nesta página, explicamos como usar builders de contribuições da comunidade e builders personalizados no Cloud Build. A
comunidade de desenvolvedores do Cloud Build fornece builders
de código aberto
que podem ser usados para executar tarefas. Se a tarefa que você quer executar requer
recursos que não são fornecidos por uma imagem existente, você pode criar sua própria
imagem personalizada e usá-la em uma etapa de versão. Para saber mais sobre os diferentes tipos de
builders, consulte Cloud Builders.
Imagens pré-criadas não estão disponíveis para builders de contribuições da comunidade. Para usar
esses builders em um arquivo de configuração do Cloud Build, primeiro é preciso
criar a imagem e enviá-la para o Artifact Registry no
projeto.
Para usar um builder de contribuições da comunidade:
Alguns exemplos de quando é possível usar uma imagem de builder personalizado são:
Fazer o download de código-fonte ou pacotes de locais externos.
Usar uma cadeia de ferramentas externa.
Armazenar as bibliotecas necessárias em cache.
Pré-criar o código-fonte (com o Cloud Build responsável apenas por
empacotar a versão em uma imagem).
Como qualquer outro, um builder personalizado é executado com o código-fonte ativado em
/workspace e com um diretório de trabalho em /workspace. Todos os arquivos deixados
em /workspace por uma determinada etapa de versão estão disponíveis para outras etapas de versão.
O builder personalizado pode enviar ou extrair de um repositório no
Artifact Registry (hospedado em gcr.io/$PROJECT-NAME/)
para que sua conta de serviço de build tem acesso.
As etapas a seguir mostram como criar e usar um builder personalizado com um exemplo de
Dockerfile:
Crie uma imagem de builder personalizada:
Crie o Dockerfile para o builder personalizado. O código a seguir
mostra um exemplo de Dockerfile:
FROMalpineRUNapkaddcurlCMDcurlhttps://httpbin.org/ip -s > myip.txt; echo "*** My IP is: $(cat myip.txt)"
Crie e envie o builder personalizado para o Artifact Registry no seu projeto,
substituindo os valores de project-id e image-name:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-01 UTC."],[[["\u003cp\u003eCloud Build allows the use of community-contributed builders, which are open-source tools provided by the developer community, after building and pushing them to Container Registry.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize a community-contributed builder, clone the \u003ccode\u003ecloud-builders-community\u003c/code\u003e repository, navigate to the desired builder's directory, submit it using \u003ccode\u003egcloud builds submit\u003c/code\u003e, and then reference it in your Cloud Build config file.\u003c/p\u003e\n"],["\u003cp\u003eCustom builders can be created and used when existing builders do not meet specific task requirements, such as downloading external code, using external toolchains, or pre-building source code.\u003c/p\u003e\n"],["\u003cp\u003eCreating a custom builder involves defining a \u003ccode\u003eDockerfile\u003c/code\u003e, building and pushing it to Container Registry, and then specifying the image in the \u003ccode\u003ename\u003c/code\u003e field of a Cloud Build step.\u003c/p\u003e\n"],["\u003cp\u003eContainer Registry, which is used to store the builders, is scheduled for shutdown on March 18, 2025 and organizations which have not used it prior to January 8, 2024 will have new repositories hosted on Artifact Registry by default.\u003c/p\u003e\n"]]],[],null,["# Using community-contributed builders and custom builders\n\nThis page explains how to use [community-contributed builders](https://github.com/GoogleCloudPlatform/cloud-builders-community) and custom builders in Cloud Build. The\nCloud Build developer community provides [open-source\nbuilders](https://github.com/GoogleCloudPlatform/cloud-builders-community)\nthat you can use to execute your tasks. If the task you want to perform requires\ncapabilities that are not provided by an existing image, you can build your own\ncustom image and use it in a build step. To learn about the different types of\nbuilders, see [Cloud Builders](/build/docs/cloud-builders).\n\nIf you're new to Cloud Build, read the [quickstarts](/build/docs/quickstarts)\nand the [Build configuration overview](/build/docs/build-config) first.\n\nUsing community-contributed builders\n------------------------------------\n\nPrebuilt images are not available for community-contributed builders; to use\nthese builders in a Cloud Build config file, you must first build the\nimage and push it to [Artifact Registry](/artifact-registry/docs/overview) in\nyour project.\n\nTo use a community-contributed builder:\n\n1. Build and push the builder:\n\n 1. Navigate to your project root directory.\n\n 2. Clone the [cloud-builders-community](https://github.com/GoogleCloudPlatform/cloud-builders-community) repository:\n\n git clone https://github.com/GoogleCloudPlatform/cloud-builders-community.git\n\n 3. Navigate to the builder image you want to use, where \u003cvar translate=\"no\"\u003ebuilder-name\u003c/var\u003e\n is the directory that contains the builder:\n\n cd cloud-builders-community/\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003ebuilder\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003ename\u003c/span\u003e\u003c/var\u003e\n\n 4. Submit the builder to your project:\n\n gcloud builds submit .\n\n 5. Navigate back to your project root directory:\n\n cd ../..\n\n 6. Remove the repository from your root directory:\n\n rm -rf cloud-builders-community/\n\n2. In your Cloud Build config file, use the builder in a build step:\n\n ### YAML\n\n steps:\n - name: 'gcr.io/\u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e/\u003cvar translate=\"no\"\u003ebuilder-name\u003c/var\u003e'\n args: ['\u003cvar translate=\"no\"\u003earg1\u003c/var\u003e', '\u003cvar translate=\"no\"\u003earg2\u003c/var\u003e', ...]\n ...\n\n ### JSON\n\n {\n \"steps\": [\n {\n \"name\": \"gcr.io/\u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e/\u003cvar translate=\"no\"\u003ebuilder-name\u003c/var\u003e\",\n \"args\": [\n \"\u003cvar translate=\"no\"\u003earg1\u003c/var\u003e\",\n \"\u003cvar translate=\"no\"\u003earg2\u003c/var\u003e\",\n ...\n ]\n ...\n }\n ]\n }\n\n3. Use the build config file to start the [build manually](/build/docs/running-builds/start-build-manually)\n or [build using triggers](/build/docs/automating-builds/create-manage-triggers).\n\nFor examples on using community-contributed builders, see\n[Deploy to Firebase](/build/docs/deploying-builds/deploy-firebase)\nand [Build VM images using Packer](/build/docs/building/build-vm-images-with-packer).\n\nCreating a custom builder\n-------------------------\n\nIf the task you want to perform requires capabilities that are not provided by\n[a public image, a supported builder, or a community-contributed builder](/build/docs/cloud-builders),\nyou can build your own image and use it in a build step.\n\nSome examples of when you might want to use a custom builder image are:\n\n- Downloading source code or packages from external locations.\n- Using an external tool chain.\n- Caching any necessary libraries.\n- Pre-building source (with Cloud Build responsible only for potentially packaging the build into an image).\n\nLike any other builder, a custom builder runs with the source mounted under\n`/workspace`, and is run with a working directory in `/workspace`. Any files left\nin `/workspace` by a given build step are available to other build steps.\n\nYour custom builder can push to or pull from a repository in\n[Artifact Registry](/artifact-registry/docs/overview) (hosted at `gcr.io/$PROJECT-NAME/`)\nto which your [build service account](/build/docs/securing-builds/configure-user-specified-service-accounts) has\naccess.\n\nThe following steps show how to create and use a custom builder with an example\n`Dockerfile`:\n\n1. Create a custom builder image:\n\n 1. Create the `Dockerfile` for the custom builder. The following\n code shows an example `Dockerfile`:\n\n FROM alpine\n RUN apk add curl\n CMD curl https://httpbin.org/ip -s \u003e myip.txt; echo \"*** My IP is: $(cat myip.txt)\"\n\n 2. Build and push the custom builder to the Artifact Registry in your project,\n replacing values for \u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e and \u003cvar translate=\"no\"\u003eimage-name\u003c/var\u003e:\n\n gcloud builds submit --tag gcr.io/\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eproject\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003eid\u003c/span\u003e\u003c/var\u003e/\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eimage\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003ename\u003c/span\u003e\u003c/var\u003e\n\n2. Use the custom builder image in Cloud Build by specifying the builder\n in the `name` field of a build step:\n\n ### YAML\n\n steps:\n - name: 'gcr.io/\u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e/\u003cvar translate=\"no\"\u003eimage-name\u003c/var\u003e'\n id: Determine IP of this build worker\n\n ### JSON\n\n {\n \"steps\": [\n {\n \"name\": \"gcr.io/\u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e/\u003cvar translate=\"no\"\u003eimage-name\u003c/var\u003e\",\n \"id\": \"Determine IP of this build worker\"\n }\n ]\n }\n\n3. Use the build config file to start the [build manually](/build/docs/running-builds/start-build-manually)\n or [build using triggers](/build/docs/automating-builds/create-manage-triggers).\n\n| **Note:** Users can specify a working directory using the `dir` field in a build config file. Because your custom builder's users may specify any `dir` value, the builder should avoid hard-coding `/workspace` if possible. Instead, use the current working directory and relative paths.\n\nWhat's next\n-----------\n\n- Learn how to [run bash scripts in build steps](/build/docs/configuring-builds/run-bash-scripts).\n- Learn how to [configure build step order](/build/docs/configuring-builds/configure-build-step-order).\n- Learn how to [write a basic build config file](/build/docs/configuring-builds/create-basic-configuration)."]]