首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google Build cloudbuild.yaml部署python函数的最佳实践

Google Build cloudbuild.yaml部署python函数的最佳实践
EN

Stack Overflow用户
提问于 2019-06-06 09:29:45
回答 1查看 1.3K关注 0票数 2

我的项目结构设置如下:

代码语言:javascript
复制
cloudbuild.yaml
requirements.txt
functions/
    folder_a/
        test/
            main_test.py
        main.py

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-06 17:03:24

为什么不重新运行测试并在每次代码更改时重新部署?测试更新后的依赖项没有破坏旧的东西,或者你依赖的东西可能已经改变,这是没有坏处的。

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

代码语言:javascript
复制
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}'
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56469896

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档