我想部署多个云功能。这是我的index.js
:
const { batchMultipleMessage } = require('./gcf-1');
const { batchMultipleMessage2 } = require('./gcf-2');
module.exports = {
batchMultipleMessage,
batchMultipleMessage2
};
如何使用gcloud beta functions deploy xxx
一次部署这两个功能。
答案 0 :(得分:1)
选项1:
目前,我编写了deploy.sh
来一次部署这两个云功能。
TOPIC=batch-multiple-messages
FUNCTION_NAME_1=batchMultipleMessage
FUNCTION_NAME_2=batchMultipleMessage2
echo "start to deploy cloud functions\n"
gcloud beta functions deploy ${FUNCTION_NAME_1} --trigger-resource ${TOPIC} --trigger-event google.pubsub.topic.publish
gcloud beta functions deploy ${FUNCTION_NAME_2} --trigger-resource ${TOPIC} --trigger-event google.pubsub.topic.publish
它可以工作,但是如果gcloud
命令行支持部署了多个云功能,那将是最好的方法。
选项2:
答案 1 :(得分:0)
如果有人正在寻找更好/更清洁/并行的解决方案,这就是我要做的:
# deploy.sh
# store deployment command into a string with character % where function name should be
deploy="gcloud functions deploy % --trigger-http"
# find all functions in index.js (looking at exports.<function_name>) using sed
# then pipe the function names to xargs
# then instruct that % should be replaced by each function name
# then open 20 processes where each one runs one deployment command
sed -n 's/exports\.\([a-zA-Z0-9\-_#]*\).*/\1/p' index.js | xargs -I % -P 20 sh -c "$deploy;"
您还可以更改在-P
标志上传递的进程数。我任意选择了20个。
这非常容易,并节省了大量时间。希望它将对某人有所帮助!