简体   繁体   中英

Deploy Google Flexible App Engine with Dockerfile (IntelliJ)

I'm having trouble deploying my Java app to the App Engine (Flexible) via IntelliJ.

I started from this "Spring Boot based Hello World app" tutorial

https://github.com/GoogleCloudPlatform/getting-started-java/tree/master/helloworld-springboot

that I managed to complete sucessfully (and deploy the Hello World app to my GCP project as a flexible app).

I then added all my services (the services from the Java app I'm trying to migrate) to this skeleton.

I have a key file that needs to be read on the services initialization so I added it in a Docker file (under the ./src/main/docker/ directory):

My Dockerfile

FROM openjdk:8-jre-alpine
RUN mkdir -p src/main/resources/
ADD keyfile.p12 src/main/resources/keyfile.p12
FROM google/cloud-sdk:alpine
RUN apk --update add openjdk8-jre
RUN gcloud components update

My app.yaml file

runtime: custom
env: flex

runtime_config:  # Optional
  jdk: openjdk8

handlers:
- url: /.*
  script: this field is required, but ignored

manual_scaling:
  instances: 1

It compiles. But when I try to deploy it (either via the terminal "mvn appengine:deploy" or via the IntelliJ "Google Cloud Tools -> Deploy to App Engine", it fails on the application startup...

[INFO] GCLOUD: cd7100a72410: Layer already exists
[INFO] GCLOUD: d4a58ad5c275: Layer already exists
[INFO] GCLOUD: a2e2afb03734: Pushed
[INFO] GCLOUD: 92624d7e4e7c: Pushed
[INFO] GCLOUD: latest: digest: sha256:c70d801102721c75b862ded5552cb967c1d464e2c02ae0f96129424da8553091 size: 1164
[INFO] GCLOUD: DONE
[INFO] GCLOUD: ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[INFO] GCLOUD: 
[INFO] GCLOUD: Updating service [default] (this may take several minutes)...
[INFO] GCLOUD: ...............................................................................................................................failed.
[INFO] GCLOUD: ERROR: (gcloud.app.deploy) Error Response: [9] 
[INFO] GCLOUD: Application startup error:
[INFO] GCLOUD: 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 03:41 min
[INFO] Finished at: 2018-08-01T18:04:17+02:00
[INFO] Final Memory: 10M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.google.cloud.tools:appengine-maven-plugin:2.0.0-rc1:deploy (default-cli) on project iron-dome: Flexible application deployment failed: com.google.cloud.tools.appengine.cloudsdk.process.ProcessHandlerException: com.google.cloud.tools.appengine.api.AppEngineException: Non zero exit: 1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.google.cloud.tools:appengine-maven-plugin:2.0.0-rc1:deploy (default-cli) on project iron-dome: Flexible application deployment failed
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Flexible application deployment failed
        at com.google.cloud.tools.maven.AppEngineFlexibleDeployer.deploy(AppEngineFlexibleDeployer.java:52)
        at com.google.cloud.tools.maven.DeployMojo.execute(DeployMojo.java:29)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
        ... 20 more
Caused by: com.google.cloud.tools.appengine.api.AppEngineException: com.google.cloud.tools.appengine.cloudsdk.process.ProcessHandlerException: com.google.cloud.tools.appengine.api.AppEngineException: Non zero exit: 1
        at com.google.cloud.tools.appengine.cloudsdk.CloudSdkAppEngineDeployment.deploy(CloudSdkAppEngineDeployment.java:90)
        at com.google.cloud.tools.maven.AppEngineFlexibleDeployer.deploy(AppEngineFlexibleDeployer.java:50)
        ... 23 more
Caused by: com.google.cloud.tools.appengine.cloudsdk.process.ProcessHandlerException: com.google.cloud.tools.appengine.api.AppEngineException: Non zero exit: 1
        at com.google.cloud.tools.appengine.cloudsdk.process.LegacyProcessHandler.handleProcess(LegacyProcessHandler.java:87)
        at com.google.cloud.tools.appengine.cloudsdk.GcloudRunner.run(GcloudRunner.java:96)
        at com.google.cloud.tools.appengine.cloudsdk.CloudSdkAppEngineDeployment.deploy(CloudSdkAppEngineDeployment.java:88)
        ... 24 more
Caused by: com.google.cloud.tools.appengine.api.AppEngineException: Non zero exit: 1
        at com.google.cloud.tools.appengine.cloudsdk.process.NonZeroExceptionExitListener.onExit(NonZeroExceptionExitListener.java:28)
        at com.google.cloud.tools.appengine.cloudsdk.process.LegacyProcessHandler.syncRun(LegacyProcessHandler.java:144)
        at com.google.cloud.tools.appengine.cloudsdk.process.LegacyProcessHandler.handleProcess(LegacyProcessHandler.java:83)
        ... 26 more
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

What am I doing wrong here?

Philippe

There seems to be a couple issues with your Dockerfile - multple unrelated FROM s; no ENTRYPOINT to run your jar

I successfully tested deploying your app to App Engine flexible with the generated jar Dockerfile using Cloud Tools for IntelliJ using the following steps:

First rename your current Dockerfile so that we can generate a new one. Then under Project Structure -> Facets -> App Engine Flexible, generate a new Dockerfile:

在此处输入图片说明

In the dialog that pops up, be sure to select the "JAR" type.

Then, under src/main/docker you'll find the generated Dockerfile:

FROM gcr.io/google_appengine/openjdk
# Replace occurrences of YOUR_ARTIFACT_NAME_HERE with the name of the deployed jar
ADD YOUR_ARTIFACT_NAME_HERE.jar /app/
ENTRYPOINT ["/docker-entrypoint.bash"]
CMD ["java","-jar","/app/YOUR_ARTIFACT_NAME_HERE.jar"]

As indicated in the Dockerfile, update the placeholder to the name of your built jar file (eg helloworld-springboot-0.0.1-SNAPSHOT.jar , or whatever you customized it to).

Customize the Dockerfile as needed for your application using this generated one as a starting point (adding any files, etc).

Then, using Tools > Google Cloud Tools > Deploy to App Engine.. you should see something like this (pointing correctly to your app.yaml and Dockerfile):

在此处输入图片说明

Run the deployment and hopefully it succeeds this time.

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