google-cloud-platform - 你如何调试谷歌部署管理器模板?
问题描述
它使用这个模板。我向它添加了一个打印语句,但我如何看到这个输出?
import base64
import hashlib
from StringIO import StringIO
import zipfile
def GenerateConfig(ctx):
"""Generate YAML resource configuration."""
in_memory_output_file = StringIO()
function_name = ctx.env['deployment'] + 'cf'
zip_file = zipfile.ZipFile(
in_memory_output_file, mode='w', compression=zipfile.ZIP_DEFLATED)
####################################################
############ HOW DO I SEE THIS????? ################
print('heelo wworrld')
####################################################
####################################################
for imp in ctx.imports:
if imp.startswith(ctx.properties['codeLocation']):
zip_file.writestr(imp[len(ctx.properties['codeLocation']):],
ctx.imports[imp])
zip_file.close()
content = base64.b64encode(in_memory_output_file.getvalue())
m = hashlib.md5()
m.update(content)
source_archive_url = 'gs://%s/%s' % (ctx.properties['codeBucket'],
m.hexdigest() + '.zip')
cmd = "echo '%s' | base64 -d > /function/function.zip;" % (content)
volumes = [{'name': 'function-code', 'path': '/function'}]
build_step = {
'name': 'upload-function-code',
'action': 'gcp-types/cloudbuild-v1:cloudbuild.projects.builds.create',
'metadata': {
'runtimePolicy': ['UPDATE_ON_CHANGE']
},
'properties': {
'steps': [{
'name': 'ubuntu',
'args': ['bash', '-c', cmd],
'volumes': volumes,
}, {
'name': 'gcr.io/cloud-builders/gsutil',
'args': ['cp', '/function/function.zip', source_archive_url],
'volumes': volumes
}],
'timeout':
'120s'
}
}
cloud_function = {
'type': 'gcp-types/cloudfunctions-v1:projects.locations.functions',
'name': function_name,
'properties': {
'parent':
'/'.join([
'projects', ctx.env['project'], 'locations',
ctx.properties['location']
]),
'function':
function_name,
'labels': {
# Add the hash of the contents to trigger an update if the bucket
# object changes
'content-md5': m.hexdigest()
},
'sourceArchiveUrl':
source_archive_url,
'environmentVariables': {
'codeHash': m.hexdigest()
},
'entryPoint':
ctx.properties['entryPoint'],
'httpsTrigger': {},
'timeout':
ctx.properties['timeout'],
'availableMemoryMb':
ctx.properties['availableMemoryMb'],
'runtime':
ctx.properties['runtime']
},
'metadata': {
'dependsOn': ['upload-function-code']
}
}
resources = [build_step, cloud_function]
return {
'resources':
resources,
'outputs': [{
'name': 'sourceArchiveUrl',
'value': source_archive_url
}, {
'name': 'name',
'value': '$(ref.' + function_name + '.name)'
}]
}
编辑:这绝不是解决这个问题的方法,但我发现如果我设置一堆outputs
信息,我有兴趣看到它有帮助。所以我想你可以通过将信息/输出收集到一个列表或你的 python 模板中的东西中来滚动你自己的 log-ish 东西,然后将所有这些作为output
- 不是很好但总比没有好
解决方案
Deployment Manager 是一项基础架构部署服务,可自动创建和管理 Google Cloud Platform (GCP) 资源。由于部署管理器的托管环境,您尝试在部署管理器上执行的操作是不可能的。
到目前为止,解决问题的唯一方法是依赖部署管理器仪表板中的扩展模板。已经有一个功能请求,以便在此处解决您的用例。我建议您为功能请求加注星标,以便通过电子邮件获取更新并发表评论以表明社区的兴趣。有关该功能的所有官方通信都将在那里发布。
推荐阅读
- javascript - 在悬停时更改多个 img 标签的 img src 属性
- sql - 从 Snowflake 中的表中选择随机百分比(使用 WHERE 子句时)
- python - Python消息框程序
- asp.net - NET平台识别
- python - Windows更新后屏幕上的Pygame对象移动了吗?
- javascript - React Native:如何将 taskmanager 返回的 promise 中的值发送到 redux 商店?
- java - 为什么当 y>5 和 x=2 时这个带有 for 循环的程序给出零
- python - 如何根据分类值将时间序列拆分为固定长度的连续子集?
- processmaker - Processmaker 作曲家安装有错误
- latex - 如何在 pandoc 中移动“数字列表”(很多)