如何使用Cloud Build和Cloud功能在Google Cloud上设置部署管道

介绍 (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

参考: 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项目。 如果您还没有,请按照以下步骤创建它:

  1. Access the GCP Console, enter a name for your new project and click the CREATE button;

    访问GCP控制台 ,输入新项目的名称,然后点击CREATE按钮;

  2. 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)

  1. From the top-left menu, select APIs & Services, then click the ENABLE APIS AND SERVICES button;

    从左上方的菜单中,选择API和服务 ,然后单击启用 API和

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您提供一些关于spring cloud项目使用docker部署,同时使用gradle构建的建议。 首先,您需要在您的spring cloud项目中集成docker支持。您可以使用docker插件来实现这一点。在您的项目中添加以下配置: ``` plugins { id 'com.palantir.docker' version '0.22.1' } docker { name "${project.group}/${project.name}:${project.version}" copySpec { from jar } buildArgs(['JAR_FILE': "$jar.archiveName"]) } ``` 这里我们使用了`com.palantir.docker`插件,并指定了一个docker镜像的名称。然后我们将`jar`文件添加到docker镜像中。 接下来,您需要在gradle中添加docker任务。在您的`build.gradle`文件中,添加以下代码: ``` task buildDocker(type: DockerBuildImage) { dependsOn assemble inputDir = project.rootDir dockerfile = file('Dockerfile') tag = "${project.group}/${project.name}:${project.version}" } task pushDocker(type: DockerPushImage) { dependsOn buildDocker inputDir = project.rootDir tag = "${project.group}/${project.name}:${project.version}" } ``` 这里我们定义了两个gradle任务:`buildDocker`和`pushDocker`。`buildDocker`任务将会构建docker镜像,并将其打上标签。`pushDocker`任务将会推送这个镜像到远程docker仓库。 最后,您需要编写一个`Dockerfile`文件来定义您的docker镜像。以下是一个示例`Dockerfile`文件: ``` FROM openjdk:8-jdk-alpine EXPOSE 8080 ARG JAR_FILE COPY ${JAR_FILE} app.jar ENTRYPOINT ["java","-jar","/app.jar"] ``` 这里我们使用了一个基于alpine的java镜像,并将其暴露在8080端口上。我们还将应用程序`jar`文件复制到容器中,并使用`java -jar`命令启动它。 现在,您可以使用以下命令来构建和推送docker镜像: ``` ./gradlew pushDocker ``` 这将会自动构建并推送docker镜像到您的docker仓库中。 希望这些信息可以帮助到您。如果您有任何其他问题,请随时问我。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值