首页 > 解决方案 > 将 URL 路由到 GAE Flex 服务器,而站点的其余部分在 GAE 标准上运行

问题描述

使用 Google App Engine 标准 Python 2.7,我的 dispatch.yaml 中有一个路径来指定所有类型为“*/flex/*”的 url,以路由到 flex 服务。

dispatch.yaml 调度:

- url: '*/flex/*'
    module: flex

flex 环境是一个自定义的 python 3.7 运行时,通常使用以下命令执行:

python dev_appserver.py flex.yaml --custom_entrypoint="docker run -p 9090:8080 flex_app".

对于我环境中的其他服务,我尝试使用以下命令启动开发环境: python dev_appserver.py dispatch.yaml default.yaml sync.yaml task.yaml flex.yaml --custom_entrypoint="docker run -p 9090:8080 flex_app" --port=8080 --skip_sdk_update_check"

但是,当它开始时,当我需要从端口 9090 访问 flex 服务时,它开始为每个服务分配本地 IP 地址。

示例服务器输出:

INFO     devappserver2.py:278] Skipping SDK update check.
INFO     dispatcher.py:223] Starting dispatcher running at: http://0.0.0.0:8080
INFO     dispatcher.py:256] Starting module "default" running at: http://0.0.0.0:8081
INFO     dispatcher.py:256] Starting module "sync" running at: http://0.0.0.0:8082
INFO     dispatcher.py:256] Starting module "task" running at: http://0.0.0.0:8083
INFO     dispatcher.py:256] Starting module "flex" running at: http://0.0.0.0:8084

如果我点击 URL localhost:9090,我就能成功访问 flex 应用程序。但是,如果我访问 localhost:8084 或 localhost:8080/flex/,我会收到错误消息:

503 - This request has timed out.

服务器日志反映了这一点,但没有显示实际错误:

INFO module.py:861] flex: "GET / HTTP/1.1" 503 59

是否可以将 GAE 标准环境中的 url 分派到 Flex 环境,并将其从指定端口路由到所需的所需端口?我认为这是可能的,因为Google App Engine 的文档指定可以将环境混合在一起。我还尝试通过强制 docker 在端口 8084 上运行来解决此问题,但端口无法共享。

标签: pythongoogle-app-enginegoogle-app-engine-python

解决方案


通过查看找到了这个dev_appserver.py --help。事实证明,这个问题的答案只是将 custom_entrypoint 更改为命令docker run -p {port}:8080 flex_app,这会自动将 GAE 随机分配的端口转发到 docker 实例。

--custom_entrypoint CUSTOM_ENTRYPOINT
                        specify an entrypoint for custom runtime modules. This
                        is required when such modules are present. Include
                        "{port}" in the string (without quotes) to pass the
                        port number in as an argument.

推荐阅读