具有内部历史记录的GC Cloud Build自定义构建过程

时间:2018-11-05 12:56:17

标签: docker google-app-engine google-cloud-platform google-compute-engine google-cloud-build

我必须使用GC Cloud Build配置GC AppEngine应用程序的自定义生成过程。
首先-我在GC ComputeEngine实例上有一个内部python存储库。它只能通过内部网络访问,我使用Remote-builder在内部GC实例上运行pip install命令。
从内部存储库下载依赖项后,我必须将结果部署到GC AppEngine中。

Cloudbuild.yaml
steps: /#Download dependencies from the internal repository - name: gcr.io/${ProjectName}/remote-builder env: - COMMAND=sudo bash workspace/download-dependencies.bash - ZONE=us-east1-b - INSTANCE_NAME=remote-cloud-build - INSTANCE_ARGS=--image-project centos-cloud --image-family centos-7 - name: gcr.io/cloud-builders/docker args: ['build', '-t', 'gcr.io/${ProjectName}/app', '.'] - name: gcr.io/cloud-builders/docker args: ['push', 'gcr.io/${ProjectName}/app'] - name: gcr.io/cloud-builders/gcloud args: ['app', 'deploy', 'app.yaml', '--image-url=gcr.io/${ProjectName}/${ProjectName}'] images: ['gcr.io/${ProjectName}/${ProjectName}']

app.yaml:
runtime: python env: flex entrypoint: python main.py service: service-name runtime_config: python_version: 3

Dockerfile:
FROM gcr.io/google-appengine/python WORKDIR /app COPY . /app

download-dependencies.bash:
#!/usr/bin/env bash easy_install pip pip install --upgrade pip pip install --upgrade setuptools pip install -r workspace/requirements.txt'

运行gcloud builds submit --config cloudbuild.yaml 后,新版本的应用程序已部署到AppEngine上,但无法正常运行

问题可能出在错误的图像上吗?据我了解,我需要配置Dockefile以将所有自定义python依赖项收集到映像中。
你能帮我吗
提前谢谢!

更新 我根据Google指南更改了Dockerfile:
FROM gcr.io/google-appengine/python RUN virtualenv /env ENV VIRTUAL_ENV /env ENV PATH /env/bin:$PATH ADD . /app CMD main.py
而新的错误是:/bin/sh: 1: main.py: not found
如果我将最后一行更改为:CMD app/main.py-它会创建版本并且不起作用

1 个答案:

答案 0 :(得分:1)

最后,我完成了。有一些问题,我将在下面分享正确的配置。希望它能对某人有所帮助。

steps:
# Move our code to instance inside the project to have access to the private repo
- name: gcr.io/${PROJECT_NAME}/remote-builder
  env:
  - COMMAND=sudo bash workspace/download-dependencies.bash:
  - ZONE=us-east1-b
  - INSTANCE_NAME=remote-cloud-build
  - INSTANCE_ARGS=--image-project centos-cloud --image-family centos-7
#Build image with downloaded deps
- name: gcr.io/cloud-builders/docker
  args: ['build', '-t', 'gcr.io/${PROJECT_NAME}/${APP_NAME}', '.']
#Push image to project repo
- name: gcr.io/cloud-builders/docker
  args: ['push', 'gcr.io/${PROJECT_NAME}/${APP_NAME}']
#Deploy image to AppEngine
- name: gcr.io/cloud-builders/gcloud
  args: ['app', 'deploy', 'app.yaml', '--image-url=gcr.io/${PROJECT_NAME}/${APP_NAME}']
images: ['gcr.io/${PROJECT_NAME}/${APP_NAME}']
timeout: '1800s'

download-dependencies.bash:

#!/usr/bin/env bash
easy_install pip

pip install --upgrade pip
pip install --upgrade setuptools
pip install wheel
#Download private deps and save it to volume (share folder between steps)
pip wheel --no-deps -r workspace/private-dependencies.txt -w workspace/lib --no-binary :all:

Dockerfile:

FROM gcr.io/google-appengine/python
COPY . /${APP_NAME}
RUN virtualenv /env


ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH

RUN pip install -r /${APP_NAME}/workspace/public-dependencies.txt
#Install private deps from volume
RUN pip install -f /${APP_NAME}/workspace/lib --no-index ${LIBRARY_NAME}

CMD gunicorn -b :$PORT main:app