我的项目结构设置如下:
cloudbuild.yaml
requirements.txt
functions/
folder_a/
test/
main_test.py
main.py
要在cloudbuild.yaml
中接受每个新编辑的功能,运行它们的测试,然后将这些功能同步到Google Cloud Functions,我需要在functions/
中指定什么?所有功能均为python37,并使用http作为触发器。
答案 0 :(得分:1)
为什么不重新运行测试并在每次代码更改时重新部署?测试更新后的依赖关系没有破坏旧的东西或您依赖的东西可能发生变化,这没有什么害处。
我不确定您使用的是什么测试框架,但是类似
steps:
- name: 'python'
args: ['pip3','install', '-r', 'requirements.txt', '--user']
# This installs your requirements and `--user` makes them persist between steps
- name: 'python'
args: ['python3','pytest', 'functions/folder_a/test/'] #run all tests in the tests folder
# Create a task for each function as shown here: https://cloud.google.com/functions/docs/bestpractices/testing#continuous_testing_and_deployment
- name: 'gcr.io/cloud-builders/gcloud']
id: 'deployMyFunction'
args: ['functions', 'deploy', 'my-function', '--source' , 'functions/folder_a/main.py', '--runtime' , 'python37' ,'--trigger-http']
# Option B: Write some python that iterates and deploys each function, although I can't seem to find the Cloud Functions in the python SDK SPI.
- name: 'python'
args: ['python3','deploy.py']
env:
- 'PROJECT_ID=${_PROJECT_ID}'