【发布时间】:2019-09-23 23:29:33
【问题描述】:
我有一个生成文件的非常简单的容器(实际上是Cloud Build quickstart 示例代码)。我正在尝试扩展此容器以通过storing non-image artifacts with Cloud Build 上的文档将所述文件上传到存储桶。
我的 Dockerfile 构建一个简单的容器并执行一个脚本:
FROM alpine
WORKDIR /app
COPY . /app # the only file present is quickstart.sh
CMD ["./quickstart.sh"]
脚本(quickstart.sh)生成一个简单的时间戳文件:
#!/bin/sh
echo "Creating file 'time.txt'"
echo "The time is $(date)" > time.txt
## for debugging:
# pwd
# ls
# cat time.txt
我的 cloudbuild.yaml 文件基本上是从上述文档中复制粘贴的,并配置为上传文件:
steps:
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/quickstart-image', '.' ]
artifacts:
objects:
location: 'gs://my-bucket/'
paths: ['*.txt']
images:
- 'gcr.io/$PROJECT_ID/quickstart-image'
但是,文件无法上传,因此构建失败。当我运行构建命令时
gcloud builds submit --config cloudbuild.yaml .
所有日志都成功到最后:
Artifacts will be uploaded to gs://my-bucket using gsutil cp
*.txt: Uploading path....
CommandException: No URLs matched: *.txt
CommandException: 1 file/object could not be transferred.
ERROR
ERROR: could not upload *.txt to gs://my-bucket/; err = exit status 1
gsutil 声称找不到匹配的文件。但是,如果我手动构建并生成文件,我可以使用gsutil cp *.txt gs://my-bucket/ 毫无问题地上传文件。因此,就好像在 Cloud Build 到达“上传工件”步骤之前文件已被擦除,但这似乎没有意义。我想这是一个非常常见的用例,但我并没有单独在文档方面取得任何进展。有任何想法吗?谢谢。
【问题讨论】:
-
您在脚本中使用了相对路径。相反,在输出和输入文件名中使用完整路径。原因是您正在对 shell 和程序的默认工作目录进行假设(通过忽略它们)。
-
谢谢@JohnHanley。你说的很有道理。但是,更新 shell 脚本以写入完整路径 (
/app/time.txt) 并更新 yaml 配置以读取完整路径 (/app/*.txt、/**/*.txt、**/*.txt) 仍然会产生相同的错误 :( 知道我是什么可能会丢失吗? -
查看 Cloud Build 服务帐号的角色。它有写入你的存储桶的作用吗?
-
@guillaumeblaquiere Cloud Build 服务帐户角色能够写入存储桶。我可以在构建时成功将文件写入存储桶如果它们已经存在于本地目录中。只有
quickstart.sh动态生成的文件写入失败。
标签: docker google-cloud-platform cloud google-cloud-storage google-cloud-build