1

I want to cache the previously stored google cloud image while creating a new build for the project. I have followed the official documentation : https://cloud.google.com/build/docs/optimize-builds/speeding-up-builds but while building it doesn't seems to be caching the data. The yaml file I am using is:

steps:
    - name: 'gcr.io/cloud-builders/docker'
      args: ['build','--cache-from', 'gcr.io/PROJECT_ID/node-app:latest', '-t', 'gcr.io/PROJECT_ID/node-app:latest', '.']
    - name: 'gcr.io/cloud-builders/docker'
      args: ['push', 'gcr.io/PROJECT_ID/node-app:latest']
    images:
    - 'gcr.io/PROJECT_ID/node-app:latest'

I also tried to first pull the docker image as:

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

I checked there is image already present and it is also pulling the image but it's not caching the image. How can I cache the image or is there any other process to do so in google cloud?

Gogle Gogle
  • 59
  • 1
  • 3

1 Answers1

1

As mentioned in this stackoverflow answer by ttfreeman

Have you tried Kaniko? It can save the cache in gcr.io and and if you have built your Dockerfile with right steps (see https://cloud.google.com/blog/products/gcp/7-best-practices-for-building-containers), it should save you a lot of time. Here is the cloudbuild.yaml example:

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

More info: https://cloud.google.com/cloud-build/docs/kaniko-cache

Sathi Aiswarya
  • 2,068
  • 2
  • 11