Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menjelaskan cara men-deploy aplikasi ke App Engine menggunakan Cloud Build. Jika Anda baru menggunakan Cloud Build, baca
panduan memulai dan
ringkasan konfigurasi build terlebih dahulu.
App Engine adalah platform serverless yang terkelola sepenuhnya untuk mengembangkan dan menghosting
aplikasi web dalam skala besar. Untuk mengetahui informasi selengkapnya tentang App Engine, baca
dokumentasi App Engine.
Untuk menjalankan perintah gcloud di halaman ini, instal
Google Cloud CLI.
Siapkan kode sumber aplikasi yang ingin Anda bangun dan deploy ke App Engine. Kode sumber Anda harus disimpan dalam repositori, seperti Cloud Source Repositories, GitHub, atau Bitbucket.
Izin IAM yang diperlukan
Di konsol Google Cloud , pilih project Anda.
Berikan peran Akun Layanan Cloud Build
ke akun layanan default App Engine. Jika akun layanan tidak muncul dalam daftar, temukan akun layanan di halaman Service Accounts.
Tetapkan status peran App Engine Admin dan peran Service Account User
ke Diaktifkan.
Mengonfigurasi deployment
Cloud Build memungkinkan Anda menggunakan image container yang tersedia secara publik untuk menjalankan tugas. Anda dapat melakukannya dengan menentukan image dalam build step
di file konfigurasi Cloud Build.
App Engine menyediakan perintah gcloud app deploy, yang mem-build image dengan
kode sumber Anda dan men-deploy image tersebut di App Engine. Anda dapat menggunakan image cloud-sdk
sebagai langkah build dalam file konfigurasi untuk memanggil perintah gcloud dalam image.
Argumen yang diteruskan ke langkah build ini diteruskan langsung ke gcloud CLI,
sehingga Anda dapat menjalankan perintah gcloud apa pun dalam image ini.
Untuk men-deploy aplikasi ke App Engine, ikuti langkah-langkah berikut:
Tambahkan kolom name untuk menentukan langkah build cloud-sdk.
Tambahkan kolom entrypoint untuk menggunakan alat bash saat cloud-sdk dipanggil.
Di kolom args, panggil perintah gcloud app deploy dan tetapkan timeout
untuk App Engine yang akan digunakan saat memanggil Cloud Build. Hal ini diperlukan karena langkah-langkah build dan build Cloud Build memiliki waktu tunggu default 10 menit dan deployment App Engine dapat memerlukan waktu lebih lama untuk diselesaikan. Menentukan waktu tunggu yang lebih lama akan memastikan bahwa build tidak mengalami waktu tunggu habis jika gcloud app deploy memerlukan waktu lebih dari 10 menit untuk selesai.
Error waktu tunggu saat menggunakan lingkungan standar App Engine:
Anda hanya dapat mengonfigurasi waktu tunggu seperti yang dijelaskan di sini saat menggunakan lingkungan fleksibel App Engine. Lingkungan standar App Engine tidak mengizinkan konfigurasi waktu tunggu build. Jika Anda menggunakan Cloud Build untuk men-deploy di lingkungan standar App Engine, dan build Anda gagal dengan error waktu tunggu, pertimbangkan untuk menggunakan lingkungan fleksibel App Engine atau Cloud Run, sebagai pengganti lingkungan standar App Engine.
{"steps":[{"name":"gcr.io/google.com/cloudsdktool/cloud-sdk","entrypoint":"bash","args":["-c","gcloud config set app/cloud_build_timeout 1600 && gcloud app deploy"]}],"timeout":"1600s"}
Mulai build, dengan SOURCE_DIRECTORY adalah jalur atau URL ke kode sumber dan REGION adalah salah satu region build yang didukung untuk memulai build:
gcloudbuildssubmit--region=REGIONSOURCE_DIRECTORY
Deployment berkelanjutan
Anda dapat mengotomatiskan deployment software ke App Engine dengan membuat
pemicu Cloud Build. Anda dapat mengonfigurasi pemicu untuk mem-build dan men-deploy image setiap kali Anda mengupdate kode sumber.
Untuk mengotomatiskan deployment ke App Engine:
Di repositori Anda, tambahkan file konfigurasi dengan langkah-langkah
untuk memanggil perintah gcloud app deploy:
[[["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-04 UTC."],[[["\u003cp\u003eThis guide outlines how to deploy applications to App Engine using Cloud Build, a fully managed, serverless platform.\u003c/p\u003e\n"],["\u003cp\u003eTo deploy an application, you'll need to create a Cloud Build configuration file, which specifies the \u003ccode\u003ecloud-sdk\u003c/code\u003e image and uses the \u003ccode\u003egcloud app deploy\u003c/code\u003e command.\u003c/p\u003e\n"],["\u003cp\u003eThe configuration requires enabling the App Engine API, installing the Google Cloud CLI, having application source code in a repository, and setting the necessary IAM permissions for Cloud Build.\u003c/p\u003e\n"],["\u003cp\u003eContinuous deployment to App Engine can be automated by creating Cloud Build triggers that are activated by code updates in your repository.\u003c/p\u003e\n"],["\u003cp\u003eWhen deploying to the App Engine flexible environment, ensure to set a build timeout in the config file, but note that this isn't configurable in the App Engine standard environment; consider using the flexible environment or Cloud Run if timeout errors occur.\u003c/p\u003e\n"]]],[],null,["# Deploying to App Engine\n\nThis page explains how to deploy applications to App Engine using\nCloud Build. If you're new to Cloud Build, read the\n[quickstarts](/build/docs/quickstarts) and the\n[build configuration overview](/build/docs/build-config) first.\n\nApp Engine is a fully managed, serverless platform for developing and hosting\nweb applications at scale. For more information on App Engine, read the\n[App Engine documentation](/appengine/docs).\n\nBefore you begin\n----------------\n\n- Enable the App Engine API:\n\n [Enable the App Engine API](https://console.cloud.google.com/apis/library/appengine.googleapis.com)\n- To run the `gcloud` commands on this page, install the\n [Google Cloud CLI](/sdk).\n\n- Have your application source code that you want to build and deploy to App Engine\n handy. Your source code needs to be stored in a repository, such as\n Cloud Source Repositories, GitHub, or Bitbucket.\n\n| **Caution:** Effective June 17, 2024, Cloud Source Repositories isn't available\n| to new customers. If your organization hasn't\n| previously used Cloud Source Repositories, you can't enable the API or use\n| Cloud Source Repositories. New projects not connected to an organization can't enable the\n| Cloud Source Repositories API. Organizations that have used Cloud Source Repositories prior to\n| June 17, 2024 are not affected by this change.\n\n### Required IAM permissions\n\n1. In the Google Cloud console, select your project.\n\n2. [Grant](/iam/docs/grant-role-console) the **Cloud Build Service Account**\n role to the App Engine default service account. If service account does not\n appear in the list, locate service account in **Service Accounts** page.\n\n [Go to Service\n Accounts](https://console.cloud.google.com/iam-admin/serviceaccounts)\n3. Grant the **App Engine Admin** role and **Service Account User** to the build\n service account:\n\n 1. In the Google Cloud console, go to the\n *settings* Cloud Build **Permissions** page:\n\n [Go to **Permissions**](https://console.cloud.google.com/cloud-build/settings)\n\n \u003cbr /\u003e\n\n 2. Set the status of the **App Engine Admin** role and the **Service Account User**\n role to **Enabled**.\n\nConfiguring the deployment\n--------------------------\n\nCloud Build lets you use any publicly available container image\nto execute your tasks. You can do this by specifying the image in a build `step`\nin the Cloud Build config file.\n\nApp Engine provides the `gcloud app deploy` command, which builds an image with\nyour source code and deploys that image on App Engine. You can use the [`cloud-sdk`\nimage](https://github.com/GoogleCloudPlatform/cloud-sdk-docker)\nas a build step in your config file to invoke `gcloud` commands within the image.\nArguments passed to this build step are passed to the gcloud CLI directly,\nallowing you to run any `gcloud` command in this image.\n\nTo deploy an application to App Engine, use the following steps:\n\n1. Create a [Cloud Build configuration file](/build/docs/build-config)\n named `cloudbuild.yaml` or `cloudbuild.json`.\n\n | **Note:** Do not store the config file in the same directory as the source code because the gcloud CLI may interpret that you want to deploy the app using Docker via Cloud Build. Instead, store your source in a separate directory and create the config file in the parent directory.\n2. In the config file:\n\n - Add a `name` field to specify the `cloud-sdk` build step.\n - Add an `entrypoint` field to use the `bash` tool when `cloud-sdk` is invoked.\n - In the `args` field, invoke the `gcloud app deploy` command and set a `timeout`\n for [App Engine to use when it invokes Cloud Build](/appengine/docs/standard/nodejs/testing-and-deploying-your-app#deploying_your_application). This is required because Cloud Build\n build steps and builds have a default timeout of 10 minutes and App Engine\n deployments could take longer than that to complete. Specifying a longer timeout\n will make sure that the build doesn't timeout if `gcloud app deploy` takes\n longer than 10 minutes to complete.\n\n **Timeout errors when using the App Engine standard environment** :\n You can configure timeouts as described here only when using the App Engine\n flexible environment. The App Engine standard environment does not allow\n the build timeout to be configured. If you're using Cloud Build\n for deploying on the App Engine standard environment, and your build\n is failing with a timeout error, consider using the App Engine flexible\n environment or [Cloud Run](/build/docs/deploying-builds/deploy-cloud-run)\n instead of the App Engine standard environment.\n - Add a [build `timeout`](/build/docs/build-config#build_steps) value of\n more than 10 minutes.\n\n ### YAML\n\n steps:\n - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'\n entrypoint: 'bash'\n args: ['-c', 'gcloud config set app/cloud_build_timeout 1600 && gcloud app deploy']\n timeout: '1600s'\n\n ### JSON\n\n {\n \"steps\": [\n {\n \"name\": \"gcr.io/google.com/cloudsdktool/cloud-sdk\",\n \"entrypoint\": \"bash\",\n \"args\": [\n \"-c\",\n \"gcloud config set app/cloud_build_timeout 1600 && gcloud app deploy\"\n ]\n }\n ],\n \"timeout\": \"1600s\"\n }\n\n3. Start the build, where \u003cvar translate=\"no\"\u003eSOURCE_DIRECTORY\u003c/var\u003e is the path or URL to the source\n code and \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e is one of the [supported build regions](/build/docs/locations)\n to start the build:\n\n gcloud builds submit --region=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eREGION\u003c/span\u003e\u003c/var\u003e \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eSOURCE_DIRECTORY\u003c/span\u003e\u003c/var\u003e\n\nContinuous deployment\n---------------------\n\nYou can automate the deployment of your software to App Engine by creating\nCloud Build triggers. You can configure your triggers to build and\ndeploy images whenever you update your source code.\n\nTo automate your deployment to App Engine:\n\n1. In your repository, add a config file with steps\n to invoke the `gcloud app deploy` command:\n\n ### YAML\n\n steps:\n - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'\n entrypoint: 'bash'\n args: ['-c', 'gcloud config set app/cloud_build_timeout 1600 && gcloud app deploy']\n timeout: '1600s'\n\n ### JSON\n\n {\n \"steps\": [\n {\n \"name\": \"gcr.io/google.com/cloudsdktool/cloud-sdk\",\n \"entrypoint\": \"bash\",\n \"args\": [\n \"-c\",\n \"gcloud config set app/cloud_build_timeout 1600 && gcloud app deploy\"\n ]\n }\n ],\n \"timeout\": \"1600s\"\n }\n\n2. Create a build trigger with the config file created in the previous step:\n\n 1. Open the **Triggers** page in the Google Cloud console:\n\n [Open Triggers page](https://console.cloud.google.com/cloud-build/triggers)\n 2. Select your project from the project selector drop-down menu at the top of\n the page.\n\n 3. Click **Open**.\n\n 4. Click **Create trigger**.\n\n On the **Create trigger** page, enter the following settings:\n 1. Enter a name for your trigger.\n\n 2. Select the repository event to start your trigger.\n\n 3. Select the repository that contains your source code and build\n config file.\n\n 4. Specify the regex for the branch or tag name that will start your\n trigger.\n\n 5. **Configuration**: Choose the build config file you created\n previously.\n\n 5. Click **Create** to save your build trigger.\n\nAnytime you push new code to your repository, you will automatically start a\nbuild and deploy on App Engine.\n\nFor more information on creating Cloud Build triggers, see\n[Creating and managing build triggers](/build/docs/automating-builds/create-manage-triggers).\n\nWhat's next\n-----------\n\n- Learn how to [deploy on Cloud Run](/build/docs/deploying-builds/deploy-cloud-run)\n- Learn how to [perform blue/green deployments on Compute Engine](/build/docs/deploying-builds/deploy-compute-engine)\n- Learn how to [deploy on GKE](/build/docs/deploying-builds/deploy-gke)\n- Learn how to [deploy on Cloud Run functions](/build/docs/deploying-builds/deploy-functions)\n- Learn how to [deploy on Firebase](/build/docs/deploying-builds/deploy-firebase)\n- Learn how to [troubleshoot build errors](/build/docs/troubleshooting)."]]