Anwendung mit app.yaml konfigurieren

Eine App Engine-Anwendung wird über eine app.yaml-Datei konfiguriert. Diese enthält Einstellungen für CPU-, Arbeitsspeicher-, Netzwerk- und Datenträgerressourcen, Skalierungen und andere allgemeine Einstellungen, einschließlich Umgebungsvariablen.

app.yaml-Dateien

Sie können die Laufzeitkonfiguration für Ihre Python-Anwendung, einschließlich Versionen und URLs, in der Datei app.yaml angeben. Diese Datei dient als Deployment-Deskriptor für eine bestimmte Dienstversion.

Erstellen Sie zuerst die Datei app.yaml für den Dienst default Ihrer Anwendung. Erst dann können Sie app.yaml-Dateien für zusätzliche Dienste erstellen und bereitstellen.

Die folgende app.yaml-Datei zeigt, wie Ihre Anwendung für Python 3.7 und frühere Versionen sowie 3.8 und höher konfiguriert wird. Beachten Sie, dass Sie Ihre app.yaml-Datei aktualisieren müssen, um die neue Version zu verwenden. Weitere Informationen zur Verwendung der neuen Versionen finden Sie unter Python-Laufzeit.

v3.8 und höher

# 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 und älter

# 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

Je nach Komplexität des Dienstes Ihrer Anwendung müssen Sie möglicherweise nur wenige Elemente in der entsprechenden app.yaml-Datei definieren. In diesem Beispiel wird gezeigt, was eine einfache Python-Anwendung in der flexiblen Umgebung erfordern kann:

Sie können Dateien des Typs app.yaml jeweils eindeutige Namen geben, müssen diese Dateinamen dann aber auch im Bereitstellungsbefehl angeben. Wenn Sie beispielsweise Ihre app.yaml-Datei service-name-app.yaml oder app.flexible.yaml benennen, müssen Sie Ihre Anwendung so bereitstellen:

gcloud app deploy service-name-app.yaml
gcloud app deploy app.flexible.yaml
Weitere Informationen zum Strukturieren mehrerer Dienste und app.yaml-Dateien in Ihrer Anwendung finden Sie unter Webdienste strukturieren.

Alle Konfigurationselemente

Eine vollständige Liste aller in dieser Konfigurationsdatei unterstützten Elemente finden Sie in der Referenz zu app.yaml.