Search code examples
dockergcloudgoogle-cloud-run

Is there a way to specify a `--build-arg` with Cloud Run?


In docker we can pass in a build argument via --build-arg:

docker build --build-arg CACHEBUST="$(date)" . -t container-name:latest

Is there an equivalent method for gcloud? The below will not work:

gcloud beta builds submit --tag="gcr.io/${PROJECT_NAME}/${name}" --no-cache --build-arg CACHEBUST="$(date)"


Solution

  • The gcloud builds submit command doesn't have an option to specify --build-arg. An alternative workaround is that you need to use a YAML file and pass it with the gcloud builds submit command.

    See below sample code:

    # Need YAML to set --build-arg
    steps:
    - name: 'gcr.io/cloud-builders/docker'
      args: ['build', '-t', '--tag=gcr.io/${PROJECT_ID}/$sample-docker-repo/sample-image:latest', --build-arg CACHEBUST="$(date)" --no-cache', '.']
    

    Then, start the build by running this sample command:

    gcloud builds submit --tag gcr.io/[PROJECT_ID]/sample-docker-repo/sample-image:latest