【发布时间】:2021-10-25 22:15:40
【问题描述】:
Cloud Build 因超时错误而失败(我正在尝试使用 Prophet 部署 CloudRun)。因此,我试图将 Dockerfile 一分为二(将图像保存在两者之间,以防万一失败)。我会像这样拆分 Dockerfile:
- Dockerfile_one:python + 先知的依赖关系
- Dockerfile_two:image_from_Dockerfile_one + 先知 + 其他依赖项
cloudbuild.yaml 应该是什么样子:
- 如果有以前可用的映像跳过该步骤,否则使用 Dockerfile_one 运行该步骤并保存映像
- 使用步骤(1)中的镜像,添加更多依赖并保存镜像以进行部署
这是 cloudbuild.yaml 现在的样子
steps:
# create gcr source directory
- name: 'bash'
args:
- '-c'
- |
echo 'Creating gcr_source directory for ${_GCR_NAME}'
mkdir _gcr_source
cp -r cloudruns/${_GCR_NAME}/. _gcr_source
# Build the container image
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$PROJECT_ID/${_GCR_NAME}', '.']
dir: '_gcr_source'
# Push the container image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/${_GCR_NAME}']
# Deploy container image to Cloud Run
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: gcloud
args:
- run
- deploy
- ${_GCR_NAME}
- --image=gcr.io/$PROJECT_ID/${_GCR_NAME}
非常感谢!
【问题讨论】:
-
一个更好的设计是保持简单。拥有一个构建基础映像的管道,您可以在需要时运行该管道。另一个使用此基础映像并完成其工作的管道。关注点分离总是更好、更简单、更智能。
-
有道理。我了解如何在第一个管道中保存构建映像。如何从第二个图像中构建?
-
如果您的构建镜像与此名称相同(例如在容器注册表中)
gcr.io/projectid/baseimage,只需使用相同的镜像FROM gcr.io/projectid/baseimage启动您的Dockerfile -
@guillaumeblaquiere 谢谢!这就是我所需要的。我不知道我可以在 FROM 中指定 gcr.io/* 图像。我设法将构建拆分为两个 Dockerfile。在 Python 3.9 上它无论如何都不起作用。看起来 pystan 不适合 Python3.9。在 python3.8 上,即使使用 1 个 Dockerfile 也一切正常,但归根结底,这是一个很好的学习练习。
-
@guillaumeblaquiere 请发表您的评论作为答案,我会接受。
标签: dockerfile google-cloud-build cloudbuild.yaml