Azure / azure-dev

A developer CLI that reduces the time it takes for you to get started on Azure. The Azure Developer CLI (azd) provides a set of developer-friendly commands that map to key stages in your workflow - code, build, deploy, monitor, repeat.
https://aka.ms/azd
MIT License
395 stars 190 forks source link

[Issue] Java Azure Function not deployed #4155

Closed yortch closed 3 weeks ago

yortch commented 1 month ago

Output from azd version Run azd version and copy and paste the output here:

azd version 1.9.5 (commit cd2b7af9995d358aab33c782614f801ac1997dde)

Describe the bug When deploying Azure Function using azd deploy (or azd up), the Azure function is created successfully (using infra/terraform), but the function is not actually deployed. When reviewing the files uploaded, I only see a file named app.jar, without the host..json, or any of the dependent libraries needed for the app to function. It appears that azd deploy is uploading the output of azd package which is a single jar, even though azd package appears to go through the correct steps to package the required files for the azure function.

See azd output:

NFO] --- jar:3.3.0:jar (default-jar) @ azure-function ---
[INFO] Building jar: /mnt/c/Users/jbalderas/source/repos/protobuf/target/azure-function-1.0.0-SNAPSHOT.jar
[INFO]
[INFO] --- azure-functions:1.36.0:package (package-functions) @ azure-function ---
[INFO] Java home : /home/jbalderas/.sdkman/candidates/java/current
[INFO] Artifact compile version : 17
[INFO]
[INFO] Step 1 of 8: Searching for Azure Functions entry points
[INFO] 1 Azure Functions entry point(s) found.
[INFO]
[INFO] Step 2 of 8: Generating Azure Functions configurations
[INFO] Generation done.
[INFO]
[INFO] Step 3 of 8: Validating generated configurations
[INFO] Validation done.
[INFO]
[INFO] Step 4 of 8: Copying/creating host.json
[INFO] Successfully saved to /mnt/c/Users/jbalderas/source/repos/protobuf/target/azure-functions/azure-function-protobuf/host.json
[INFO]
[INFO] Step 5 of 8: Copying/creating local.settings.json
[INFO] Successfully saved to /mnt/c/Users/jbalderas/source/repos/protobuf/target/azure-functions/azure-function-protobuf/local.settings.json
[INFO]
[INFO] Step 6 of 8: Saving configurations to function.json
[INFO] Starting processing function: HttpTriggerJava
[INFO] Successfully saved to /mnt/c/Users/jbalderas/source/repos/protobuf/target/azure-functions/azure-function-protobuf/HttpTriggerJava/function.json
[INFO]
[INFO] Step 7 of 8: Copying JARs to staging directory /mnt/c/Users/jbalderas/source/repos/protobuf/target/azure-functions/azure-function-protobuf
[INFO] Copied successfully.
[INFO] Step 8 of 8: Installing function extensions if needed
[INFO] Extension bundle specified, skip install extension
[INFO] Successfully built Azure Functions.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  44.314 s
[INFO] Finished at: 2024-07-29T16:53:40-04:00
[INFO] ------------------------------------------------------------------------
  (✓) Done: Packaging service protobuf
  - Package Output: /tmp/protobuf-protobuf-azddeploy-1722286420.zip

To Reproduce

  1. Clone repo: https://github.com/yortch/protobuf-function
  2. Checkout azd branch: git checkout azd
  3. Run azd up

Expected behavior I expect the function to be deployed successfully with the HTTP Trigger binding.

Environment Information on your environment:

Additional context Issue appears to be incorrect output from azd package, assuming this is supported

yortch commented 1 month ago

As a temporary workaround I ended up using a postdeploy script: https://github.com/yortch/protobuf-function/blob/main/azure.yaml#L16 which effectively deploys the function using this command: func azure functionapp publish $env:AZURE_FUNCTION_NAME I still would like confirmation as to whether this is supported, to determine if I'm doing something incorrectly or this is a defect.

weikanglim commented 1 month ago

@yortch Thanks for reporting this. When Java support was introduced over a year ago, support was added for ACA + App Service but not Functions. The behavior you're seeing is unfortunately the default behavior of deploying the packaged artifact, which happens to be app.jar without host.json included.

If azd could automatically figure out the staging directory used in mvn package, or perhaps just let the user specify it directly in azure.yaml as dist, and zip the directory that includes host.json, app.jar, I could see this working without too much effort.

yortch commented 1 month ago

Thank you @weikanglim for the input. The documentation lists both Azure Functions and Java as supported features, so I assumed this combination was supported: [https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/supported-languages-environments] It does seem like every other azd operation supports Azure Java Functions, except for the package (and deploy) steps. I tried on a separate repo to provide a dist path which included a zip file with the necessary files to deploy the function, unfortunately I got this error:

ERROR: failed packaging service 'fn-quarkus': no java archive files (.jar, .ear, .war) found in C:\Users\jbalderas\source\repos\fn-quarkus\target\dist

I also tried renaming this zip file as a jar file, and azd deploy published the file successfully, but it assumes it is the Java code jar file and does not upload the required function.zip file. I would assume most developers are using the azure-functions-maven-plugin to develop Azure Functions in Java, so it would be ideal if the deploy step would take the output from target\azure-functions\function-name when deploying the function.

weikanglim commented 4 weeks ago

@yortch, there's a private build in the linked PR (install instructions here) that uses target/azure-functions/<functionAppName> by default in deploying functions if you'd like to give it a try. You can also point the dist path at a custom staging directory, if needed.