如何在cloudbuild.yaml中使用Kaniko ?



我刚刚了解到可以通过使用Kaniko缓存来加快Google Cloud构建中的构建过程。我看了一下文档,它提供了一个小例子。然而,我不确定如何在我的用例中应用它。我基本上是将next应用程序推送到我的Github仓库中,每次推送时云都会构建它。docs的例子说我们需要用kaniko-project/executor:latest代替cloud-builders/docker。下面是我的cloudbuild.yaml代码片段

steps:
# Create .npmrc file from Fontawesome secret
- name: gcr.io/cloud-builders/gcloud
entrypoint: 'bash'
args: [ '-c', 'gcloud secrets versions access latest --secret=fontawesome > .npmrc' ]
# Build the container image
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/PROJECTNAME/IMAGENAME:$COMMIT_SHA', '.']
# Push the image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/PROJECTNAME/IMAGENAME:$COMMIT_SHA']

Kaniko docs说我需要以下文件:

steps:
- name: 'gcr.io/kaniko-project/executor:latest'
args:
- --destination=gcr.io/$PROJECT_ID/image
- --cache=true
- --cache-ttl=XXh

这就是我所尝试的(但不确定是否应该这样):

steps:
# Create .npmrc file from Fontawesome secret
- name: gcr.io/cloud-builders/gcloud
entrypoint: 'bash'
args: [ '-c', 'gcloud secrets versions access latest --secret=fontawesome > .npmrc' ]
# Build the container image
- name: 'gcr.io/kaniko-project/executor:latest'
args: ['--destination=gcr.io/$PROJECT_ID/image', '--cache=true', '--cache-ttl=6h'
,'build', '-t', 'gcr.io/PROJECTNAME/IMAGENAME:$COMMIT_SHA', '.']
# Push the image to Container Registry
- name: 'gcr.io/kaniko-project/executor:latest'
args: ['--destination=gcr.io/$PROJECT_ID/image', '--cache=true', '--cache-ttl=6h'
, 'push', 'gcr.io/PROJECTNAME/IMAGENAME:$COMMIT_SHA']

Kaniko没有push和build命令。当您在cloudbuild.yaml中将其指定为构建步骤时,它将隐式地执行此操作(构建和推送)。

的例子是:

steps:
# Build the container image and push it with Kaniko
- name: 'gcr.io/kaniko-project/executor:latest'
args:
[
"--dockerfile=<DOCKER-FILE-DIST>",
"--context=dir://<BUILD_CONTEXT>",
"--cache=true",
"--cache-ttl=6h",
"--destination=gcr.io/$PROJECT_ID/hello:$COMMIT_SHA"
]
# Deploy image to Cloud Run
- name: "gcr.io/cloud-builders/gcloud"
args:
- "run"
- "deploy"
- "hello"
- "--image"
- "gcr.io/$PROJECT_ID/hello:$COMMIT_SHA"
- "--region"
- "us-central1"
- "--platform"
- "managed"

相关内容

  • 没有找到相关文章

最新更新