[英]Google Cloud Functions: CI/CD for Python 3.7 Runtime
At the end of the docs on testing your cloud function there is a section on CI/CD. 在测试您的云功能的文档末尾,有一个关于CI / CD的部分。 However, the only example they give is for node.
但是,他们给出的唯一示例是节点。 I've been trying to do something with python 3.7 to no avail.
我一直在尝试用python 3.7做某事无济于事。
I set up a trigger for each time I push to a Google Source Cloud repository. 每当我推送到Google Source Cloud存储库时,我都会设置一个触发器。 Its a multifunction project
它是一个多功能项目
├── actions
│ ├── action.json
│ └── main.py
├── cloudbuild.yaml
├── Dockerfile
├── graph
│ ├── main.py
│ └── requirements.txt
└── testing
├── test_actions.py
└── test_graph.py
I've tried the example to make a custom build. 我已经尝试过该示例进行自定义构建。
here is my cloudbuild.yml
: 这是我的
cloudbuild.yml
:
steps:
- name: 'gcr.io/momentum-360/pytest'
Here is my Dockerfile
: 这是我的
Dockerfile
:
FROM python:3.7
COPY . /
WORKDIR /
RUN pip install -r graph/requirements.txt
RUN pip install pytest
ENTRYPOINT ["pytest"]
I'm getting the following error when I run it in the cloud build environment (not locally): 在云构建环境(而非本地)中运行它时,出现以下错误:
"Missing or insufficient permissions.","grpc_status":7}"
E >
The above exception was the direct cause of the following exception:
testing/test_graph.py:7: in <module>
from graph import main
which means I don't have enough permission to read my own files? 这意味着我没有足够的权限来读取自己的文件? I'm not sure I'm doing this right at all.
我不确定我是否正在正确执行此操作。
I believe the problem is with your cloudbuild.yaml
. 我相信问题出在您的
cloudbuild.yaml
。 You need to configure it to build the image from the Dockerfile. 您需要对其进行配置,以从Dockerfile构建映像。 Check the official Google Cloud Build to know how to create a build configuration file.
查看官方的Google Cloud Build了解如何创建构建配置文件。
I have been trying with this simple setup and it worked for me: 我一直在尝试这种简单的设置,它为我工作:
├── project
├── cloudbuild.yaml
└── Dockerfile
└── test_sample.py
The content of test_sample.py
: test_sample.py
的内容:
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 4
Here is the cloudbuild.yaml
: 这是
cloudbuild.yaml
:
steps:
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/pytest-image', '.' ]
images:
- 'gcr.io/$PROJECT_ID/pytest-image'
The Dockerfile
, it is important to copy the project in its own directory to run pytest. Dockerfile
,将项目复制到其自己的目录中以运行pytest很重要。
FROM python:3.7
COPY . /project
WORKDIR /project
RUN pip install pytest
ENTRYPOINT ["pytest"]
Now, inside the project directory we build the image: 现在,在项目目录中,我们构建图像:
gcloud builds submit --config cloudbuild.yaml .
We pull it: 我们拉它:
docker pull gcr.io/$PROJECT_ID/pytest-image:latest
And run it: 并运行它:
docker run gcr.io/$PROJECT_ID/pytest-image:latest
Result: 结果:
============================= test session starts ==============================
platform linux -- Python 3.7.2, pytest-4.2.0, py-1.7.0, pluggy-0.8.1
rootdir: /src, inifile:
collected 1 item
test_sample.py . [100%]
=========================== 1 passed in 0.03 seconds ===========================
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.