Configura tu app con app.yaml

Una app de App Engine se configura mediante un archivo app.yaml que contiene los recursos de CPU, memoria, red y disco, el escalamiento y otros parámetros de configuración generales, incluidas las variables de entorno.

Acerca de los archivos app.yaml

Puedes especificar la configuración del entorno de ejecución para la app de Python, incluidas las versiones y las URL, en el archivo app.yaml. Este actúa como un descriptor de implementación de una versión específica del servicio.

Primero, debes crear el archivo app.yaml para el servicio default de tu app antes de que puedas crear e implementar los archivos app.yaml de servicios adicionales.

El siguiente app.yaml muestra cómo configurar tu app para la versión 3.7 de Python y anteriores, y la versión 3.8 y posteriores. Ten en cuenta que debes actualizar tu archivo app.yaml para usar la versión nueva. Consulta el entorno de ejecución de Python para obtener más información sobre el uso de las nuevos versiones.

v3.8 y posteriores

# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app

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/python/configuring-your-app-with-app-yaml
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

v3.7 y anteriores

# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app

runtime_config:
  python_version: 3

# 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/python/configuring-your-app-with-app-yaml
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

Según la complejidad del servicio de tu app, es posible que solo necesites definir algunos elementos en el archivo app.yaml correspondiente. En el siguiente ejemplo, se muestra lo que puede requerir una app de Python simple en el entorno flexible:

Puedes especificar un nombre único para tus archivos app.yaml, pero también debes especificar el nombre del archivo con el comando de implementación. Por ejemplo, si al archivo app.yaml lo nombras service-name-app.yaml o app.flexible.yaml, debes implementar la aplicación mediante una de las siguientes opciones:

gcloud app deploy service-name-app.yaml
gcloud app deploy app.flexible.yaml
Para obtener más información sobre cómo estructurar varios servicios y archivos app.yaml en tu aplicación, consulta Estructura servicios web.

Todos los elementos de configuración

Para obtener una lista completa de todos los elementos compatibles con este archivo de configuración, consulta la referencia de app.yaml.