简体   繁体   中英

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. The build is currently triggered when I push to the master branch of my linked Github repository.

The application is a Spring Boot application with Maven, which is serving a simple API. I'm trying to issue the mvn appengine:deploy in my cloudbuild.yaml file, which looks like this:

# 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.

The triggered build run for about 20 seconds, and then fails with the following error message:

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

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

The appengine-maven-plugin requires the Cloud SDK to be installed. Since the gcr.io/cloud-builders/mvn docker image does not have it installed, the appengine:deploy goal fails.

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 . Then deploy it to your GCR and use it in your cloudbuild.yaml instead of gcr.io/cloud-builders/mvn .

2) Do not use appengine-maven-plugin , but split the build and deploy into several steps.

# 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 .

I recently ran into a similar error message when I upgraded to my new 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM