简体   繁体   English

如何在 cloudbuild.yaml 中使用 Kaniko?

[英]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.

相关问题 问:如何配置 cloudbuild.yaml 运行测试? - Q: How to configure cloudbuild.yaml to run tests? 如何设置谷歌云 Cloudbuild.yaml 以复制 jenkins 作业? - How to setup google cloud Cloudbuild.yaml to replicate a jenkins job? 我的 cloudbuild.yaml 失败了。 请查看我的 cloudbuild.yaml - My cloudbuild.yaml is failing. Please review my cloudbuild.yaml 如何在 GCP 中使用 cloudbuild.yaml 创建 CI/CD 管道? - How can I create CI/CD pipeline with cloudbuild.yaml in GCP? 如何通过 cloudbuild.yaml 在构建过程中正确获取/设置 env vars? - How to properly get/set env vars during the build via cloudbuild.yaml? 在嵌套文件夹中使用 cloudbuild.yaml 进行 Cloud Build - 构建失败 - Cloud Build w/ cloudbuild.yaml in nested folder - build fails Google Cloud Build - Dockerfile 和 cloudbuild.yaml 的不同范围 - Google Cloud Build - Different scopes of Dockerfile and cloudbuild.yaml cloudbuild.yaml 上的错误:(gcloud.builds.submit)将 cloudbuild.yaml 解释为构建配置:'list' object 没有属性'ms' - Error on cloudbuild.yaml : (gcloud.builds.submit) interpreting cloudbuild.yaml as build config: 'list' object has no attribute 'items' 如何使用 Google Ko 构建和推送 Go 映像?你能告诉我 cloudbuild.yaml 创建映像并使用 Google 推送 go 映像的步骤吗? - How to build and push Go image using Google Ko?Could you tell me the steps for cloudbuild.yaml to create the image and push go image using Google ko? 我是否需要将通过 CLI 提供的替代值添加到 cloudbuild.yaml 文件中? - Do I need to add substituions values that I'll provide via CLI to the cloudbuild.yaml file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM