Ben*_*ite 1 google-cloud-platform google-cloud-run
我使用https://www.starlette.io/和 docker 镜像创建了一个 API,python:3.7-slim-stretch并且在本地以及部署在 AWS ECS 上时一切正常。
但是当我尝试在 Google Cloud Run 上部署相同的应用程序时,我无法收到任何请求。我可以使用根域上的浏览器访问服务器,/但是当我尝试访问时,/prediction-url我收到诸如Error: Stream error in the HTTP/2 framing layer或 之类的响应错误Service unavailable。尝试使用 Insomnia、javascript 请求以及 curl 请求访问 API。奇怪的是,一切都在 AWS ECS 上 100% 运行,但我无法在 Googl Cloud Run 上运行。部署到 Google Cloud Run 时有什么具体需要考虑的吗?
请求路由定义:
@app.route("/classify-url", methods=["GET"])
@requires("authenticated")
async def classify_url(request):
img_bytes = await get_bytes(request.query_params["url"])
return await predict_image_from_bytes(img_bytes)
Run Code Online (Sandbox Code Playgroud)
服务器启动命令:
if __name__ == "__main__":
if "serve" in sys.argv:
# int(os.environ.get('PORT', 8080))
uvicorn.run(app, host="0.0.0.0", port=8080, log_level="info")
Run Code Online (Sandbox Code Playgroud)
码头档案:
FROM python:3.7-slim-stretch
RUN apt-get update && apt-get install -y git python3-dev gcc \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --upgrade -r requirements.txt
COPY . .
EXPOSE 8080
EXPOSE 8000
EXPOSE 80
ENV LISTEN_PORT=8080
# Start the server
CMD ["gunicorn", "-w 1", "-k uvicorn.workers.UvicornWorker", "-b 0.0.0.0:8080", "-t 8", "main:app"]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4507 次 |
| 最近记录: |