【发布时间】:2019-10-09 00:59:52
【问题描述】:
我正在查看这个使用部署管理器部署云功能的示例:https://github.com/GoogleCloudPlatform/deploymentmanager-samples/tree/master/examples/v2/cloud_functions
让这个变得笨拙且不太实用的原因之一是,它需要您在函数中显式导入每个文件:
imports:
- path: cloud_function.py
# The function code will be defined for the files in function/
- path: function/index.js
- path: function/package.json
每次有新文件时都必须添加它是不可接受的。 Deployment Manager 也不支持通配符。
如何以编程方式导入文件?
这是 cloud_function.py 中引用导入文件的部分,我尝试只使用一个字符串,但似乎 import 实际上将文件复制到某个地方?如何以编程方式执行此操作,这样我就不需要显式定义每个单独的文件?
files = ["function/index.js","function/package.json"] # this does not work if these files have not been declared via "import"
#for imp in ctx.imports:
for imp in files:
if imp.startswith(ctx.properties['codeLocation']):
zip_file.writestr(imp[len(ctx.properties['codeLocation']):],
ctx.imports[imp])
【问题讨论】:
标签: google-cloud-platform google-deployment-manager