5

I'm having a problem with Google Cloud Build where the docker build command doesn't seem to be accepting the build-arg option, even though this same command works as expected on local:

Dockerfile:

ARG ASSETS_ENV=development
RUN echo "ASSETS_ENV is ${ASSETS_ENV}"

Build Command:

docker build --build-arg="ASSETS_ENV=production" .

Result on local:

ASSETS_ENV is production

Result on Cloud Build:

ASSETS_ENV is development
Paludis
  • 714
  • 6
  • 21

2 Answers2

10

Ok the fix was in the cloud build yaml config:

Before:

- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '--build-arg="ASSETS_ENV=production"', '.']

After:

- name: 'gcr.io/cloud-builders/docker'
  entrypoint: 'bash'
  args: ['-c', 'docker build --build-arg="ASSETS_ENV=production" .']
Paludis
  • 714
  • 6
  • 21
  • 1
    Btw, does anyone know why the former solution doesn't work? – mlukasik May 07 '21 at 10:36
  • 1
    Have you tried passing `build-arg` in two separate args? as in `args: [ "build", "--build-arg", "ASSET_ENV=production", ...]`. I have a similar setup and it works. `args: ["build","--build-arg", "TF2_BASE_IMAGE=${_TF2_BASE_IMAGE}" ...]` – Nader Ghanbari Jun 25 '21 at 23:10
3

For anyone who defines their steps like this:

- name: 'gcr.io/cloud-builders/docker'
  args:
  - build
  - foo
  - bar

The comment from @nader-ghanbari worked for me:

- name: 'gcr.io/cloud-builders/docker'
  args:
  - build
  - --build-arg
  - TF2_BASE_IMAGE=${_TF2_BASE_IMAGE}
jayjyli
  • 771
  • 3
  • 11
  • 23