app.yaml によるアプリの構成

App Engine アプリを構成するには、app.yaml ファイルを使用します。このファイルには、CPU、メモリ、ネットワーク リソース、ディスク リソース、スケーリングをはじめとする、環境変数を含む全般的な設定が含まれています。

app.yaml ファイルの概要

app.yaml ファイルには、バージョンや URL など、Go アプリのランタイム構成を指定できます。このファイルは、特定のサービス バージョンのデプロイ記述子として機能します。

追加サービス用に app.yaml ファイルを作成してデプロイするには、その前に、default サービス用の app.yaml ファイルを作成する必要があります。

次の app.yaml は、Go 1.15 以前と 1.18 以降用にアプリを構成する方法を示しています。新しいバージョンを使用するには app.yaml ファイルを更新する必要があることに留意してください。新しいバージョンの使用の詳細については、Go ランタイムをご覧ください。

v1.18 以降

# 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 以前

# 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

アプリのサービスの複雑さによっては、対応する app.yaml ファイルの一部の要素を定義するだけで済む場合もあります。次の例では、Go アプリをフレキシブル環境に配置する場合に必要となる内容について示します。

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 リファレンスをご覧ください。