Google Cloud Functions:用于 Python 3.7 运行时的 CI/CD

在有关测试云功能的文档末尾,有一个关于 CI/CD 的部分。但是,他们给出的唯一示例是节点。我一直在尝试用 python 3.7 做一些无济于事。


每次推送到 Google Source Cloud 存储库时,我都会设置一个触发器。它是一个多功能项目


├── actions

│   ├── action.json

│   └── main.py

├── cloudbuild.yaml

├── Dockerfile

├── graph

│   ├── main.py

│   └── requirements.txt

└── testing

    ├── test_actions.py

    └── test_graph.py


我已经试过这个例子来进行自定义构建。


这是我的cloudbuild.yml:


steps:

  - name: 'gcr.io/momentum-360/pytest'

这是我的Dockerfile:


FROM python:3.7

COPY . /

WORKDIR /

RUN pip install -r graph/requirements.txt

RUN pip install pytest

ENTRYPOINT ["pytest"]

在云构建环境(非本地)中运行时出现以下错误:


"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

这意味着我没有足够的权限读取自己的文件?我不确定我这样做是否正确。


梦里花落0921
浏览 162回答 1
1回答

陪伴而非守候

我相信问题出在你的cloudbuild.yaml. 您需要对其进行配置以从 Dockerfile 构建映像。查看官方的 Google Cloud Build以了解如何创建构建配置文件。我一直在尝试这个简单的设置,它对我有用:├── project&nbsp; &nbsp; ├── cloudbuild.yaml&nbsp; &nbsp; └── Dockerfile&nbsp; &nbsp; └── test_sample.py内容test_sample.py:def inc(x):&nbsp; &nbsp;return x + 1def test_answer():&nbsp; &nbsp;assert inc(3) == 4这是cloudbuild.yaml:steps:- name: 'gcr.io/cloud-builders/docker'&nbsp; args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/pytest-image', '.' ]images:- 'gcr.io/$PROJECT_ID/pytest-image'的Dockerfile,重要的是这个项目在自己的目录复制到运行pytest是很重要的。FROM python:3.7COPY . /projectWORKDIR /projectRUN pip install pytestENTRYPOINT ["pytest"]现在,在项目目录中我们构建镜像:gcloud builds submit --config cloudbuild.yaml .我们拉它:docker pull gcr.io/$PROJECT_ID/pytest-image:latest并运行它:docker run gcr.io/$PROJECT_ID/pytest-image:latest结果:============================= test session starts ==============================platform linux -- Python 3.7.2, pytest-4.2.0, py-1.7.0, pluggy-0.8.1rootdir: /src, inifile:collected 1 itemtest_sample.py .&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[100%]=========================== 1 passed in 0.03 seconds ===========================
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python