gpt4 book ai didi

java - 使用 Dockerfile (IntelliJ) 部署 Google 灵活应用引擎

转载 作者:行者123 更新时间:2023-12-02 02:00:41 28 4
gpt4 key购买 nike

我在通过 IntelliJ 将 Java 应用程序部署到 App Engine (Flexible) 时遇到问题。

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

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

我成功完成了这一任务(并将 Hello World 应用作为灵活的应用部署到我的 GCP 项目中)。

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

我有一个需要在服务初始化时读取的 key 文件,因此我将其添加到 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 -> Deploy to 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

我在这里做错了什么?

菲利普

最佳答案

您的 Dockerfile 似乎存在一些问题 - 多个不相关的 FROM;没有ENTRYPOINT来运行你的jar

我使用 Cloud Tools for IntelliJ 成功测试了如何使用生成的 jar Dockerfile 将您的应用程序部署到灵活的 App Engine使用以下步骤:

首先重命名当前的 Dockerfile,以便我们可以生成一个新的。然后在 Project Structure -> Facets -> App EngineFlexible 下,生成一个新的 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 作为起点(添加任何文件等),根据应用程序的需要自定义 Dockerfile。

然后,使用工具 > Google Cloud Tools > 部署到 App Engine.. 您应该看到类似这样的内容(正确指向您的 app.yaml 和 Dockerfile):

enter image description here

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

关于java - 使用 Dockerfile (IntelliJ) 部署 Google 灵活应用引擎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51637903/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com