阻止在使用Java 11部署单个JAR包到Google App Engine时的构建尝试。

huangapple go评论93阅读模式
英文:

Prevent build attempt when deploying single jar on Google App Engine with java11

问题

我有一个构建在Google Cloud之外的CI系统上的Spring Java项目。最终的构建命令是gradle bootJar。我想部署生成的JAR文件到Google App Engine。

建议的方法只是调用gcloud app deploy my.jar。不幸的是,这种方法对我来说不起作用,因为应用程序需要比默认实例类型提供的RAM更多(F1 = 256MB)。所以我必须以某种方式指定实例类型。

我当前的方法是创建一个自定义的app.yaml文件 - 并且还有一个.gcloudignore文件,以确保只上传JAR文件。我的app.yaml文件如下所示:

runtime: java11
instance_class: F2
entrypoint: java -noverify -jar my.jar

虽然实例正在工作,但实例日志显示正在尝试并行构建(日志摘录):

Starting Step #5 - "builder"
Step #5 - "builder": Already have image (with digest): eu.gcr.io/gae-runtimes/buildpacks/java11/builder:java11_20200913_11_0_RC00
Step #5 - "builder": === Java - App Engine (google.java.appengine@0.9.0) ===
Step #5 - "builder": DEBUG: Using GOOGLE_RUNTIME: java11
Step #5 - "builder": DEBUG: Using config appengine.Config{Runtime:"java11", Entrypoint:appengine.Entrypoint{Type:"User", Command:"java -noverify -jar my.jar", WorkDir:""}, MainExecutable:""}
Step #5 - "builder": === Utils - Label Image (google.utils.label@0.0.1) ===
Finished Step #5 - "builder"

当我直接在gcloud app deploy中指定JAR文件时,这些构建尝试不会发生,但正如我所说,由于内存不足,这种方法失败。

理想情况下,我希望使用自己的app.yaml来指定其他配置选项。但我不想一直发生构建。

所以,是否有一种方法可以抑制这些构建尝试,或者可以传递通常在app.yaml中的其他配置选项到gcloud app deploy my.jar调用中?

英文:

I have a spring java project which is built on a CI system outside of google cloud. The final build command is gradle bootJar . I want to deploy the resulting jar to Google App Engine.

The suggested way to do so is just calling gcloud app deploy my.jar . Unfortunately, this approach doesn't work for me as the application needs more RAM than provided by the default instance type (F1 = 256MB). So I have to specify the instance type somehow.

My current approach is to create a custom app.yaml - and also a .gcloudignore to ensure that only the jar is uploaded. My app.yaml looks like this:

runtime: java11
instance_class: F2
entrypoint: java -noverify -jar my.jar

While the instance is working, the instance logs indicate that a build is tried in parallel (log excerpt):

Starting Step #5 - "builder"
Step #5 - "builder": Already have image (with digest): eu.gcr.io/gae-runtimes/buildpacks/java11/builder:java11_20200913_11_0_RC00
Step #5 - "builder": === Java - App Engine (google.java.appengine@0.9.0) ===
Step #5 - "builder": DEBUG: Using GOOGLE_RUNTIME: java11
Step #5 - "builder": DEBUG: Using config appengine.Config{Runtime:"java11", Entrypoint:appengine.Entrypoint{Type:"User", Command:"java -noverify -jar my.jar", WorkDir:""}, MainExecutable:""}
Step #5 - "builder": === Utils - Label Image (google.utils.label@0.0.1) ===
Finished Step #5 - "builder"

These build attempts do not happen when I specify the jar directly in gcloud app deploy, but as said this fails due to memory.

Ideally, I want to use my own app.yaml in order to specify other configuration options as well. But I don't want to have a build happening all the time.

So is there a way to either suppress these build attempts or, alternatively, pass additional configuration options which would usually be in an app.yaml to a gcloud app deploy my.jar call?

答案1

得分: 1

你正在尝试的操作是不可能的,如果你使用 app.yaml 来部署你的应用程序,构建将始终会被触发,而如果你使用 gradle,你将无法像 app.yaml 那样选择 instance_class。因此,针对你的问题没有最佳解决方案。然而,有一个替代方案,就是使用 App Engine Flex 来部署一个包含你的 my.jar 文件的容器。

你可以查看这个链接,了解如何创建一个 Docker 文件来运行一个 .jar 应用。此外,在这个文档中,你可以看到如何将包含你的 jar 文件的 Docker 部署到 App Engine Flex 中,这个配置还会创建一个 app.yaml 文件,在这个 app.yaml 文件中,你可以指定运行应用所需的基础设施。正如你在这第二个文档中所看到的,你可以向 app.yaml 添加以下配置块,以让 App Engine Flex 知道你的应用程序容器需要多少基础设施:

resources:
  cpu: 2
  memory_gb: 2.3
  disk_size_gb: 10
  volumes:
  - name: ramdisk1
    volume_type: tmpfs
    size_gb: 0.5

注意:由于你的应用程序已经在 App Engine Standard 的实例中运行,我认为如果你可以简单地忽略构建日志,那么所提出的替代方案可能并不值得努力去实现。

英文:

What you are trying to do is not possible, if you use a app.yaml to deploy your app a build will always be triggered and if you use gradle you will not be able to select the instance_class like the app.yaml allows you to do. So there is no optimal solution for your problem, However there is an alternative for this, which is to use App Engine Flex to deploy a container with your my.jar file.

You can check this link for how to create a docker file to run a .jar app. Also in this documentation you can see how you can deploy that docker containing your jar file to App Engine Flex, this configuration will also create an app.yaml file and in that app.yaml you can specify the infrastructure that you will need to run your app. As you can see in this second documentation, you could add the following block of configurations to the app.yaml to let App Engine Flex know how much infrastructure you need for your app's container:

resources:
  cpu: 2
  memory_gb: 2.3
  disk_size_gb: 10
  volumes:
  - name: ramdisk1
    volume_type: tmpfs
    size_gb: 0.5

NOTE: Since you already have your app up and running in an instance of App Engine Standard I would say that the proposed alternative is not worth the effort if you can simply ignore the build logs.

huangapple
  • 本文由 发表于 2020年10月16日 16:19:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/64385431.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定