I am trying to replicate on Azure Functions the example that is in Quickstart: Create a Go or Rust function in Java. 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. When I run java -jar handler.jar
, an instance of a Jetty server is started, so I can navigate to 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
:
"customHandler": {
"description": {
"defaultExecutablePath": "java",
"arguments": ["-jar", "handler.jar"]
},
"enableForwardingHttpRequest": true
}
Now, I'm trying to deploy this app to Azure Functions. One possible way would be to create a custom image with the following 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.
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? 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?
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!