简体   繁体   English

如何在 google cloudbuild 中跨连续构建步骤(包括在 docker 步骤中)访问内容

[英]how to access content across successive build steps (including in docker steps) in google cloudbuild

Within Google Cloud Platform, in a multistage cloudbuild process it is possible to use the shared /workspace to access content from one build step to the next.在 Google Cloud Platform 中,在多阶段 cloudbuild 过程中,可以使用共享的/workspace来访问从一个构建步骤到下一个步骤的内容。 For instance the following cloudbuild.yaml would print "hello world" where the text hello is accessed from the first build step.例如,下面的 cloudbuild.yaml 将打印“hello world”,其中文本 hello 是从第一个构建步骤访问的。

steps:
  - name: gcr.io/cloud-builders/gcloud
    entrypoint: 'bash'
    args: [ '-c', " echo world > sample.txt" ]
  - name: gcr.io/cloud-builders/gcloud
    entrypoint: 'bash'
    args: [ '-c', "echo hello $( < sample.txt)" ]

However, it seems this method does not work when it comes to accessing this content in the docker build step.但是,在 docker build 步骤中访问此内容时,此方法似乎不起作用。 There does not appear to be a way to access files within the docker build step.似乎没有办法在 docker build 步骤中访问文件。

The following step, when executed as the third step subsequent to the above steps executes a Dockerfile but doesn't appear to make the sample.txt file available to commands within it.以下步骤作为上述步骤之后的第三步执行时会执行 Dockerfile,但似乎不会使 sample.txt 文件可用于其中的命令。

  # Build the container image
  - name: gcr.io/cloud-builders/docker
    args: ['build',
           '-t', 'repositoryname:latest',
           '.']

I've tried the following:我尝试了以下方法:

  • looking for the default directory named workspace within the container, to no avail.在容器中寻找名为 workspace 的默认目录,但无济于事。
  • creating a custom volume shared across all steps (the custom volume does not appear to be accessible within the Dockerfile scope.创建跨所有步骤共享的自定义卷(自定义卷似乎无法在 Dockerfile 范围内访问。

Is it possible in cloudbuild to progressively build content in a series of steps including docker steps?在 cloudbuild 中是否可以通过包括 docker 步骤在内的一系列步骤逐步构建内容? If so, how could this be done?如果是这样,这怎么可能?

Update更新

Actually it appears the files do remain in a workspace environment.实际上,这些文件似乎确实保留在工作区环境中。 My problem was in not being able to use the content of the file in the build command as follows.我的问题是无法在构建命令中使用文件的内容,如下所示。

  # Build the container image
  - name: gcr.io/cloud-builders/docker
    args: ['build',
           '--build-arg', 'GITHUB_AUTH_TOKEN=$( < sample.txt)',
           '-t', '$_REPO_PATH/$_PROJECT_ID/$_REPO_NAME:$_TAG_NAME',
           '.']

In the first step I am actually using gcloud to get a secret from the secret manager, I then wanted to pass this as an argument to the docker build process.在第一步中,我实际上是使用 gcloud 从秘密管理器获取秘密,然后我想将其作为参数传递给 docker 构建过程。 I could not get the above build step to work, and then I read that command substition does not work on the docker argument?我无法使上述构建步骤起作用,然后我读到命令替换对 docker 参数不起作用?

The problem comes from the args interpretation.问题来自args解释。 Written like this, there isn't any arg evaluation.像这样写,没有任何arg评估。 Use script mode like this像这样使用脚本模式

  # Build the container image
  - name: gcr.io/cloud-builders/docker
    entrypoint: "bash"
    args: 
      - "-c"
      - |
          docker build --build-arg GITHUB_AUTH_TOKEN=$( < sample.txt) -t $_REPO_PATH/$_PROJECT_ID/$_REPO_NAME:$_TAG_NAME .

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

相关问题 如何在 google cloudbuild 步骤中保留变量? - How to persist variables in google cloudbuild steps? 如何使用 Google Ko 构建和推送 Go 映像?你能告诉我 cloudbuild.yaml 创建映像并使用 Google 推送 go 映像的步骤吗? - How to build and push Go image using Google Ko?Could you tell me the steps for cloudbuild.yaml to create the image and push go image using Google ko? 如何在 Google Cloud Build 中构建 Docker 映像并在后续构建步骤中使用? - How can I build a Docker Image in Google Cloud Build and use in later Build Steps? 如何衡量 Docker 构建步骤的持续时间? - How to measure Docker build steps duration? 有没有办法允许 cloudbuild 步骤在 GCP 中访问 Cloud SQL - Is there a way to allow cloudbuild steps to access the Cloud SQL in GCP 如何防止 Docker 构建创建新步骤? - How to prevent Docker build from creating new steps? Docker:仅重新运行一些构建步骤 - Docker: Rerun some build steps only 如何在这些构建步骤中使用 Jenkinsfile? - How to use a Jenkinsfile for these build steps? 重用 docker 构建映像中的步骤。 缓存? - Reuse steps in docker build image. Cache? jenkins 管道 - 如何在声明性管道步骤中使用 powershell 命令构建 docker 镜像 - jenkins pipeline - how to build a docker image in a declarative pipeline steps use powershell command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM