使用Dockerfile(IntelliJ)部署Google Flexible App Engine

时间:2018-08-01 16:11:34

标签: java docker google-app-engine intellij-idea app-engine-flexible

我无法通过IntelliJ将Java应用程序部署到App Engine(灵活)。

我从这个“基于Spring Boot的Hello World应用程序”教程开始

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

我成功完成了操作(并将Hello World应用程序作为灵活的应用程序部署到我的GCP项目中)。

然后,我将所有服务(我尝试迁移的Java应用程序中的服务)添加到此框架中。

我有一个密钥文件需要在服务初始化时读取,因此我将其添加到了Docker文件中(在./src/main/docker/目录下):

我的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

我的app.yaml文件

runtime: custom
env: flex

runtime_config:  # Optional
  jdk: openjdk8

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

manual_scaling:
  instances: 1

它编译。但是,当我尝试部署它(通过终端“ mvn appengine:deploy”或通过IntelliJ“ Google Cloud Tools->部署到App Engine”)时,它在应用程序启动时失败...

[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

我在这里做错了什么?

菲利普

1 个答案:

答案 0 :(得分:2)

您的Dockerfile似乎有几个问题-多个无关的FROM;没有ENTRYPOINT来运行您的jar

我成功测试了使用Cloud Tools for IntelliJ使用生成的jar Dockerfile将您的应用程序部署到App Engine flexible的步骤,

首先重命名您当前的Dockerfile,以便我们可以生成一个新文件。然后在Project Structure-> Facets-> App Engine Flexible下,生成一个新的Dockerfile:

enter image description here

在弹出的对话框中,请确保选择“ JAR”类型。

然后,在src/main/docker下,您将找到生成的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"]

如Dockerfile中所示,将占位符更新为构建的jar文件的名称(例如helloworld-springboot-0.0.1-SNAPSHOT.jar或您对其进行自定义的任何名称)。

使用此生成的文件作为起点(添加任何文件等),根据应用程序的需要自定义Dockerfile。

然后,使用Tools > Google Cloud Tools > Deploy to App Engine..,您应该会看到类似以下内容(正确指向您的app.yaml和Dockerfile):

enter image description here

运行部署,希望这次能够成功。