文系プログラマによるTIPSブログ

文系プログラマ脳の私が開発現場で学んだ事やプログラミングのTIPSをまとめています。

GAE/GOでgoapp serveした時に起きるThere are too many filesに対応する

ファイル数が多すぎるとエラーになるんですよね〜
f:id:treeapps:20160521191008p:plain

GAEで開発している時に、node.jsを使いたい時ってありますよね。
普通にnpm init してnpm installして開発していくわけですが、例えばGAE/GOで開発中にgoapp serveすると以下のエラーが発生する場合があります。

tree:tree-maps-go tree$ goapp serve
INFO     2016-12-05 12:41:32,635 devappserver2.py:756] Skipping SDK update check.
INFO     2016-12-05 12:41:32,731 api_server.py:205] Starting API server at: http://localhost:62066
INFO     2016-12-05 12:41:32,734 dispatcher.py:197] Starting module "default" running at: http://localhost:8080
INFO     2016-12-05 12:41:32,736 admin_server.py:116] Starting admin server at: http://localhost:8000
/usr/local/go_appengine/google/appengine/tools/devappserver2/mtime_file_watcher.py:129: UserWarning: There are too many files in your application for changes in all of them to be monitored. You may have to restart the development server to see some changes to your files.
  'There are too many files in your application for '

何が起きているかというと、goapp serveによってファイル監視が行われるわけですが、監視するファイル数が多過ぎるため、警告が表示されています。

特にnpm installすると、node_modules以下に大量の依存モジュールが配置されてしまい、goapp serveがすぐギブアップしてしまいます。

現象が起きる環境

状況が再現するSDKバージョンは以下の通りです。

tree:tree-maps-go tree$ goapp version
go version go1.6.3 (appengine-1.9.46) darwin/amd64

このSDKバージョンは最新に近いバージョンなのですが、このバージョンでもこの警告が発生します。

解決法

まず、警告が出ているファイルはmtime_file_watcher.pyなので、mtime_file_watcher.pyを修正します。

修正対象ファイル

$APPENGINE_HOME/google/appengine/tools/devappserver2/mtime_file_watcher.py

修正前

    for dirpath, dirnames, filenames in os.walk(self._directory,
                                                followlinks=True):

      if self._quit_event.is_set():

修正後

    for dirpath, dirnames, filenames in os.walk(self._directory,
                                                followlinks=True):

      if '/node_modules/' in dirpath: continue

      if self._quit_event.is_set():


これでnode_modulesフォルダの監視がスキップされ、次回goapp serveした際に警告が表示されなくなります。

もしnode_modules以外で同様の現象が起きてしまう場合、or句で複数条件を記述して下さい。

node_modulesをデプロイ対象から外す

これでgoapp serveできるようになりましたが、このままではgoapp deployした時にnode_modulesフォルダもデプロイ対象に入ってしまいます。GAEはデプロイできるファイル数に上限があるので、これはいただけません。

そんな場合は、app.yamlに以下の記述を追加すると、node_modulesディレクトリをデプロイ対象から外す事ができます。

skip_files:
  - ^(node_modules/.*)

続き

以下の記事と本記事よりもっと根本的な解決策について書きました。
www.bunkei-programmer.net