0

I have a container builder step

steps:
- id: dockerbuild
  name: gcr.io/cloud-builders/docker
  entrypoint: 'bash'
  args:
  - -c
  - |
    docker build . -t test 
images: ['gcr.io/project/test']

The Dockerfile used to create this test image has gsutil specific commands like

FROM gcr.io/cloud-builders/gcloud
RUN gsutil ls

When I submit a docker build to container builder service using

gcloud container builds submit --config cloudbuild.yml

I see the following error

You are attempting to perform an operation that requires a project id, with none configured. Please re-run gsutil config and make sure to follow the instructions for finding and entering your default project id.
The command '/bin/sh -c gsutil ls' returned a non-zero code: 1
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: exit status 1

My question is, how do we use gcloud/gsutil commands inside the DockerFile so that I can run inside a docker build step ?

Varunkumar Manohar
  • 887
  • 3
  • 11
  • 29

2 Answers2

0

To do this, your Dockerfile either needs to start from a base image that has the cloud SDK installed already (like FROM gcr.io/cloud-builders/gcloud) or you would need to install it. Here's a Dockerfile that installs it: https://github.com/GoogleCloudPlatform/cloud-builders/blob/master/gcloud/Dockerfile.slim

David Bendory
  • 1,258
  • 8
  • 14
  • Thanks for you reply. I tried to do the same but issuing a gcloud/gsutil command inside a container builder step's dockerfile throws a error that I do not have enough permissions – Varunkumar Manohar Jul 18 '18 at 15:59
0

To invoke "gcloud commands." using the tool builder, you need Container Builder service account, because it executes your builds on your behalf.

Here in this GitHub there is an example for cloud-builders using the gcloud command:

Note : you have to specify $PROJECT_ID it's mandatory for your builder to work.

Alioua
  • 1,663
  • 1
  • 9
  • 18