Menggunakan builder yang dikontribusikan oleh komunitas dan builder kustom
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menjelaskan cara menggunakan builder yang dikontribusikan oleh komunitas dan builder kustom di Cloud Build. Komunitas developer Cloud Build menyediakan builder open source yang dapat Anda gunakan untuk menjalankan tugas. Jika tugas yang ingin Anda lakukan memerlukan kemampuan yang tidak disediakan oleh image yang ada, Anda dapat membuat image kustom sendiri dan menggunakannya dalam langkah build. Untuk mempelajari berbagai jenis builder, lihat Cloud Builder.
Menggunakan builder yang dikontribusikan oleh komunitas
Image yang telah di-build sebelumnya tidak tersedia untuk builder yang dikontribusikan komunitas; untuk menggunakan builder ini dalam file konfigurasi Cloud Build, Anda harus mem-build image terlebih dahulu dan mengirimkannya ke Artifact Registry di project Anda.
Untuk menggunakan builder yang dikontribusikan oleh komunitas:
Beberapa contoh kapan Anda mungkin ingin menggunakan image builder kustom adalah:
Mendownload kode sumber atau paket dari lokasi eksternal.
Menggunakan rangkaian alat eksternal.
Meng-cache library yang diperlukan.
Membangun sumber terlebih dahulu (dengan Cloud Build hanya bertanggung jawab untuk
berpotensi mengemas build ke dalam image).
Seperti builder lainnya, builder kustom berjalan dengan sumber yang di-mount di
/workspace, dan dijalankan dengan direktori kerja di /workspace. File apa pun yang tersisa di /workspace oleh langkah build tertentu tersedia untuk langkah build lainnya.
Builder kustom Anda dapat mengirim atau menarik dari repositori di
Artifact Registry (di-hosting di gcr.io/$PROJECT-NAME/)
yang dapat diakses oleh akun layanan build Anda.
Langkah-langkah berikut menunjukkan cara membuat dan menggunakan builder kustom dengan contoh
Dockerfile:
Buat image builder kustom:
Buat Dockerfile untuk builder kustom. Kode
berikut menunjukkan contoh Dockerfile:
FROMalpineRUNapkaddcurlCMDcurlhttps://httpbin.org/ip -s > myip.txt; echo "*** My IP is: $(cat myip.txt)"
Bangun dan kirim builder kustom ke Artifact Registry di project Anda, dengan mengganti nilai untuk project-id dan image-name:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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)."]]