如何使用 Deployment Manager 将文件写入 Google Cloud Storage?
How to write a file to Google Cloud Storage using 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
资源?
"uploading objects to Cloud Storage isn't really a supported use case"
in Deployment Manager.
但是,在从 Deployment Manager 上传对象的线程中建议的解决方法是:
创建一个 Google Cloud Function 并从部署管理器调用它:
action: gcp-types/cloudfunctions-v1beta2:cloudfunctions.projects.locations.functions.call
中找到 Cloud Functions 示例
您可以将以下示例作为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
我在 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
资源?
"uploading objects to Cloud Storage isn't really a supported use case" in Deployment Manager.
但是,在从 Deployment Manager 上传对象的线程中建议的解决方法是:
创建一个 Google Cloud Function 并从部署管理器调用它:
action: gcp-types/cloudfunctions-v1beta2:cloudfunctions.projects.locations.functions.call
中找到 Cloud Functions 示例
您可以将以下示例作为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