gcloud dev_appserver.py 启动 Dart 托管 VM 时出错

gcloud dev_appserver.py error while starting Dart Managed VM

我按照 tutorial 中的描述为 AppEngine 配置了一个 Dart 托管 VM。它已经过时并且仍然使用现在删除的 gcloud preview app run 而不是 dev_appserver.py。然而,我发现其他人成功地为 Dart VM 使用了 dev_appserver.py,但我收到以下错误:

$ dev_appserver.py app.yaml --runtime custom
INFO     2015-12-11 12:19:50,907 application_configuration.py:431] No version specified. Generated version id: 20151211t121950
INFO     2015-12-11 12:19:50,908 devappserver2.py:769] Skipping SDK update check.
INFO     2015-12-11 12:19:50,939 api_server.py:205] Starting API server at: http://localhost:36858
INFO     2015-12-11 12:19:50,951 api_server.py:648] Applying all pending transactions and saving the datastore
INFO     2015-12-11 12:19:50,951 api_server.py:651] Saving search indexes
Traceback (most recent call last):
  File "/opt/google/cloud-sdk/platform/google_appengine/dev_appserver.py", line 83, in <module>
    _run_file(__file__, globals())
  File "/opt/google/cloud-sdk/platform/google_appengine/dev_appserver.py", line 79, in _run_file
    execfile(_PATHS.script_file(script_name), globals_)
  File "/opt/google/cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 1040, in <module>
    main()
  File "/opt/google/cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 1033, in main
    dev_server.start(options)
  File "/opt/google/cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 824, in start
    self._dispatcher.start(options.api_host, apis.port, request_data)
  File "/opt/google/cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/dispatcher.py", line 194, in start
    _module.start()
  File "/opt/google/cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/module.py", line 1548, in start
    self._add_instance()
  File "/opt/google/cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/module.py", line 1700, in _add_instance
    expect_ready_request=True)
  File "/opt/google/cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/custom_runtime.py", line 83, in new_instance
    assert self._runtime_config_getter().custom_config.custom_entrypoint
AssertionError

我的 Dockerfile 已经到位并且 app.yaml 是正确的。我在 IntelliJ 中创建了一个示例 Dart AppEngine 项目,并根据教程检查了创建文件的内容。

This post from the e-mail list 建议使用 --custom_entrypoint 选项。我试过了,但收到了这个错误信息。似乎在调用 Dart 入口点之前应用服务器正在声明该端口。

$ dev_appserver.py app.yaml --custom_entrypoint "dart bin/server.dart --port=8080"
INFO     2015-12-11 12:41:13,334 application_configuration.py:431] No version specified. Generated version id: 20151211t124113
INFO     2015-12-11 12:41:13,334 devappserver2.py:769] Skipping SDK update check.
INFO     2015-12-11 12:41:13,363 api_server.py:205] Starting API server at: http://localhost:44617
INFO     2015-12-11 12:41:13,375 dispatcher.py:197] Starting module "default" running at: http://localhost:8080
INFO     2015-12-11 12:41:13,376 admin_server.py:116] Starting admin server at: http://localhost:8000
Unhandled exception:
SocketException: Failed to create server socket (OS Error: Address already in use, errno = 98), address = 0.0.0.0, port = 8080
#0      _NativeSocket.bind.<anonymous closure> (dart:io-patch/socket_patch.dart:494)
#1      _rootRunUnary (dart:async/zone.dart:914)
#2      _CustomZone.runUnary (dart:async/zone.dart:810)
#3      _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:502)
#4      _Future._propagateToListeners (dart:async/future_impl.dart:585)
#5      _Future._completeWithValue (dart:async/future_impl.dart:376)
#6      _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:430)
#7      _rootRun (dart:async/zone.dart:907)
#8      _CustomZone.run (dart:async/zone.dart:802)
#9      _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:735)
#10     _microtaskLoop (dart:async/schedule_microtask.dart:43)
#11     _microtaskLoopEntry (dart:async/schedule_microtask.dart:52)
#12     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:96)
#13     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:151)
^CTraceback (most recent call last):
  File "/opt/google/cloud-sdk/bin/dev_appserver.py", line 35, in <module>
    main()
  File "/opt/google/cloud-sdk/bin/dev_appserver.py", line 29, in main
    os.path.join('platform', 'google_appengine'), 'dev_appserver.py', *args)
  File "/opt/google/cloud-sdk/bin/bootstrapping/bootstrapping.py", line 45, in ExecutePythonTool
    execution_utils.ArgsForPythonTool(_FullPath(tool_dir, exec_name), *args))
  File "/opt/google/cloud-sdk/bin/bootstrapping/bootstrapping.py", line 86, in _ExecuteTool
    execution_utils.Exec(args + sys.argv[1:], env=_GetToolEnv())
  File "/opt/google/cloud-sdk/lib/googlecloudsdk/core/execution_utils.py", line 209, in Exec
INFO     2015-12-11 12:41:37,298 shutdown.py:45] Shutting down.
    ret_val = p.wait()
  File "/usr/lib64/python2.7/subprocess.py", line 1384, in wait
INFO     2015-12-11 12:41:37,298 api_server.py:648] Applying all pending transactions and saving the datastore
    pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
  File "/usr/lib64/python2.7/subprocess.py", line 476, in _eintr_retry_call
    return func(*args)
KeyboardInterruptINFO     2015-12-11 12:41:37,298 api_server.py:651] Saving search indexes

该教程已过时,您不能再执行此操作。

原因是您使用的是自定义运行时间(教程中的app.yamlruntime: custom)。

自定义运行次不能再在开发服务器上运行!!!(见

可以 运行 应用程序,但您必须部署到 App Engine 服务器。

我认为在这里正确的做法是指定一个运行您的 dart 服务器应用程序的自定义入口点,因为 --runtime 仅适用于特定支持的兼容运行时。查看 dev_appserver.py 的错误输出:

google.appengine.tools.devappserver2.errors.InvalidAppConfigError: 
Must set either --runtime or --custom_entrypoint.  
For a standard runtime, set the --runtime flag with one of 
['java-compat', 'java', 'php55', 'python', 'custom', 
'python-compat', 'java7', 'python27', 'go'].  
For a custom runtime, set the --custom_entrypoint with a command to start your app.