0

While setting up a my build system to automatically version my containers in Cloud Registry (How do I set an environment or substitution variable via a step in Google Cloud Build?), I ran into a frustrating error.

This works:

- name: 'gcr.io/cloud-builders/docker'
  entrypoint: 'bash'
  args: ['-c', 'docker build -t gcr.io/$PROJECT_ID/$REPO_NAME:$SHORT_SHA -t gcr.io/$PROJECT_ID/$REPO_NAME:latest -t gcr.io/$PROJECT_ID/$REPO_NAME:$(cat VERSION) -t gcr.io/$PROJECT_ID/$REPO_NAME:$(cat SEMVER) -t gcr.io/$PROJECT_ID/$REPO_NAME:$(cat MAJOR) -t gcr.io/$PROJECT_ID/$REPO_NAME:$(cat MAJOR).$(cat MINOR) .']
images: ['gcr.io/$PROJECT_ID/$REPO_NAME']

But this does not work:

- name: 'gcr.io/cloud-builders/docker'
  entrypoint: 'bash'
  args: ['-c', 'docker', 'build',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$SHORT_SHA',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:latest',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$(cat VERSION)',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$(cat SEMVER)',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$(cat MAJOR)',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$(cat MAJOR).$(cat MINOR)',
    '.']
images: ['gcr.io/$PROJECT_ID/$REPO_NAME']

Shouldn't these be equivalent? What am I missing?

1 Answers1

1

Try this one.

```
  - name: 'gcr.io/cloud-builders/docker'
    entrypoint: 'bash'
    args: 
      - -c
      - |
        docker build -t gcr.io/$PROJECT_ID/$REPO_NAME:$SHORT_SHA \
        -t gcr.io/$PROJECT_ID/$REPO_NAME:latest \
        -t gcr.io/$PROJECT_ID/$REPO_NAME:$(cat VERSION) \
        -t gcr.io/$PROJECT_ID/$REPO_NAME:$(cat SEMVER) \
        -t gcr.io/$PROJECT_ID/$REPO_NAME:$(cat MAJOR) \
        -t gcr.io/$PROJECT_ID/$REPO_NAME:$(cat MAJOR).$(cat MINOR) .

images: ['gcr.io/$PROJECT_ID/$REPO_NAME']
```

and one way this could work is. Just removing the entry point from bash.

```
- name: 'gcr.io/cloud-builders/docker'
  args: [ 'build',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$SHORT_SHA',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:latest',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$(cat VERSION)',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$(cat SEMVER)',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$(cat MAJOR)',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$(cat MAJOR).$(cat MINOR)',
    '.']
images: ['gcr.io/$PROJECT_ID/$REPO_NAME']
```
Azar
  • 32
  • 1
  • 7
  • to be exactly answer your question, your entry point is bash. executing docker build -t . is different from docker , build, -t , . – Azar Dec 21 '19 at 08:39