使用 app.yaml 配置应用

App Engine 应用是使用 app.yaml 文件进行配置的,该文件包含 CPU、内存、网络和磁盘资源设置、扩缩设置以及环境变量等其他常规设置。

app.yaml 文件简介

您可以在 app.yaml 文件中指定 Ruby 应用的运行时配置,包括版本和网址。该文件充当特定服务版本的部署描述符。

您必须先为应用的 default 服务创建 app.yaml 文件,然后才能为其他服务创建和部署 app.yaml 文件。

以下 app.yaml 演示了对于 3.1 版及更低版本和 3.2 版,如何配置 Ruby 应用。请注意,您必须更新 app.yaml 才能使用新版本。如需详细了解如何使用新版运行时,请参阅 Ruby 运行时

3.2 版

runtime: ruby
env: flex
entrypoint: bundle exec ruby app.rb

runtime_config:
  operating_system: ubuntu22

# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/ruby/configuring-your-app-with-app-yaml
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

3.1 版及更低版本

runtime: ruby
env: flex
entrypoint: bundle exec ruby app.rb

# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/ruby/configuring-your-app-with-app-yaml
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

您可能只需在相应的 app.yaml 文件中定义几个元素,具体取决于应用服务的复杂程度。以下示例演示了柔性环境中的简单 Ruby 应用可能需要定义的元素:

您可以为 app.yaml 文件指定一个独特的名称,但还必须使用部署命令指定该文件名。例如,如果您将 app.yaml 文件命名为 service-name-app.yamlapp.flexible.yaml,则必须使用下列任一命令部署您的应用:

gcloud app deploy service-name-app.yaml
gcloud app deploy app.flexible.yaml
如需详细了解如何在应用中设计多个服务和 app.yaml 文件的结构,请参阅设计 Web 服务的结构

所有配置元素

如需查看此配置文件中所有受支持的元素的完整列表,请参阅 app.yaml 参考文档