编写cloudbuild.yaml 时有几个关键参数
entrypoint 和 args 的基本介绍
id: 显示在 cloud build logs 里的item 名字
name: docker 镜像名字 - 下面的命令会在这个镜像的1个容器instance 内执行
entrypoint: 执行的命令入口 , 只能有1个对象
args: 命名的参数, 它是1个list
问题来了, 如何理解深而慢是entrypoint 和 args
entrypoint 就是执行的命令 bin file 名字, args 是参数, 不能混淆
例如:
cat /tmp/1.txt /tmp/2.txt
中
cat 就entrypoint
/tmp/1.txt /tmp/2.txt 就是两个参数, 因为args 是1个list
又如:
echo abc def
中, echo 是 entrypoint, args 是 [abc, def]
所以在clouldbuild.yaml 中下面command 1是正确的, command 2 是错误的
steps:
# correct
- id: test command 1
name: 'gcr.io/cloud-builders/gcloud'
entrypoint: echo
args: [abc, def]
# wrong
- id: test command 2
name: 'gcr.io/cloud-builders/gcloud'
entrypoint: echo abc
args: [ def ]
logsBucket: gs://jason-hsbc_cloudbuild/logs/
options: # https://cloud.google.com/cloud-build/docs/build-config#options
logging: GCS_ONLY # or CLOUD_LOGGING_ONLY https://cloud.google.com/cloud-build/docs/build-config#logging
因为第2中写法, 它把 echo abc 作为endpoint, 虽然合并字符串 也是 echo abc def, 跟 command 1 的写法一样, 但是yaml 中命令的写法绝对不是字符串
而镜像中的 /usr/bin 中绝对不可能有1个 echo abc 包括空格的file, 所以会出错
日志
starting build "34e39f7f-e039-4572-a392-21a154ed8228"
FETCHSOURCE
Fetching storage object: gs://jason-hsbc_cloudbuild/source/1717185531.688094-1bcec1bbcfb64618b377c2a5e097c551.tgz#1717185513807965
Copying gs://jason-hsbc_cloudbuild/source/1717185531.688094-1bcec1bbcfb64618b377c2a5e097c551.tgz#1717185513807965...
/ [0 files][ 0.0 B/ 73.9 KiB]
-
- [1 files][ 73.9 KiB/ 73.9 KiB]
Operation completed over 1 objects/73.9 KiB.
tar: cloudbuild-test.yaml: time stamp 2024-05-31 19:58:47.9453259 is 4.465130295 s in the future
BUILD
Starting Step #0 - "test command 1"
Step #0 - "test command 1": Already have image (with digest): gcr.io/cloud-builders/gcloud
Step #0 - "test command 1": abc def
Finished Step #0 - "test command 1"
Starting Step #1 - "test command 2"
Step #1 - "test command 2": Already have image (with digest): gcr.io/cloud-builders/gcloud
Finished Step #1 - "test command 2"
ERROR
ERROR: build step