英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论