简体   繁体   中英

Container builder dockerfile with gcloud commands

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 ?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM