简体   繁体   English

Google云功能:适用于Python 3.7运行时的CI / CD

[英]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.

相关问题 轻量级的ETL,将Google Cloud Storage和Cloud Functions与Python 3.7结合使用 - lightweight ETL using Google Cloud Storage and Cloud Functions with Python 3.7 在 App Engine 上使用带有 Django 的 Google Cloud 构建的 Ci/CD 失败 - Ci/CD using Google Cloud build with Django on App Engine failed All nameservers failed to answer UDP port 53 Google cloud functions python 3.7 atlas mongodb - All nameservers failed to answer UDP port 53 Google cloud functions python 3.7 atlas mongodb Google Cloud Functions中的Python - Python in Google Cloud Functions 如何从Python运行时云函数访问Google Cloud Platform Firestore触发器 - How to access Google Cloud Platform Firestore triggers from Python runtime cloud functions 将 Google Calendar API 与 Python 3.7 Google Cloud Function 结合使用 - Using Google Calendar API with a Python 3.7 Google Cloud Function 如何将Google Appengine Python运行时2.7迁移到3.7? - How to migrate Google Appengine Python runtime 2.7 to 3.7? Google Cloud Engine-如何在Python 3.7中接收电子邮件并处理? - Google Cloud Engine - How to receive an email and handle in Python 3.7? 自定义函数 Python 3.7 - Customary Functions Python 3.7 使用 Functions Framework for Python 时如何在 Google Cloud Buildpacks 中设置运行时版本? - How to set runtime version in Google Cloud Buildpacks when using Functions Framework for Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM