简体   繁体   English

在 Google App Engine 上部署 Flask 和 Tensorflow 服务

[英]Deploy Flask and Tensorflow serving on Google App Engine

I want to deploy Flask API with gunicorn and tensorflow serving to Google App Engine (Flex).我想将带有 gunicorn 和 tensorflow 的 Flask API 部署到 Google App Engine (Flex)。 I wrote a Dockerfile and startup.sh but fails to deploy.我写了一个 Dockerfile 和 startup.sh 但部署失败。 I increased memory to 6GB and set timeout 2 min for gunicorn, but it doesn't help.我将内存增加到 6GB,并为 gunicorn 设置了 2 分钟的超时时间,但这没有帮助。

Dockerfile runs successfully but startup.sh doesn't launch both of gunicorn and tensorflow serving. Dockerfile 运行成功,但 startup.sh 不会同时启动 gunicorn 和 tensorflow 服务。 Can anybody point out what's wrong in sartup.sh?有人能指出 sartup.sh 有什么问题吗?

Dockerfile文件

FROM gcr.io/google-appengine/python

RUN virtualenv /env -p python3.7
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH

RUN apt-get update
ADD app/ /app/
RUN pip install --upgrade pip
RUN pip install -r /app/requirements.txt

RUN echo "deb http://storage.googleapis.com/tensorflow-serving-apt stable tensorflow-model-server tensorflow-model-server-universal" | tee /etc/apt/sources.list.d/tensorflow-serving.list && \
curl https://storage.googleapis.com/tensorflow-serving-apt/tensorflow-serving.release.pub.gpg | apt-key add -
RUN apt-get update
RUN apt-get install -y tensorflow-model-server

RUN apt-get install -y nginx
COPY app/default /etc/nginx/sites-available/default

WORKDIR /root

RUN chmod -R a+r /var/www/html

COPY startup.sh /startup.sh
RUN chmod 744 /startup.sh
RUN cd /
CMD /startup.sh

startup.sh启动文件

#!/bin/bash
/etc/init.d/nginx start
cd /app && nohup gunicorn app:app --bind 127.0.0.1:8081 --workers 1 --timeout 120 &
nohup tensorflow_model_server \
  --rest_api_port=8501 \
  --model_name=bird_net \
  --model_base_path=/app/saved_model &

Standard error output标准错误输出

$ gcloud app deploy
...
(ommited)
...
bc9f3e1065bb: Pushed
latest: digest: sha256:8dd67b5292199744a51d58c3cafb5ff17b87c4b39e35589c0d44e646dc1dd272 size: 5567
DONE
---------------------------------------------------------------------------------------------------------------------------------------------------------------

Updating service [default] (this may take several minutes)...failed.                                                                                          
ERROR: (gcloud.app.deploy) Error Response: [9] 
Application startup error! Code: APP_CONTAINER_CRASHED
 * Starting nginx nginx
   ...done.

I solved.我解决了。 Docker needs at least one foreground process. Docker 至少需要一个前台进程。

#!/bin/bash
set -m
/etc/init.d/nginx start
cd /app
gunicorn app:app --bind 127.0.0.1:8081 --workers 1 --timeout 120 &
tensorflow_model_server \
  --rest_api_port=8501 \
  --model_name=birdnet \
  --model_base_path=/app/saved_model
fg %1

References参考
https://docs.docker.com/config/containers/multi-service_container/ https://docs.docker.com/config/containers/multi-service_container/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM