每次将更改部署到特定服务时,Cloud Run 都会使用 Revision 而不是 Version 一词来表示。首次将应用部署到 Cloud Run 中的服务会创建其第一个修订版本。服务的每个后续部署都会创建其他修订版本。详细了解如何部署到 Cloud Run。
您可以使用 Google Cloud CLI 或 Google Cloud 控制台将源代码部署到 Cloud Run 来配置和管理应用设置。Cloud Run 不需要基于文件的配置,但 YAML 配置受支持,您可以使用 app2run 工具转换 Cloud Run 的现有 App Engine 文件。
[[["易于理解","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-08-20。"],[[["\u003cp\u003eThis guide details how to migrate an existing App Engine app connected to a Cloud SQL instance with a public IP to Cloud Run, using the same application source code and Cloud SQL database user.\u003c/p\u003e\n"],["\u003cp\u003eThe migration process to Cloud Run involves enabling required APIs, configuring the Cloud Run service account with appropriate permissions, and deploying the app without code modifications, leveraging buildpacks and Cloud Build for container image creation.\u003c/p\u003e\n"],["\u003cp\u003eCloud Run uses \u003ccode\u003eRevision\u003c/code\u003e instead of \u003ccode\u003eVersion\u003c/code\u003e, does not mandate file-based configuration, defaults to private services unlike App Engine, and uses the \u003ccode\u003erun.app\u003c/code\u003e domain for public service URLs.\u003c/p\u003e\n"],["\u003cp\u003eDeploying to Cloud Run from App Engine source code involves using the \u003ccode\u003egcloud run deploy\u003c/code\u003e command with the \u003ccode\u003e--source\u003c/code\u003e flag, along with setting environment variables for Cloud SQL connection information, such as instance connection name, database name, user, and password.\u003c/p\u003e\n"],["\u003cp\u003eThe Region ID is an abbreviated code that Google assigns based on the selected region when creating an app, which is included in App Engine URLs for apps created after February 2020.\u003c/p\u003e\n"]]],[],null,["# Migrate an App Engine standard environment app to Cloud Run\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n### Region ID\n\n\u003cbr /\u003e\n\n\nThe \u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e is an abbreviated code that Google assigns\nbased on the region you select when you create your app. The code does not\ncorrespond to a country or province, even though some region IDs may appear\nsimilar to commonly used country and province codes. For apps created after\nFebruary 2020, \u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e`.r` is included in\nApp Engine URLs. For existing apps created before this date, the\nregion ID is optional in the URL.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nLearn more\n[about region IDs](/appengine/docs/standard/python/how-requests-are-routed#region-id). \nOK\n\nThis guide describes how to migrate an existing App Engine app that connects\nto a Cloud SQL instance with a\n[public IP](/sql/docs/mysql/connect-overview#public_ip).\n\nIn general, the steps in this guide demonstrate how you can deploy the same\napplication source code in Cloud Run and then configure it to\nuse the same Cloud SQL database user to connect your existing\ninstance and database.\n\nThe steps in this guide don't include how to use an internal private IP\nconnection because that requires you to first modify your application code.\nHowever, after you deploy your app to Cloud Run, you can then use\nthe steps in\n[Connect to Cloud SQL from Cloud Run](/sql/docs/mysql/connect-run#private-ip)\nto learn the requirements and how to use Private IPs.\n\nTo understand more about the similarities and differences between App Engine\nand Cloud Run, including the benefits for migrating to\nCloud Run, see the [comparison summary](/appengine/docs/standard/cloud-run-for-gae-customers#comparison_summary).\n\nBefore you begin\n----------------\n\n1. Ensure that Cloud Run [meets your application requirements](/run/docs/fit-for-run). Review [App Engine and Cloud Run comparison](/appengine/docs/standard/cloud-run-for-gae-customers#comparison_summary) to determine if the Cloud Run resources like CPU and memory meet your needs.\n2. This guide assumes that your app runs without errors.\n\n3. You need [access to your Cloud SQL instance](/sql/docs/mysql/instance-info#info),\n including the database username and password for connecting your app.\n Cloud Run uses encryption and connects through the Cloud SQL Auth\n proxy using either Unix sockets or Cloud SQL connectors.\n\n4. Review the following Cloud Run differences:\n\n - Cloud Run uses the term `Revision`, instead of `Version` to represent\n each time you deploy changes to a specific service. Deploying your app\n to a service in Cloud Run for the first time creates its first\n revision. Each subsequent deployment of a service creates another revision.\n [Learn more about deploying to Cloud Run](/run/docs/deploying#service).\n\n - You can deploy your source code to Cloud Run using Google Cloud CLI\n or the Google Cloud console to configure and manage your apps\n settings. Cloud Run does not require file-based configuration, however\n [YAML configuration](/run/docs/deploying?tab=yaml#revision) is supported\n and you can use the\n [`app2run` tool](https://github.com/GoogleCloudPlatform/app2run) to\n translate your existing App Engine file for Cloud Run.\n\n - Every service that you deploy to Cloud Run uses the\n [run.app](/run/docs/triggering/https-request#creating_public_services)\n domain in the URL to access the service publicly.\n\n - Unlike App Engine services that are public by default,\n [Cloud Run services are private by default](/run/docs/authenticating/overview)\n and require you to configure them for public (unauthenticated) access.\n\nMigrate your app to Cloud Run\n-----------------------------\n\nAt a high level, the process to migrate your App Engine app to\nCloud Run consists of the following steps:\n\n1. [Enable the required APIs](#apis)\n2. [Configure the Cloud Run service account](#configure_service_account)\n3. [Deploy your app in Cloud Run](#deploy)\n\n### Enable the required APIs\n\nBefore you can deploy your app to Cloud Run, you must first enable\nboth the Cloud Run and Artifact Registry APIs.\n\nUse the Google Cloud console to enable the APIs:\n\n[Go to APIs and Services](https://console.cloud.google.com/flows/enableapi?apiid=run.googleapis.com,artifactregistry.googleapis.com&_ga=2.109139269.1795509783.1687809390-606913076.1686784330)\n\n### Configure the Cloud Run service account\n\nYou can choose to either create a new service account or continue using the same\nuser-managed [service account](/run/docs/configuring/service-accounts) in\nCloud Run that you are using for App Engine.\nIn the service account, you must ensure that the following Identity and Access Management (IAM) roles\nor the equivalent permissions are configured:\n\nFor deploying to Cloud Run, you must have one of the following:\n\n- *Owner*\n- *Editor*\n- Both *Cloud Run Admin* and *Service Account User* roles\n- Equivalent [Cloud Run permissions](/run/docs/reference/iam/roles)\n\nFor public IP connections to Cloud SQL, you must have one of the following:\n\n- *Cloud SQL Client* (preferred)\n- *Cloud SQL Admin*\n- Equivalent [Cloud SQL permissions](/sql/docs/mysql/iam-roles)\n\n### Deploy your app in Cloud Run\n\nIt is not necessary to make any code changes to deploy your App Engine app to\nCloud Run.\n\nIn the following steps, you deploy your app to a new service in\nCloud Run and concurrently configure that service to connect to\nCloud SQL.\n| **Important:** The steps assume that you have access to the `app.yaml` file that you originally deployed to App Engine so that you can copy over the Cloud SQL configuration information. To manually locate the required configuration information for your Cloud SQL database, see both:\n|\n| - [Create and manage databases.](/sql/docs/sqlserver/create-manage-databases)\n| - [Create and manage users.](/sql/docs/sqlserver/create-manage-users)\n\n\u003cbr /\u003e\n\nLike App Engine standard environment, Cloud Run supports source-based\ndeployments. You need access to your source code repository.\n\n\nCloud Run internally uses [buildpacks](/docs/buildpacks)\nand [Cloud Build](/build/docs) to automatically build container images\nfrom your source code and does not require you to manually build a container\nor specify a Dockerfile. However, if a Dockerfile is present it will be used.\n\nDeploying a Cloud Run service from source uses Artifact Registry, so this\nfeature is only available in regions supported by Artifact Registry.\n\nTo deploy the same source code that you previously deployed to App Engine:\n\n1. Change to your source directory where the source code of your application resides.\n\n cd \u003cvar translate=\"no\"\u003eYOUR_APPENGINE_CODE_DIR\u003c/var\u003e\n\n2. Deploy to Cloud Run.\n\n To build your source code and deploy your application, run the deploy\n command with the `--source` flag. You must set configuration flags to\n include the same SQL connection environment variables defined in the\n `app.yaml` file of your App Engine app: \n\n gcloud run deploy run-sql --source \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eSOURCE\u003c/span\u003e\u003c/var\u003e \\\n --allow-unauthenticated \\\n --add-cloudsql-instances \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eINSTANCE_CONNECTION_NAME\u003c/span\u003e\u003c/var\u003e\\\n --set-env-vars INSTANCE_UNIX_SOCKET=\"/cloudsql/\u003cvar translate=\"no\"\u003eINSTANCE_CONNECTION_NAME\u003c/var\u003e\" \\\n --set-env-vars INSTANCE_CONNECTION_NAME=\"\u003cvar translate=\"no\"\u003eINSTANCE_CONNECTION_NAME\u003c/var\u003e\" \\\n --set-env-vars DB_NAME=\"\u003cvar translate=\"no\"\u003eDB_NAME\u003c/var\u003e\" \\\n --set-env-vars DB_USER=\"\u003cvar translate=\"no\"\u003eDB_USER\u003c/var\u003e\" \\\n --set-env-vars DB_PASS=\"\u003cvar translate=\"no\"\u003eDB_PASS\u003c/var\u003e\"\n\n Replace:\n - \u003cvar translate=\"no\"\u003eSOURCE\u003c/var\u003e with the path to your App Engine source directory\n - \u003cvar translate=\"no\"\u003eINSTANCE_CONNECTION_NAME\u003c/var\u003e with the instance connection name of your Cloud SQL instance, or a comma delimited list of connection names. You can find the `INSTANCE_CONNECTION_NAME` by running:\n\n gcloud instances describe \u003cvar translate=\"no\"\u003eINSTANCE_NAME\u003c/var\u003e\n\n - \u003cvar translate=\"no\"\u003eDB_NAME\u003c/var\u003e with the name of your database.\n - \u003cvar translate=\"no\"\u003eDB_USER\u003c/var\u003e with the username of your database.\n - \u003cvar translate=\"no\"\u003eDB_PASS\u003c/var\u003e with the password of your database user.\n3. Enter a name of the SERVICE when prompted.\n\n4. Respond to any prompts to install required APIs by responding `y` when prompted.\n You only need to do this once for a project.\n Wait for the build and deploy to complete. When finished, a message similar to this one is displayed:\n\n Service [my-app] revision [my-app-00000-xxx] has been deployed and is serving 100 percent of traffic. Service URL: https://sample.run.app\n\n To learn more about deploying source code to Cloud Run, see\n [Deploying from source code](/run/docs/deploying-source-code).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nNext steps\n----------\n\n- Review [Cloud SQL best practices](/sql/docs/mysql/connect-run#best-practices) for connecting your Cloud SQL instance from Cloud Run.\n- Learn how to store dependencies for your service requiring API keys, passwords or other sensitive information using a [secret manager](/run/docs/configuring/services/secrets).\n- Understand how to [manage your Cloud Run services](/run/docs/managing/services).\n- See the Cloud Run [container runtime contract](/run/docs/container-contract) to understand the requirements and behaviors of containers in Cloud Run."]]