我刚刚了解到,使用Kaniko缓存可以加快Google Cloud build中的构建过程。我看了文档,它提供了一个小示例。然而,我不确定如何在我的用例中应用它。我基本上是在向我的Github存储库推送Nuxt应用程序,每次我推送时,云计算都会构建它。文档示例说明我们需要用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']发布于 2021-02-23 18:16:11
Kaniko没有推送和构建命令。当您在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"https://stackoverflow.com/questions/66165014
复制相似问题