【问题标题】:Google Cloud Build with Kaniko is not caching, all dockerbuilds start from scratch each time带有 Kaniko 的 Google Cloud Build 没有缓存,所有 dockerbuild 每次都从头开始
【发布时间】:2022-08-13 22:08:56
【问题描述】:

我有一个谷歌云触发器,它连接到我构建 docker 容器的 github 存储库。但是当我更新我的代码时,它需要很长时间才能构建,所以我希望它通过将谷歌触发器配置从之前设置的Dockerfile 更改为Cloud Build configuration file 来缓存它(通过将它设置为 dockerfile 它确实需要很长一段时间就像提到的那样)。

我的 cloudbuild.yaml 看起来像这样:

steps:
- name: \'gcr.io/kaniko-project/executor:latest\'
  args:
  - --destination=gcr.io/project/github.com/user/repo_name:$COMMIT_SHA
  - --cache=true
  - --cache-ttl=6h
  - --dockerfile=Dockerfile
timeout: 7200s

但是当我像这样运行它时,它总是从头开始,即使它构建它,它也不会显示在容器注册表的图像部分下,我的构建通常注册到以及我希望它们在哪里。

我怎样才能让我的 kaniko 缓存我的构建,这样每次我提交到我的 github 时都不会花费太多时间?

使用 kubernetes 和 docker 进行构建。

    标签: docker google-cloud-platform kaniko


    【解决方案1】:

    如果您使用 Docker 镜像构建,您可以使用 --cache-from

    提高 Docker 映像构建速度的最简单方法是 指定可用于后续构建的缓存图像。你 可以通过添加 --cache-from 参数来指定缓存的图像 您的构建配置文件,它将指示 Docker 使用该文件进行构建 图像作为缓存源。

    YAML 示例

    steps:
    - name: 'gcr.io/cloud-builders/docker'
      entrypoint: 'bash'
      args: ['-c', 'docker pull gcr.io/$PROJECT_ID/[IMAGE_NAME]:latest || exit 0']
    - name: 'gcr.io/cloud-builders/docker'
      args: [
                'build',
                '-t', 'gcr.io/$PROJECT_ID/[IMAGE_NAME]:latest',
                '--cache-from', 'gcr.io/$PROJECT_ID/[IMAGE_NAME]:latest',
                '.'
            ]
    images: ['gcr.io/$PROJECT_ID/[IMAGE_NAME]:latest']
    

    谷歌建议的最佳实践:https://cloud.google.com/build/docs/optimize-builds/speeding-up-builds

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-02
      • 2021-09-27
      • 2018-07-04
      • 1970-01-01
      • 2013-07-17
      • 2022-09-13
      • 2021-02-01
      • 1970-01-01
      相关资源
      最近更新 更多