Reputation: 217
Does Google Cloud Build keep docker images between build steps by default?
In their docs they say built images are discarded after every step but I've seen examples in which build steps use images produced in previous build ones! so, are built images discarded on completion of every step or saved somewhere for coming steps?
Here's my cloudbuild.yaml
.
steps:
- name: gcr.io/cloud-builders/docker
args:
- build
- '-t'
- '${_ARTIFACT_REPO}'
- .
- name: gcr.io/cloud-builders/docker
args:
- push
- '${_ARTIFACT_REPO}'
- name: gcr.io/google.com/cloudsdktool/cloud-sdk
args:
- run
- deploy
- my-service
- '--image'
- '${_ARTIFACT_REPO}'
- '--region'
- us-central1
- '--allow-unauthenticated'
entrypoint: gcloud
Upvotes: 6
Views: 1604
Reputation: 3789
Yes, Cloud Build keep images between steps.
You can imagine Cloud Build like a simple VM or your local computer so when you build an image it is stored in local (like when you run docker build -t TAG .
)
All the steps run in the same instance so you can re-use built images in previous steps in other steps. Your sample steps do not show this but the following do:
steps:
- name: 'gcr.io/cloud-builders/docker'
args:
- build
- -t
- MY_TAG
- .
- name: 'gcr.io/cloud-builders/docker'
args:
- run
- MY_TAG
- COMMAND
- ARG
As well use the previous built image as part of an step:
steps:
- name: 'gcr.io/cloud-builders/docker'
args:
- build
- -t
- MY_TAG
- .
- name: 'MY_TAG'
args:
- COMMAND
- ARG
All the images built are available in your workspace until the build is done (success or fail).
P.D. The reason I asked where did you read that the images are discarded after every step is because I've not read that in the docs unless I missed something, so if you have the link to that please share it with us.
Upvotes: 6