Google 构建 cloudbuild.yaml 部署 python 函数最佳实践

Google Build cloudbuild.yaml deploying python functions best practices

我的项目结构是这样设置的:

cloudbuild.yaml
requirements.txt
functions/
    folder_a/
        test/
            main_test.py
        main.py

我需要在我的 cloudbuild.yaml 中指定什么才能在 functions/、运行 他们的测试中获取每个新编辑的函数,然后将这些函数同步到 Google云函数?所有函数都是 python37 并使用 http 作为它们的触发器。

为什么不 re-run 测试并在每次代码更改时重新部署?测试更新的依赖项没有破坏旧的东西或你所依赖的东西可能已经改变没有坏处。

我不确定您使用的是什么测试框架,但类似于

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}'