dackdive's blog

新米webエンジニアによる技術ブログ。JavaScript(React), Salesforce, Python など

[Google App Engine] app.yamlについて

ここを読んでみた。

https://cloud.google.com/appengine/docs/python/config/appconfig

とりあえず前半部分、handlers のところまで。

Required elements

app.yaml には以下の項目を1つずつ記載する必要がある。

application
  • アプリケーション名(任意)
version
  • バージョン名(任意)
  • 文字列で指定。アルファベット小文字・数字・ハイフンが使える
  • 例:alpha-001
  • 以下は NG
    • ah- から始まる文字列・defaultlatest
  • 異なるバージョンでアプリケーションをデプロイしておくと、Developer Console で簡単にバージョンを切り替えることができる
runtime
  • python の場合は python27
api_version
  • runtime 環境の API のバージョン
  • Google がリリースするものなのでこちらが気にする必要はない
  • python の場合は 1
    • (新しいバージョンがリリースされたら、どちらを使うか選べるということ?)
threadsafe
  • true または false を指定
  • 違いは勉強中
handlers
  • この URL にアクセスされた時はどうする、ということを記述する
  • handler は以下の2種類
    • script handlers: pythonスクリプトを実行する
    • static file handlers: 静的リソースを返す

handlers のサンプル

# --- Script handlers ---
handlers:
# The root URL (/) is handled by the webapp handler in the home.py script
# No other URLs match this pattern.
- url: /
  script: home.app

# The URL /index.html is also handled by the home.py script.
- url: /index\.html
  script: home.app

# A regular expression can map parts of the URL to the path of the script.
# \1 には books|videos|tools が渡される
- url: /browse/(books|videos|tools)
  script: \1.catalog.app

# All other URLs use the not_found.py script.
- url: /.*
  script: not_found.app


# --- Static file handlers ---
# All URLs beginning with /stylesheets are treated as paths to static files in
# the stylesheets/ directory.
- url: /stylesheets
  static_dir: stylesheets