GAE Flexible 上具有不同 dockerfile 的多个服务

Kir*_*nov 2 google-app-engine docker google-app-engine-python app-engine-flexible

我在python 环境中使用 Google AppEngine Flexible 。现在我有两个服务:default 和 worker,它们共享相同的代码库,由app.yaml和配置worker.yaml。现在我需要安装本机 C++ 库,所以我不得不切换到自定义运行时并添加 Dockerfile。

这是gcloud beta app gen-config --custom命令生成的Dockerfile

FROM gcr.io/google-appengine/python
LABEL python_version=python3.6

RUN virtualenv --no-download /env -p python3.6

# Set virtualenv environment variables. This is equivalent to running
# source /env/bin/activate
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH
ADD requirements.txt /app/
RUN pip install -r requirements.txt
ADD . /app/
CMD exec gunicorn --workers=3 --threads=3 --bind=:$PORT aces.wsgi
Run Code Online (Sandbox Code Playgroud)

以前我app.yamlworker.yaml每个人都有自己的entrypoint:配置,指定需要运行以启动服务的命令。

所以,我的问题是如何使用两个不同的命令来启动服务?

编辑 1

到目前为止,我能够通过CMD为每个服务的每次部署重写dockerfile 中的行来解决这个问题。但是,我对这个解决方案不太满意。

gcloud app deploy命令具有--image-url允许从 GCR 设置图像 url 的标志。我还没有研究过,但似乎我可以将图像上传到 GCR 并使用网址,因为不经常更改

小智 5

是的,正如您所提到的,我认为使用--image-url标志是一个不错的选择。

指定自定义运行时。在本地构建镜像,标记它,然后将其推送到 Google Container Registry (GCR),然后部署您的服务,指定自定义服务文件,并使用 --image-url 选项在 GCR 上指定远程镜像。

这是在共享相同代码的 2 个服务中完成不同入口点的示例:...这是假设正在使用“flex”而不是“标准”应用程序引擎产品。

假设您有一个:名为my-proj 的项目, 其中有一个不重要的默认服务,另一个名为queue-processor 的服务使用来自同一目录的大部分相同代码。为它创建一个名为QueueProcessorDockerfile的单独 dockerfile 和一个名为queue-processor-app.yaml的单独app.yaml来告诉谷歌应用引擎我想要发生什么。

QueueProcessorDockerfile

FROM node:10
# Create app directory
WORKDIR /usr/src/app
COPY package.json ./
COPY yarn.lock ./
RUN npm install -g yarn
RUN yarn
# Bundle app source
COPY . .
CMD [ "yarn", "process-queue" ]
Run Code Online (Sandbox Code Playgroud)

*当然,我的 package.json 中有一个“进程队列”脚本 queue-processor-app.yaml

runtime: custom
env: flex
... other stuff...
...
Run Code Online (Sandbox Code Playgroud)
  1. 构建并标记 docker 映像在此处查看 googles指南 -> https://cloud.google.com/container-registry/docs/pushing-and-pulling docker build -t eu.gcr.io/my-proj/queue-处理器 -f QueueProcessorDockerfile 。
  2. 将它推送到 GCR docker push eu.gcr.io/my-proj/queue-processor
  3. 部署服务,指定谷歌应该使用哪个 yaml 配置文件,以及你推送的图像 url gcloud app deploy queue-processor-app.yaml --image-url eu.gcr.io/my-proj/queue-processor