[英]How to use Kaniko in cloudbuild.yaml?
I just learned that one can speed up the build process in Google Cloud build by using Kaniko cache.我刚刚了解到可以通过使用 Kaniko 缓存来加快 Google Cloud 构建中的构建过程。 I looked at the docs and it provided a small example.
我查看了文档,它提供了一个小例子。 However, I'm not sure how to apply it in my use case.
但是,我不确定如何在我的用例中应用它。 I am basically pushing a Nuxt app into my Github repo and cloud builds it every time I make a push.
我基本上是在将 Nuxt 应用程序推送到我的 Github 存储库中,并且每次推送时云都会构建它。 The docs example says we need to replace
cloud-builders/docker
with kaniko-project/executor:latest
.文档示例说我们需要用
kaniko-project/executor:latest
替换cloud-builders/docker
docker。 Below is a snippet of my cloudbuild.yaml
下面是我的
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 says I need the following: Kaniko docs说我需要以下内容:
steps:
- name: 'gcr.io/kaniko-project/executor:latest'
args:
- --destination=gcr.io/$PROJECT_ID/image
- --cache=true
- --cache-ttl=XXh
This is what I tried (but not sure if that's how it should be):这是我尝试过的(但不确定是否应该这样):
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 doesn't have push and build command. Kaniko 没有推送和构建命令。 It will do that implicitly (build and push) when you specify it as a build step in cloudbuild.yaml.
当您在 cloudbuild.yaml 中将其指定为构建步骤时,它将隐式执行此操作(构建和推送)。
an example would be:一个例子是:
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"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.