Search code examples
google-cloud-build

Any practical difference between using `docker build` & `docker push` together vs. `cloud build submit` in cloud build config files?


Google Cloud docs use the first code block but I'm wondering why they don't use the second one. As far as I can tell they achieve the same result. Is there any practical difference?

# config 1
steps:
# Build the container image
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '-t', 'gcr.io/project-id/project-name','.']
- name: 'gcr.io/cloud-builders/docker'
  args: ['push', 'gcr.io/project-id/project-name']
# Deploy container image to Cloud Run
- name: 'gcr.io/cloud-builders/gcloud'
  args: ['run', 'deploy', 'project-name', '--image', 'gcr.io/project-id/project-name', '--region', 'us-central1']
images: ['gcr.io/project-id/project-name']
# config 2
steps:
# Build the container image
- name: 'gcr.io/cloud-builders/gcloud'
  args: ['builds', 'submit', '--region', 'us-central1', '--tag', 'gcr.io/project-id/project-name','.']
# Deploy container image to Cloud Run
- name: 'gcr.io/cloud-builders/gcloud'
  args: ['run', 'deploy', 'project-name', '--image', 'gcr.io/project-id/project-name', '--region', 'us-central1']

I run this with gcloud builds submit --config cloudbuild.yaml


Solution

  • In the second config, you call a Cloud Build from inside a Cloud Build, that means you pay twice the docker build/push process in the second config.

    That time of timeline in fact

    • Cloud Build 1
      • Cloud build 2
      • Docker Build
      • Docker Push
    • Deploy on cloud run

    In addition, the number of concurrent build are limited and with the config 2 you use 2 times more quotas.

    And the result is the same (it should be slightly faster with the config 1 because you haven't a new Cloud Build to spin up)