介绍 (Introduction)
In my last two articles, I showed How to Set Up a Deployment Pipeline on Google Cloud with Cloud Build, Container Registry and Cloud Run and also How to Develop, Debug and Test your Python Google Cloud Functions on Your Local Dev Environment.
在我的前两篇文章中,我展示了如何在Google Cloud上使用Cloud Build,Container Registry和Cloud Run设置部署管道,以及如何在本地Dev环境中开发,调试和测试Python Google Cloud功能 。
In this article, we’ll build on top of the previous two, showing how to deploy Cloud Functions with Cloud Build, as well as to check the behavior of our Cloud Functions after they are deployed, to make sure the behavior we saw while developing with Functions Framework for Python is accurate with the deployed version.
在本文中,我们将在前两个基础之上构建,展示如何使用Cloud Build部署Cloud Functions,以及在部署Cloud Function后检查其功能,以确保在开发过程中看到的行为使用Functions Framework for Python与部署的版本正确。
Disclaimer: all opinions expressed are my own, and represent no one but myself.
免责声明 :所有表达的意见都是我自己的,仅代表我自己。
云构建 (Cloud Build)
Cloud Build is a service that executes your builds on Google Cloud Platform infrastructure. Cloud Build can import source code from Google Cloud Storage, Cloud Source Repositories, GitHub, or Bitbucket, execute a build to your specifications, and produce artifacts such as Docker containers or Java archives.
Cloud Build是一项服务,可在Google Cloud Platform基础架构上执行您的构建。 Cloud Build可以从Google Cloud Storage,Cloud Source Repository,GitHub或Bitbucket导入源代码,根据您的规范执行构建,并生成Docker容器或Java存档等工件。
Cloud Build executes your build as a series of build steps, where each build step is run in a Docker container. A build step can do anything that can be done from a container irrespective of the environment. To perform your tasks, you can either use the supported build steps provided by Cloud Build or write your own build steps.
Cloud Build将您的构建作为一系列构建步骤执行,其中每个构建步骤都在Docker容器中运行。 无论环境如何,构建步骤都可以执行容器中可以执行的任何操作。 要执行任务,您可以使用 Cloud Build提供的受支持的构建步骤 ,也可以编写自己的构建步骤 。
Reference: https://cloud.google.com/cloud-build/docs
云功能 (Cloud Functions)
Google Cloud Functions is a serverless execution environment for building and connecting cloud services. With Cloud Functions you write simple, single-purpose functions that are attached to events emitted from your cloud infrastructure and services. Your function is triggered when an event being watched is fired. Your code executes in a fully managed environment. There is no need to provision any infrastructure or worry about managing any servers.
Google Cloud Functions是用于构建和连接云服务的无服务器执行环境。 使用云功能,您可以编写简单的,单一用途的功能,这些功能附加到从云基础架构和服务发出的事件。 触发正在监视的事件时,将触发您的功能。 您的代码在完全托管的环境中执行。 无需配置任何基础架构,也无需担心管理任何服务器。
Cloud Functions can be written using JavaScript, Python 3, Go or Java. runtimes on Google Cloud Platform. You can take your function and run it in any standard Node.js (Node.js 6, 8 or 10), Python 3 (Python 3.7), Go (Go 1.11 or Go 1.13) or Java (Java 11) environment, which makes both portability and local testing a breeze.
可以使用JavaScript,Python 3,Go或Java编写Cloud Functions。 Google Cloud Platform上的运行时。 您可以使用函数并在任何标准Node.js(Node.js 6、8或10),Python 3(Python 3.7),Go(Go 1.11或Go 1.13)或Java(Java 11)环境中运行它,便携性和本地测试轻而易举。
Reference: https://cloud.google.com/functions/docs/concepts/overview
参考: https : //cloud.google.com/functions/docs/concepts/overview
设置GCP项目 (Set Up the GCP Project)
创建项目 (Create the Project)
To follow this tutorial, you’ll need to have access to a GCP Project. If you don’t have one already, follow these steps to create it:
要遵循本教程,您需要有权访问GCP项目。 如果您还没有,请按照以下步骤创建它:
Access the GCP Console, enter a name for your new project and click the CREATE button;
访问GCP控制台 ,输入新项目的名称,然后点击CREATE按钮;
- Once your project is created, make sure it’s selected on the top-left corner, right beside the Google Cloud Platform logo. 创建项目后,请确保已在左上角,Google Cloud Platform徽标旁边的位置将其选中。
启用必需的API (Enable the Required APIs)
From the top-left menu, select APIs & Services, then click the ENABLE APIS AND SERVICES button;
从左上方的菜单中,选择API和服务 ,然后单击启用 API和 服