Configurer votre application avec app.yaml

Une application App Engine est configurée à l'aide d'un fichier app.yaml contenant les ressources (processeur, mémoire, réseau et disque), le scaling, ainsi que d'autres paramètres généraux tels que les variables d'environnement.

À propos des fichiers app.yaml

Vous pouvez spécifier la configuration de l'environnement d'exécution de votre application Python, y compris les versions et les URL, dans le fichier app.yaml. Ce dernier sert de descripteur de déploiement pour une version de service spécifique.

Vous devez d'abord créer le fichier app.yaml pour le service default de votre application avant de pouvoir créer et déployer des fichiers app.yaml pour des services supplémentaires dans l'application.

Le fichier app.yaml suivant montre comment configurer votre application dans les versions 3.7 et antérieures, et les versions 3.8 et ultérieures de Python. Notez que vous devez mettre à jour votre fichier app.yaml pour utiliser la nouvelle version. Pour en savoir plus sur l'utilisation des nouvelles versions, consultez la page Environnement d'exécution Python.

Versions 3.8 et ultérieures

# 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 et versions précédentes

# 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

Selon la complexité du service de votre application, il vous suffira peut-être de définir quelques éléments dans le fichier app.yaml correspondant. L'exemple suivant montre ce qu'une application Python simple peut nécessiter dans un environnement flexible :

Vous pouvez spécifier un nom unique pour les fichiers app.yaml. Toutefois, dans ce cas, vous devez également spécifier ce nom de fichier dans la commande de déploiement. Par exemple, si vous nommez votre fichier app.yaml "service-name-app.yaml" ou "app.flexible.yaml", vous devez déployer votre application à l'aide de l'une des commandes suivantes :

gcloud app deploy service-name-app.yaml
gcloud app deploy app.flexible.yaml
Pour savoir comment structurer plusieurs services et fichiers app.yaml dans votre application, consultez la page Structurer des services Web.

Liste de tous les éléments de configuration

Pour obtenir la liste complète des éléments acceptés dans ce fichier de configuration, consultez la documentation de référence sur le fichier app.yaml.