Configurazione dell'app con app.yaml

Un'app di App Engine viene configurata utilizzando un file app.yaml, contenente le risorse di CPU, memoria, rete e disco, scalabilità e altre impostazioni generali, comprese le variabili di ambiente.

Circa app.yaml file

Puoi specificare la configurazione di runtime per la tua app Go, inclusi versioni e URL, nel file app.yaml. Questo file funge da descrittore di deployment di una specifica versione di servizio.

Devi creare il file app.yaml per il servizio default della tua app prima di poter creare file app.yaml per i servizi aggiuntivi ed eseguirne il deployment.

Il seguente app.yaml mostra come configurare l'app per Go 1.15 e versioni precedenti e 1.18 e successive. Tieni presente che devi aggiornare il file app.yaml per utilizzare la nuova versione. Consulta Go runtime per ulteriori informazioni sull'utilizzo delle nuove versioni.

1.18 e versioni successive

# Copyright 2019 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
#
#     https://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: go
env: flex

runtime_config:
  operating_system: 'ubuntu22'
  runtime_version: '1.18'

# 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

v1.15 e precedenti

# Copyright 2023 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
#
#     https://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: go
env: flex

# 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

A seconda della complessità del servizio della tua app, potresti dover definire solo alcuni elementi nel file app.yaml corrispondente. L'esempio seguente mostra cosa potrebbe richiedere un'app Go semplice nell'ambiente flessibile:

Puoi specificare un nome univoco per i tuoi file app.yaml, ma devi specificare anche il nome del file con il comando deployment. Ad esempio, se il nome del file app.yaml è service-name-app.yaml o app.flexible.yaml, devi eseguire il deployment dell'app utilizzando:

gcloud app deploy service-name-app.yaml
gcloud app deploy app.flexible.yaml
Per scoprire di più sulla strutturazione di più servizi e file app.yaml nella tua app, vedi Strutturare i servizi web.

Tutti gli elementi di configurazione

Per un elenco completo di tutti gli elementi supportati in questo file di configurazione, consulta la documentazione di riferimento di app.yaml.