如何使用Deployment Manager将文件写入Google云端存储?

时间:2018-03-28 17:36:16

标签: google-cloud-platform google-cloud-storage google-deployment-manager

我在Supported Resource Types列表中看到,Google Cloud Deployment Manager至少支持storage.v1.object类型。我希望这能让我能够根据DM模板中的数据将文件写入GCS。但是,我仍然坚持如何以DM喜欢的方式编写资源的属性。当我使用以下模板时:

resources:
  - name: foo.txt
    type: storage.v1.object
    properties:
      bucket: my-bucket
      name: foo.txt
      uploadType: media

我从gcloud deployment-manager收到以下错误:

ERROR: (gcloud.deployment-manager.deployments.update) Error in Operation [operation-1522258413242-5687c67fa4691-c89f17c6-c0b96018]: errors:
- code: RESOURCE_ERROR
  location: /deployments/test-serviceaccount/resources/foo.txt
  message: '{"ResourceType":"storage.v1.object","ResourceErrorCode":"400","ResourceErrorMessage":{"code":400,"errors":[{"domain":"global","message":"Upload
    requests must include an uploadType URL parameter and a URL path beginning with
    /upload/","reason":"wrongUrlForUpload","extendedHelp":"https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload"}],"message":"Upload
    requests must include an uploadType URL parameter and a URL path beginning with
    /upload/","statusMessage":"Bad Request","requestPath":"https://www.googleapis.com/storage/v1/b/my-bucket/o","httpMethod":"POST"}}'

我在这里缺少什么?如何在Deployment Manager模板中构建有效的storage.v1.object资源?

1 个答案:

答案 0 :(得分:2)

根据this Github thread

  

“将对象上传到云端存储并不是真正受支持的用例”   在Deployment Manager中。

但是,从Deployment Manager上传对象的线程中提出的解决方法是:

您可以使用以下示例作为Cloud Builder的参考。它克隆了一个存储库(您可以使用自己的图像和run a custom script)并将目录上传到存储桶。

resources:
  - name: my-build
    action: gcp-types/cloudbuild-v1:cloudbuild.projects.builds.create
    metadata:
      runtimePolicy:
      - CREATE
    properties:
      steps:
      - name: gcr.io/cloud-builders/git
        args: ['clone', 'https://github.com/GoogleCloudPlatform/appengine-helloworld-php.git']
      - name: gcr.io/cloud-builders/gsutil
        args: ['-m', 'cp', '-r', 'appengine-helloworld-php', 'gs://<MY_BUCKET>/']
      timeout: 120s