Como configurar o aplicativo com app.yaml

Um aplicativo do App Engine é configurado usando um arquivo app.yaml, que contém recursos de CPU, memória, rede e disco, escalonamento e outras configurações gerais, incluindo variáveis de ambiente.

Sobre arquivos app.yaml

É possível especificar a configuração do ambiente de execução do aplicativo Go no arquivo app.yaml, incluindo versões e URLs. Esse arquivo atua como um descritor de implantação de uma versão de serviço específica.

Primeiro, é necessário criar o arquivo app.yaml para o serviço default do app antes de criar e implementar arquivos app.yaml para outros serviços.

O app.yaml a seguir demonstra como configurar seu app para Go 1.15 e anteriores e 1.18 e mais recentes. Você precisa atualizar o arquivo app.yaml para usar a nova versão. Consulte Ambiente de execução do Go para mais informações sobre como usar as novas versões.

v1.18 e posterior

# 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 anteriores

# 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

Dependendo da complexidade do serviço do aplicativo, talvez seja necessário definir apenas alguns elementos no arquivo app.yaml correspondente. Veja no exemplo a seguir o que um simples aplicativo em Go pode exigir no ambiente flexível:

É possível especificar um nome único para os arquivos app.yaml, mas será necessário especificar o nome do arquivo com o comando de implantação também. Por exemplo, ao nomear seu arquivo app.yaml, service-name-app.yaml ou app.flexible.yaml, será preciso implantar o aplicativo usando:

gcloud app deploy service-name-app.yaml
gcloud app deploy app.flexible.yaml
Para saber mais sobre como estruturar vários serviços e arquivos app.yaml no app, consulte Como estruturar serviços da Web.

Todos os elementos de configuração

Para uma lista completa de todos os elementos compatíveis com esse arquivo de configuração, consulte a referência do app.yaml.