9
6

More than 5 years have passed since last update.

GoogleAppEngineのapp.yamlの罠(と、思っているもの)

Last updated at Posted at 2018-07-26

Google App Engine便利ですよね。
いかに利用者にインフラの負担をかけずサービスを運用させていかせるか、凄い考えられてると思います。
standard環境でpython3.7やphp7.2も将来的に使用できるようになりますし、今後にも期待できます。

ただ……たまに罠のような何かがあるんですよね。
こう、予期していなかったエラーというか、桶狭間でいうところの今川義元感というか。

app.yaml

runtime: python27
api_version: 1
threadsafe: yes
service: trap-service

handlers:
- url: (/|/(.+)/|/index\.html)
  script: main.app

- url: /(.+)
  static_files: dist/\1
  upload: dist\/(?!(index\.html))
  expiration: "15m"

skip_files:
- ^(?!(dist|main\.py|\.env)).*$

という訳で問題の発生したapp.yamlです。

  • 「/」か、「foo/bar/」とかの末尾/系か、/index.htmlであればpythonを呼び出す
  • それ以外であればdistフォルダからURLに応じたファイルを参照して返却する
  • gaeにアップロードするのは、distフォルダとmain.pyと、.envファイルだけ!

という構成です。一見問題なさそうに見えます。
いや、自分も問題ないだろうと思っていました。
ここでエラーに気づける人は凄いと思います。

エラー!!

gcloud app deploy --project foobar --version 1 app.yaml

ERROR: (gcloud.app.deploy) INVALID_ARGUMENT: The request is invalid.
- '@type': type.googleapis.com/google.rpc.BadRequest
  fieldViolations:
  - description: 'Value "dist\/(?!(index\.html))" must be a valid regular expression.
      Details: invalid or unsupported Perl syntax.'
    field: version.handlers[1].static_files.upload_path_regex
  • 「?!」の正規表現は使えないというエラー……!!
  • そして現れるperl syntaxのエラー
  • googleではperlを使っているのか……というちょっとした驚き

原因は書いてある通り、否定の正規表現「?!」が通らないというエラーでした:sob:

URL and file path patterns use POSIX extended regular expression syntax, excluding collating elements and collation classes. Back-references to grouped matches (e.g. \1) are supported, as are these Perl extensions: \w \W \s \S \d \D.

と書いてあるから仕方ない……

だがしかし

skip_filesでは?!の指定が使えるんですよね!
ドキュメントには書いてある……けれども、skip_filesで使えるのであれば、urlでも使えると嬉しかった……:pensive:

最後に

株式会社ネコカリでは猫の手も借りたい🔥炎上中🔥なお仕事を募集しています!
一緒に働くメンバーも募集していますので、よかったら是非!

9
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
6