【问题标题】:Google cloud build - provide assets to docker build step谷歌云构建 - 向 docker build 步骤提供资产
【发布时间】:2020-09-07 21:06:39
【问题描述】:

我正在尝试结合 Google Cloud Build 文档中的两个示例

This example where a container is built using a yaml file

And this example where a persistent volume is used

我的场景很简单,构建的第一步会生成一些我想捆绑到后续步骤中构建的 Docker 映像中的资产。但是,由于COPY 命令是relative to the build directory of the image,我无法确定如何在用于第二步的 Dockerfile 中引用第一步中的资产。

【问题讨论】:

  • 如果您解决了您赢得的问题,请将其标记为正确,如果您遗漏了什么,请使用更新的代码编辑问题,以便我们更好地为您提供帮助
  • 嗨@Edgardo,这是一篇“问答风格”的帖子。您必须等待 2 天才能接受您自己的答案。我会尽快这样做;)

标签: google-cloud-build


【解决方案1】:

可能有多种方法可以解决此问题,但我发现最简单的方法是使用 docker cloud builder 并运行 sh 脚本(因为 docker 映像中不包含 Bash)。

在此示例中,我们以问题中的示例为基础,在第一个构建步骤中生成资产 file,然后在第二步的 Dockerfile 中使用它。

cloudbuild.yaml

steps:
- name: 'ubuntu'
  volumes:
  - name: 'vol1'
    path: '/persistent_volume'
  entrypoint: 'bash'
  args:
  - '-c'
  - |
        echo "Hello, world!" > /persistent_volume/file
- name: 'gcr.io/cloud-builders/docker'
  entrypoint: 'sh'
  volumes:
  - name: 'vol1'
    path: '/persistent_volume'
  args: [ 'docker-build.sh' ]
  env:
    - 'PROJECT=$PROJECT_ID'
images:
- 'gcr.io/$PROJECT_ID/quickstart-image'

docker-build.sh

#/bin/sh
cp -R /persistent_volume .
docker build -t gcr.io/$PROJECT/quickstart-image .

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-08
    • 1970-01-01
    • 2020-12-25
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多