Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy using VS or VS Code #3

Closed
rdorris opened this issue Jul 16, 2021 · 20 comments
Closed

Deploy using VS or VS Code #3

rdorris opened this issue Jul 16, 2021 · 20 comments
Labels
accepted Tagging Ideas I like and will implement enhancement New feature or request question Further information is requested

Comments

@rdorris
Copy link

rdorris commented Jul 16, 2021

This project looks like exactly what I need. However, and as you hint at in the readme, I have little experience with Java/Maven/etc but do use VS and Azure daily (C#/Asp.net core).
Would you be able to provide simple instructions using VS or VS Code for deployment? I'm trying to avoid the installation of another IDE and SDK.
Thanks for building this!

@cajuncoding
Copy link
Owner

cajuncoding commented Jul 16, 2021

It's great that you will find this project helpful!

I can completely understand you wanting to avoid the Java environment (it can be a massive pain). But, that was exactly the goal of sharing this project -- to hopefully help you get past that and get on to more important things.

Unfortunately I don't think there is an easier way around other than to just install IntelliJ IDEA Community -- it's by far the easiest and best Java IDE's and using it to publish the project to Azure Functions is likely the easiest and most efficient way to get it up and running . . . other than having someone else do it for you.

The Maven parts should all be in place, so the key steps are:

  1. (Highly Recommended) Uninstall and remove any/all other versions of Java you may have on your development workstation; this will save you a lot of headaches.
  2. Install the dependencies: Azure Functions compliant Zulu Java JDK, Maven, and Azure Funcitons Core Tools.
    • Make sure this Zulu installation is the only Java runtime on your machine to save alot of headaches.
    • Pretty good documentation is here...
    • One of the hardest parts of this is getting Azure Functions Core Tools setup as expected... thier install process has evolved over time and can be tricky but now with their installer and Azure Functions runtime v3 it is definitely easier...
    • image
  3. Now install IDEA IntelliJ Community Addition after Java JDK is already installed.
  4. Install the latest Azure Toolkit for IntelliJ (documented very well here).
  5. Pull down the Repo locally...
  6. Open the Repo root folder in IDEA IntelliJ to open the project.
  7. Verify and setup IntelliJ to point to your installed JDK (from above); with any luck it will have automatically configured this.
    • image
  8. Update IntelliJ Build settings to delegate to Maven as documented here (not set by default since Java has many options and leaves this to the dev team).
    • image
  9. Now you should be ready to build the project:
    • image
  10. Ensure that IntelliJ is configured correctly to find the right location for Azure Core Tools:
    • Installer will put the func.exe here: C:\Program Files\Microsoft\Azure Functions Core Tools\func.exe
      image
  11. And Run / Debug:
    • image
  12. Now you can Deploy . . . but first Log into your Azure account:
    - Ensure that you Sign into your Azure Account First!
    - image
  13. Once Logged in then you'll be able to Deploy to Azure Functions instance:
    • It's Easiest to have FIRST already created your Azure Function instance, but the Toolkit does have the ability to create a new one on the fly.
    • image
    • image

There may be a way to automate deployment via some GitHub Actions, but I've not worked through that because once I got the environment up and running, it's just soo easy to deploy as needed via the Toolkit in the IDE.

Remember to give the project a Star, Thanks!
Brandon

@cajuncoding
Copy link
Owner

cajuncoding commented Jul 16, 2021

@rdorris FYI.... I'm investigating the use of VS Code . . . I'll get back to you if I get it working.

@rdorris
Copy link
Author

rdorris commented Jul 16, 2021

I've installed java and maven and opened the project in code. Installed a bunch of extensions for java build/debug and hit run. Got the following... anything useful to you?

[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ apachefop-serverless-az-func ---
[INFO] Building jar: C:\Users\Rick.WAVEDOMAIN\Source\Repos\ApacheFOP.Serverless\apachefop-serverless-az-func\target\apachefop-serverless-az-func-1.1-SNAPSHOT.jar
[INFO]
[INFO] --- azure-functions-maven-plugin:1.9.2:package (package-functions) @ apachefop-serverless-az-func ---
[WARNING] The POM for com.microsoft.azure.applicationinsights.v2015_05_01:azure-mgmt-insights:jar:1.0.0-beta is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 20.699 s
[INFO] Finished at: 2021-07-16T15:58:41-07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.microsoft.azure:azure-functions-maven-plugin:1.9.2:package (package-functions) on project apachefop-serverless-az-func: Execution package-functions of goal com.microsoft.azure:azure-functions-maven-plugin:1.9.2:package failed: An API incompatibility was encountered while executing com.microsoft.azure:azure-functions-maven-plugin:1.9.2:package: java.lang.ExceptionInInitializerError: null
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>com.microsoft.azure:azure-functions-maven-plugin:1.9.2
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy

@cajuncoding
Copy link
Owner

cajuncoding commented Jul 16, 2021

The error isn't clear, but since I was curious, I've been mucking with VS Code for a couple hours now and all I can say is that it is flaky... doesn't want to let me cleanly import the project and recognize the existing Azure Function classes.

Since your error says something about an incompatible API I'd make sure that you have the right version of Java runtime configured in VS Code (and in your machine environment variables), that's one of the bigger gotchas with Java is ensuring that your environment variables are set up correctly; something that IntelliJ lets you override and sometimes makes life alot easier.

image

More details from my side:
What I have successfully got working is that the project will open, Java extensions are installed, and both VS Code launch.json and tasks.json setup (whether they are correct is still unknown). But, the Maven build works successfully as it should!
image

But, the native Run/Debug will not work, and throws other module conflict errors that Maven obviously has no issues resolving and appear like red herrings since IntelliJ has no issues.

And, no matter what I try I can't get the Azure Functions tab to recognize the Functions from the Java project.

@rdorris
Copy link
Author

rdorris commented Jul 16, 2021

my java:
java 16.0.1 2021-04-20
Java(TM) SE Runtime Environment (build 16.0.1+9-24)
Java HotSpot(TM) 64-Bit Server VM (build 16.0.1+9-24, mixed mode, sharing)

I did have to add <functionAppName>FOPService</functionAppName> to <properties> to get code to not complain about a missing functionAppName.

@cajuncoding
Copy link
Owner

As noted in the Readme and in my post above, Azure Functions only supports very specific versions of Java 8 (aka v1.8), or Java 11.

And I’ve updated this project to now use Java 11 with Functions runtime V3! So you need to make sure your system is using the Zulu Java 11, anything else will not work due to dependencies of the Azure Functions libraries!

@rdorris
Copy link
Author

rdorris commented Jul 17, 2021

Yep, starting at the beginning and uninstalled everything.
Now using java:
openjdk version "11.0.11" 2021-04-20 LTS
OpenJDK Runtime Environment 21.4-(Zulu-11.48+21-win_x64)-Microsoft-Azure-restricted (build 11.0.11+9-LTS)
OpenJDK 64-Bit Server VM 21.4-(Zulu-11.48+21-win_x64)-Microsoft-Azure-restricted (build 11.0.11+9-LTS, mixed mode)

And have installed Azure Functions 3.0.3477

@cajuncoding
Copy link
Owner

cajuncoding commented Jul 17, 2021

I’ve logged off for the day… as noted above I tried to get VSCode to import the current project and load it, but it was missing various key project elements…. But even after adding a valid launch.json, and tasks.json Inside the .vscode folder I was only able to get Maven build working but no ability to run/debug and it wouldn’t even show or recognized the Function classes either.

I did get some really odd module import conflicts but those then magically disappeared after banging on it a while (figuratively speaking).

But all that leads me too believe that even more project setup/config issues exist.

I think the next strategy is to get a ”Hello World” Java Azure Function working and running locally first, and then migrate the ApacheFOP.Serverless source into that working solution folder for VSCode, and that may make it more reliable.

In theory both VSCode & IntelliJ project settings/config can coexist together so this would be a really nice thing to commit with the solution….but it’ll take more time next week to iron out a working POC and try again.

@rdorris
Copy link
Author

rdorris commented Jul 17, 2021

Thanks so much for working on this.
In the meantime, I kinda have it working in IntelliJ but whenever I post to the function, I'm getting:
System.Private.CoreLib: Exception while executing function: Functions.ApacheFOP. Microsoft.Azure.WebJobs.Script: Did not find any initialized language workers.

This is what I have for the run configuration:
image
Are there some other App Settings that I need?

@cajuncoding
Copy link
Owner

cajuncoding commented Jul 17, 2021

Ok, I didn't realize you were marching down the IntelliJ Path... here's one last response (before my Wife kills me)...

Add each of the following Keys into that App Settings list for your run configuration and see if this helps it to run locally:

  • FUNCTIONS_WORKER_RUNTIME = java
  • FUNCTIONS_EXTENSION_VERSION = ~3
  • FUNCTIONS_CORE_TOOLS_DISPLAY_LOGO = true (pretty sure this is optional, but I like having it)
  • JAVA_HOME = C:\Program Files\Zulu\zulu-11\ (may be optional, but at one point this was the only way I got it to find the right version before uninstalling everything else)
  • AzureWebJobsStorage = UseDevelopmentStorage=true OR Initialize a new Azure Function in the Portal to get a valid Web Jobs storage key
    • Note: this one is required for the KeepWarmFunction that helps keep the Azure function performance up after sitting for a while... you can always just comment out that Function class to eliminate this dependency, but it's very helpful in production environments.)
    • _Note: IntelliJ currently doesn't natively enable local Azure Storage Emulator or Azurite (the newer replacement) so a real connection string works best with IntelliJ; but local setting may work better with VS Code.
  • KeepWarmCronSchedule = 0 */5 * * * * (also required configuration for the KeepWarmFunction)
  • DebuggingEnabled = true (Optional but very helpful once you start using it to return debug details in the responses).

image

I guess the run configuration is not saved with the project.... I do suppose I could beef up the Readme file a bit. And probably even do a video of a from scratch setup; I just haven't been able to afford any downtime to uninstall it all since I use this pretty often for my projects . . . 😁

@rdorris
Copy link
Author

rdorris commented Jul 18, 2021

So I did as you suggested... I created a new java function project in VS and then copied over your code. Few configuration changes here and there and I think I have it working!

@rdorris
Copy link
Author

rdorris commented Jul 20, 2021

@rdorris FYI.... I'm investigating the use of VS Code . . . I'll get back to you if I get it working.

Do you want any of the stuff I did to get it working in VS Code?
(Hope you got the coffees I bought)

@cajuncoding
Copy link
Owner

@rdorris Yes I did get the very generous coffee donation you sent! It's very much appreciated and totally made my day! I will certainly enjoy several E22's!!!

Yes, that's awesome that you have it working well in VSCode! I really do think that would be an excellent addition to the project -- as I wasn't aware that VSCode experience with Java would be very good, but as you noted it's perfect for those that don't want/need to install another IDE (though there is still some setup specific for Java).

But, absolutely, please submit a PR for me to check out 👍👍👍!

@rdorris
Copy link
Author

rdorris commented Jul 20, 2021

AzureFOP.zip
I created a new project on a private git server. I've attached the code and stuff. Biggest changes were the excludes in the pom.xml
image

@cajuncoding
Copy link
Owner

cajuncoding commented Jul 21, 2021

Awesome, yes I knew something would need to be excluded but I could not quickly find where the conflict was being caused....There is definitely a different behavior between VS Code Java Extensions and Maven . . . whereby Maven was resolving conflicts just fine. Bravo for tracking them down!

So are you liking the experience via VS Code?

@rdorris
Copy link
Author

rdorris commented Jul 21, 2021 via email

@cajuncoding
Copy link
Owner

Gotcha... so you guys are already syndicating content to different formats... yeah Apache FOP should work much better than Html to Pdf converters. If you're interested I wrote a whole blog piece on that topic (as I often have to explain this to clients so it was easier to just consolidate it into a couple articles:

Once you get the hang of the Xsl-FO markup you can create pretty decent looking reports... with combination of portrait/landscape, etc. The main tip for layout is to realize that the old-days of table-based-layouts work really well with Xsl-FO :-) and always avoid absolute positioning. Nesting tables and creating helper functions to create default empty blocks and table structures will greatly help. At our current client we post-process the docs with PdfSharp helpers to then merge in other Pdfs and Images uploaded by users that have been resized and normalized . . .

Good Luck!

@cajuncoding cajuncoding added question Further information is requested enhancement New feature or request accepted Tagging Ideas I like and will implement labels Aug 29, 2021
@eferfolja
Copy link

I started playing around with this project.

@cajuncoding, big thanks.

I managed to deploy it without installing java or IntelliJ. I used GitHub Actions and @rdorris code posted in #3 (comment) and following the steps found here.

I changed only the following settings:

env:
  AZURE_FUNCTIONAPP_NAME: your-app-name      # set this to your function app name on Azure
  POM_XML_DIRECTORY: '.'                     # set this to the directory which contains pom.xml file
  POM_FUNCTIONAPP_NAME: AzureFopFunction     # set this to the function app name in your local development environment
  JAVA_VERSION: '11'                         # set this to the dotnet version to use

Now I have a CI/CD in place for a java Azure Function without even having java installed locally on my dev machine!

I will further test in the future but at the moment the sample works.

@cajuncoding, @rdorris great work!

@cajuncoding
Copy link
Owner

cajuncoding commented Oct 25, 2021

@eferfolja that's great! Of course you won't be able to test/debug the actual code locally, but if you're just debugging your own Xsl-FO markup then you may not need to actually run locally. Because the event log is returned to you if you have the debugging enabled in the Azure Function configuration values... (I've fixed a couple encoding bugs recently affecting that)...

