如何为 运行 我的 python 代码构建一个 yaml 文件
how to build a yaml file to run my python code
大家好,很抱歉提出这个愚蠢的问题,但这是我使用 Yaml 的第 2 天。
- 问题陈述:
我有一个 python 代码 运行s 12 分钟,(所以我不能使用 Cloud Function 来自动化它),因此使用云构建作为 hack。
- 到目前为止完成的步骤:
我的代码在 google 云存储库中,我使用云构建来构建图像并创建了一个 google 云构建触发器。现在,我想在每次触发构建时 运行 main.py python 代码(我将按照
所述使用 Cloud Scheduler 来执行此操作
- 文件夹结构(如下图所示)
- cloudbuild.yaml 到目前为止我设法写了
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())'
大家好,很抱歉提出这个愚蠢的问题,但这是我使用 Yaml 的第 2 天。
- 问题陈述: 我有一个 python 代码 运行s 12 分钟,(所以我不能使用 Cloud Function 来自动化它),因此使用云构建作为 hack。
- 到目前为止完成的步骤:
我的代码在 google 云存储库中,我使用云构建来构建图像并创建了一个 google 云构建触发器。现在,我想在每次触发构建时 运行 main.py python 代码(我将按照
- 文件夹结构(如下图所示)
- cloudbuild.yaml 到目前为止我设法写了
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())'