我可以自动执行Google Cloud SDK gcloud init-交互式命令

问题描述:

有关Google Cloud SDK的文档 https://cloud.google.com/sdk/docs/在安装gcloud init后指示它运行.

Documentation on Google Cloud SDK https://cloud.google.com/sdk/docs/ directs one to run gcloud init after installing it.

假设gcloud init是交互式命令,是否有一种方法可以自动执行此步骤?

Is there a way to automate this step given that gcloud init is an interactive command?

一个不需要运行gcloud init.主要目标是确保已配置凭据,并且可能已设置了项目属性.如果您具有服务帐户凭据,则可以配置gcloud并准备通过以下方法进行操作:

One does not need to run gcloud init. Main goal is to make sure credentials are configured and perhaps the project property is set. If you have service-account credentials, gcloud can be configured and ready to go via the following:

gcloud auth activate-service-account --key-file=credential_key.json
gcloud config set project my-project

出于完整性考虑,gcloud init本质上执行以下步骤:

For completeness gcloud init essentially runs the following steps:

  1. 选择配置(以下一项)
    • gcloud config configurations create my_configuration
    • gcloud config configurations activate my_configuration
  1. Select configuration (one of the following)
    • gcloud config configurations create my_configuration
    • gcloud config configurations activate my_configuration
  • (交互式)gcloud auth login
  • gcloud config set account my_existing_credentials
  • gcloud auth activate-service-account
  • (Interactive) gcloud auth login
  • gcloud config set account my_existing_credentials
  • gcloud auth activate-service-account
  • gcloud config set project my_project
    • 可通过以下方式查看设置凭据的可访问项目列表 gcloud projects list
    • gcloud config set project my_project
      • List of accessible projects for set credentials can be seen via gcloud projects list
      • gcloud config set compute/zone my_default_gce_zone
        • 可以通过gcloud compute zones list
        • 获取区域列表
        • gcloud config set compute/zone my_default_gce_zone
          • List of zones can be obtained via gcloud compute zones list
          • gcloud config set compute/region my_default_gce_region
            • 可以通过gcloud compute regions list
            • 获取区域列表
            • gcloud config set compute/region my_default_gce_region
              • List of regions can be obtained via gcloud compute regions list
              • gsutil config -n -o ~/.boto