简体   繁体   English

在没有 docker 映像的 Azure 函数上部署可执行 JAR?

[英]Deploying an executable JAR on Azure functions without docker image?

I am trying to replicate on Azure Functions the example that is in Quickstart: Create a Go or Rust function in Java.我正在尝试在 Azure Functions 上复制快速入门中的示例:在 Java 中创建 Go 或 Rust 函数 I set up a couple of methods that respond to REST requests, and I bundled them as well as a Jetty server, that manages and routes the requests, into an executable Uber JAR.我设置了几个响应 REST 请求的方法,并将它们与一个管理和路由请求的 Jetty 服务器捆绑到一个可执行的 Uber JAR 中。 When I run java -jar handler.jar , an instance of a Jetty server is started, so I can navigate to http://localhost:8080/ping .当我运行java -jar handler.jar时,会启动一个 Jetty 服务器实例,因此我可以导航到http://localhost:8080/ping I can achieve the same by using the JRE I have installed on my computer when using func start with the following host.json :当使用带有以下host.jsonfunc start时,我可以使用我在计算机上安装的 JRE 来实现相同的目的:

     "customHandler": {
         "description": {
           "defaultExecutablePath": "java",
           "arguments": ["-jar", "handler.jar"]
         },
         "enableForwardingHttpRequest": true
       }

Now, I'm trying to deploy this app to Azure Functions.现在,我正在尝试将此应用程序部署到 Azure Functions。 One possible way would be to create a custom image with the following Dockerfile:一种可能的方法是使用以下 Dockerfile 创建自定义映像:

FROM mcr.microsoft.com/azure-functions/java:4-java11-slim
ENV AzureWebJobsScriptRoot=/home/site/wwwroot
COPY ["./functions", "/home/site/wwwroot"]

and start a function by using this image - I tried this and it works ok, but it seems to be quite inefficient to create a 1GB+ image, when the JAR I want to deploy takes up just a couple of MBs.并通过使用此图像启动一个功能 - 我尝试了这个并且它工作正常,但是当我要部署的 JAR 只占用几 MB 时,创建一个 1GB+ 的图像似乎效率很低。

I was wondering, if there is a way to avoid this step?我想知道,是否有办法避免这一步? For example, push only the JAR and all the .json files to functions and use the default JRE, that is included when I create a Function App with the Java runtime stack?例如,仅将 JAR 和所有.json文件推送到函数并使用默认 JRE,这在我使用 Java 运行时堆栈创建函数应用程序时包含? In other words, is it possible to achieve what I achieve locally when using func start , but use the JRE that is on azure instead?换句话说,是否可以在使用func start时实现我在本地实现的目标,但使用 azure 上的 JRE 代替?

The documentation ( "If your handler requires operating system or platform dependencies (such as a language runtime), you may need to use a custom container." ) is not that very clear about the topic.文档( “如果您的处理程序需要操作系统或平台依赖项(例如语言运行时),您可能需要使用自定义容器。” )关于该主题并不是很清楚。

Thank you!谢谢!

Have a look at the Triggers and annotations paragraph of the Azure Functions Java developer guide.查看 Azure Functions Java 开发人员指南的触发器和注释段落

In the function.json , set the scriptFile field to the (relative) location of your jar, and set entryPoint to the location of the method the Azure Function should execute.function.json中,将scriptFile字段设置为 jar 的(相对)位置,并将entryPoint设置为 Azure Function 应执行的方法的位置。 Then using the Azure Functions Core Tools , you can do func azure functionapp publish {function_app_name_in_Azure} --java to publish too the Function App in the cloud.然后使用Azure Functions Core Tools ,您可以执行func azure functionapp publish {function_app_name_in_Azure} --java在云中发布 Function App。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM