הגדרת האפליקציה באמצעות app.yaml

אפליקציית App Engine מוגדרת באמצעות קובץ app.yaml, שמכיל משאבי מעבד, זיכרון, רשת וכונן, קנה מידה והגדרות כלליות אחרות, כולל משתני סביבה.

app.yaml קבצים בקירוב

אתם יכולים לציין את הגדרות זמן הריצה של אפליקציית Python, כולל גרסאות וכתובות URL, בקובץ app.yaml. הקובץ הזה משמש כמתאר פריסה של גרסה ספציפית של שירות.

קודם צריך ליצור את הקובץ app.yaml לשירות default של האפליקציה, לפני שיוצרים ומפעילים קבצים מסוג app.yaml לשירותים נוספים.

בקובץ app.yaml הבא מוצג איך להגדיר את האפליקציה כך שתשתמש בגרסה העדכנית ביותר של Python. כדי להשתמש בגרסה אחרת של Python שנתמכת, צריך לעדכן את קובץ app.yaml. מידע נוסף זמין במאמר בנושא Python runtime.

# 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: ubuntu24
  runtime_version: 3.12

# 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

בהתאם למורכבות השירות של האפליקציה, יכול להיות שתצטרכו להגדיר רק כמה רכיבים בקובץ app.yaml המתאים. בדוגמה הבאה אפשר לראות מה אפליקציית Python פשוטה עשויה לדרוש בסביבה גמישה:

אתם יכולים לציין שם ייחודי לקובצי app.yaml, אבל אז תצטרכו לציין את שם הקובץ גם בפקודת הפריסה. לדוגמה, אם קובץ app.yaml נקרא service-name-app.yaml או app.flexible.yaml, תצטרכו לפרוס את האפליקציה באמצעות אחת מהאפשרויות הבאות:

gcloud app deploy service-name-app.yaml
gcloud app deploy app.flexible.yaml
מידע נוסף על מבנה של כמה שירותים וקבצים של app.yaml באפליקציה זמין במאמר מבנה של שירותי אינטרנט.

כל רכיבי ההגדרה

רשימה מלאה של כל הרכיבים הנתמכים בקובץ ההגדרות הזה זמינה בחומר העזר בנושא app.yaml.