Search code examples
dockergoogle-cloud-platformdocker-composegoogle-cloud-buildgitops

How can I create CI/CD pipeline with cloudbuild.yaml in GCP?


I am trying to create a simple CI/CD pipeline. After the client makes git push, it will start a trigger with the below cloudbuilder.yaml:

# steps:
# - name: 'docker/compose:1.28.2'
#   args: ['up', '-d']
# - name: "docker/compose:1.28.2"
#   args: ["build"]
# images: ['gcr.io/$PROJECT_ID/cloudbuild-demo-dockercompose']
# - name: 'gcr.io/cloud-builders/docker'
#   id: 'backend'
#   args: ['build','-t', 'gcr.io/$PROJECT_ID/cloudbuild-demo-dockercompose:latest','.']
# - name: 'gcr.io/cloud-builders/docker'
#   args: ['push', 'gcr.io/$PROJECT_ID/cloudbuild-demo-dockercompose:latest']

# steps:
# - name: 'docker/compose:1.28.2'
#   args: ['up', '-d']
# - name: "docker/compose:1.28.2"
#   args: ["build"]
# images:
# - 'gcr.io/$PROJECT_ID/cloudbuild-demo-dockercompose'

# In this directory, run the following command to build this builder.
# $ gcloud builds submit . --config=cloudbuild.yaml
substitutions:
  _DOCKER_COMPOSE_VERSION: 1.28.2
steps:
- name: 'docker/compose:1.28.2'
  args:
  - 'build'
  - '--build-arg'
  - 'DOCKER_COMPOSE_VERSION=${_DOCKER_COMPOSE_VERSION}'
  - '-t'
  - 'gcr.io/$PROJECT_ID/cloudbuild-demo-dockercompose:latest'
  - '-t'
  - 'gcr.io/$PROJECT_ID/cloudbuild-demo-dockercompose:${_DOCKER_COMPOSE_VERSION}'
  - '.'
- name: 'gcr.io/$PROJECT_ID/cloudbuild-demo-dockercompose'
  args: ['version']

images:
- 'gcr.io/$PROJECT_ID/cloudbuild-demo-dockercompose:latest'
- 'gcr.io/$PROJECT_ID/cloudbuild-demo-dockercompose:${_DOCKER_COMPOSE_VERSION}'
tags: ['cloud-builders-community']

It returns the error below: it cannot create images in the repository. How can I solve this issue?

ERROR: failed to pull because we ran out of retries.
ERROR
ERROR: build step 1 "gcr.io/internal-invoicing-solution/cloudbuild-demo-dockercompose" failed: error pulling build step 1 "gcr.io/internal-invoicing-solution/cloudbuild-demo-dockercompose": generic::unknown: retry budget exhausted (10 attempts): step exited with non-zero status: 1
```



Solution

  • Before pulling your image in the 2nd step, you need to push it. When you declare the images at the end of your yaml definition, the image are pushed automatically at the end on the pipeline. Here you need it in the middle.


    EDIT 1

    I just added a docker push step, copy and paste from your comments. Does it work?

    substitutions:
      _DOCKER_COMPOSE_VERSION: 1.28.2
    steps:
    - name: 'docker/compose:1.28.2'
      args:
      - 'build'
      - '--build-arg'
      - 'DOCKER_COMPOSE_VERSION=${_DOCKER_COMPOSE_VERSION}'
      - '-t'
      - 'gcr.io/$PROJECT_ID/cloudbuild-demo-dockercompose:latest'
      - '-t'
      - 'gcr.io/$PROJECT_ID/cloudbuild-demo-dockercompose:${_DOCKER_COMPOSE_VERSION}'
      - '.'
    - name: 'gcr.io/cloud-builders/docker'
      args: ['push', 'gcr.io/$PROJECT_ID/cloudbuild-demo-dockercompose:latest']
    - name: 'gcr.io/$PROJECT_ID/cloudbuild-demo-dockercompose'
      args: ['version']
    
    images:
    - 'gcr.io/$PROJECT_ID/cloudbuild-demo-dockercompose:latest'
    - 'gcr.io/$PROJECT_ID/cloudbuild-demo-dockercompose:${_DOCKER_COMPOSE_VERSION}'
    tags: ['cloud-builders-community']