[英]Build trigger for Spring Boot application on Google Cloud App Engine
I'm attempting to achieve automatic build and deployment on the Google Cloud Platform using build triggers with Google App Engine.我正在尝试使用 Google App Engine 的构建触发器在 Google Cloud Platform 上实现自动构建和部署。 The build is currently triggered when I push to the master branch of my linked Github repository.
当我推送到链接的 Github 存储库的主分支时,当前会触发构建。
The application is a Spring Boot application with Maven, which is serving a simple API.该应用程序是一个带有 Maven 的 Spring Boot 应用程序,它提供一个简单的 API。 I'm trying to issue the
mvn appengine:deploy
in my cloudbuild.yaml
file, which looks like this:我正在尝试在我的
cloudbuild.yaml
文件中发出mvn appengine:deploy
,它看起来像这样:
# cloudbuild.yaml
steps:
- name: 'gcr.io/cloud-builders/mvn'
args: ['appengine:deploy']
The mvn appengine:deploy
works as expected when I run it in the Google Cloud Shell, but does not work when it is executed by the build trigger. mvn appengine:deploy
在 Google Cloud Shell 中运行时按预期工作,但在构建触发器执行时不起作用。
The triggered build run for about 20 seconds, and then fails with the following error message:触发的构建运行了大约 20 秒,然后失败并显示以下错误消息:
Execution default-cli of goal com.google.cloud.tools:appengine-maven-plugin:1.3.1:deploy failed: The Google Cloud SDK could not be found in the customary locations and no path was provided.
This is my pom.xml
configuration这是我的
pom.xml
配置
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.api</groupId>
<artifactId>api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>api</name>
<description>API</description>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<appengine.maven.plugin>1.3.2</appengine.maven.plugin>
<jetty-maven-plugin>9.3.7.v20160115</jetty-maven-plugin>
<gcloud-maven-plugin>2.0.9.121.v20160815</gcloud-maven-plugin>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>1.5.9.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.7.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.maven.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-maven-plugin}</version>
</plugin>
</plugins>
</build>
</project>
Any ideas what I might be missing in my configuration?任何想法我的配置中可能缺少什么? I had a hard time finding any examples online of a
cloudbuild.yaml
deploying on the Google App Engine using Maven.我很难在网上找到任何使用 Maven 部署在 Google App Engine 上的
cloudbuild.yaml
示例。
The appengine-maven-plugin
requires the Cloud SDK to be installed. appengine-maven-plugin
需要安装 Cloud SDK。 Since the gcr.io/cloud-builders/mvn
docker image does not have it installed, the appengine:deploy
goal fails.由于
gcr.io/cloud-builders/mvn
映像未安装它,因此appengine:deploy
目标失败。
I can think of two ways of working around this:我可以想到两种方法来解决这个问题:
1) Create a custom Cloud Build build step (Dockerfile) that has both maven and gcloud . 1) 创建一个包含maven和gcloud的自定义 Cloud Build 构建步骤 (Dockerfile)。 Then deploy it to your GCR and use it in your
cloudbuild.yaml
instead of gcr.io/cloud-builders/mvn
.然后将其部署到您的 GCR 并在您的
cloudbuild.yaml
而不是gcr.io/cloud-builders/mvn
使用它。
2) Do not use appengine-maven-plugin
, but split the build and deploy into several steps. 2)不要使用
appengine-maven-plugin
,而是将构建和部署分成几个步骤。
# cloudbuild.yaml
steps:
- name: 'gcr.io/cloud-builders/mvn'
args: ['package']
- name: 'gcr.io/cloud-builders/gcloud'
args: ['app', 'deploy', '/workspace/.../target/path-to-app.yaml']
Note that after building the WAR, you might need to use gcloud
several times to stage the app before calling gcloud app deploy
.请注意,在构建 WAR 之后,您可能需要多次使用
gcloud
来gcloud app deploy
程序,然后再调用gcloud app deploy
。
I recently ran into a similar error message when I upgraded to my new MacBook.我最近在升级到新 MacBook 时遇到了类似的错误消息。 I moved the
google-cloud-sdk
folder in the /usr/local/share/google/
directory ie /usr/local/share/google/google-cloud-sdk
and that solved my issue.我将
google-cloud-sdk
文件夹移动到/usr/local/share/google/
目录中,即/usr/local/share/google/google-cloud-sdk
并解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.