If you don't mind, give the project a Star 🌟

Thanks for Sharing! 👏👏👏

@cajuncoding
Copy link
Owner

cajuncoding commented Oct 26, 2021

FYI @rdorris

I finally had time to work through this and have now fully updated the project to work with VS Code & IntelliJ IDEA. 🙌 now tagged as version 1.4-SNAPSHOT in the pom.xml.

All configuration files for both VS Code & IntelliJ (of which both use folder context configs) have been included in the code and checked into the repository. This should make it easier for anyone to get up and running with either IDE ✅.

I also resolved several issues as follows:

  1. A bug in the Font loading/path handling when running in Windows Host (due to existing font paths).
  2. Updated Microsoft's azure-functions-maven-plugin to address various issues (esp. the need for a GUID in the deployment name which broke VS Code's ability to debug.
  3. Pom.xml cleanup
  4. Various other cleanup items as noted in VS Code Java "Problems" tab.

Have also now tested all of the following to now be working in both VS Code & IntelliJ IDEA:

  1. Local running and debug support!
  2. Embedded custom Font loading and handling in both Linux & Windows Azure Functions Hosts -- which now works as expected with OS based fonts loaded via in Apache FOP.
  3. Deployment to Azure to both Linux & Windows Azure Function Hosts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Tagging Ideas I like and will implement enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants