如何为 运行 我的 python 代码构建一个 yaml 文件

how to build a yaml file to run my python code

大家好,很抱歉提出这个愚蠢的问题,但这是我使用 Yaml 的第 2 天。

steps:
- name: 'gcr.io/$PROJECT_ID/p2p-cloudbuild' 
  entrypoint: '/bin/bash'
  args: ['-c','virtualenv /workspace/venv' ]
  # Create a Python virtualenv stored in /workspace/venv that will persist across container runs.

- name: 'gcr.io/$PROJECT_ID/p2p-cloudbuild' 
  entrypoint: 'venv/bin/pip'
  args: ['install', '-V', '-r', 'requirements.txt']
  # Installs any dependencies listed in the project's requirements.txt.

问题:如何将步骤添加到 main.py 文件中的 call/execute 'my_function'?

感谢您的帮助。

steps:
- name: 'gcr.io/$PROJECT_ID/p2p-cloudbuild' 
  entrypoint: '/bin/bash'
  args: ['-c','virtualenv /workspace/venv' ]
  # Create a Python virtualenv stored in /workspace/venv that will persist across container runs.

- name: 'gcr.io/$PROJECT_ID/p2p-cloudbuild' 
  entrypoint: 'venv/bin/pip'
  args: ['install', '-V', '-r', 'requirements.txt']
  # Installs any dependencies listed in the project's requirements.txt.

假设我有一个文件 main.py:

def foo():
  return "bar"

这其实可以简化为:

- name: 'gcr.io/$PROJECT_ID/p2p-cloudbuild' 
  entrypoint: '/bin/bash'
  args:
    - '-c'
    - |
      virtualenv /workspace/venv
      source /workspace/venv/bin/activate
      pip install -V -r requirements.txt
      python -c 'from main import foo; print (foo())'