-
Notifications
You must be signed in to change notification settings - Fork 526
Add support for GraalVM ResourceURLConnection #447
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
Conversation
For completeness, I'm attaching the full stack of what happens:
- Server hits the swagger-ui ring handler
https://github.com/metosin/reitit/blob/master/modules/reitit-swagger-ui/src/reitit/swagger_ui.cljc#L40 - Reitit uses
response/resource-responseunder the hood https://github.com/metosin/reitit/blob/master/modules/reitit-ring/src/reitit/ring.cljc#L237 ring/ring-core/src/ring/util/response.clj
Line 337 in bc87e3b
(defn resource-responsering/ring-core/src/ring/util/response.clj
Line 355 in bc87e3b
(let [response (url-response resource)]ring/ring-core/src/ring/util/response.clj
Line 313 in bc87e3b
(defn url-response- And here the protocol is different:
ring/ring-core/src/ring/util/response.clj
Line 244 in bc87e3b
(defmulti resource-data
GraalVM native-image produces the binary with embedded resources from jar:. They substitute the protocol with resource:, so that they can .getResource embedded in the binary.
- https://github.com/oracle/graal/blob/db22885e2deb21ff0c1a72314f7b9bb86b7d334c/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Resources.java#L128
- https://github.com/oracle/graal/blob/db22885e2deb21ff0c1a72314f7b9bb86b7d334c/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Resources.java#L128
Why is it important to add the following change to Ring if it's only for GraalVM?
- Almost all of the Clojure
frameworksare based on Ring. If we add the following change in theRingwe will not have to patch other libraries that useresponse/resource-response. - Without this change GraalVM returns a cryptic error on runtime.
Thanks for the patch. I think explanations of why this is included should be mainly confined to the commit message rather than as part of a comment. We can limit the comment to something like ;; GraalVM resource scheme.
bc87e3b to
ac1c0d8
Compare
Commit messages of this repository should follow the seven rules of a great Git commit message, as mentioned in the project's contributing guidelines. It looks like there's a few issues with the commit messages in this pull request:
- The commit message should not contain markdown.
- The commit message body has a line over 72 characters.
GraalVM native-image produces the binary with embedded resources from jar:. The protocol is then substituted to resource:.
ac1c0d8 to
ac9625c
Compare
Thank you so much @weavejester. I have updated the patch. Hope the changes match Ring standards :)
BTW: Thank you for making Ring!
@weavejester Is there something I can do more to have it merged?
Apologies for the delay. I haven't had the time to setup a GraalVM environment to test this properly. Do you have an example project that uses Ring and GraalVM?
Don't sorry, it's all good! I'm patient :)
Working demo: here
Source code: here
I have included the patch in my library (see here).
How to test if patch is correct
-
Install
aws,sam,bbcommands. Make sure you have adocker, and at least 8GB of RAM. (if you're using mac enable 8GB in Docker Desktop). -
Configure you AWS Account via
aws configure -
Clone the library.
-
Remove the patch.
-
Go to the
examples/native/ -
You would need
aws,sam,bbCLI's to deploy. -
Run the following commands in
examples/native/:bb hl:compile && bb hl:native:executable && sam deploy --guided
-
After deployment get the URL of the endpoint and navigate to
<URL>/api-docs/index.html. It should not work without the patch.
PS: If you're using the Mac with M1 you would need to change :image in bb.edn to ghcr.io/fierycod/holy-lambda-builder:aarch64-java11-21.3.0.
Thanks for the link, but I'm looking for something a little easier to set up, and something we can keep around to test this in future (or even automate). For example, a small project that uses the Leiningen GraalVM plugin.
Hi @weavejester! Sorry for not responding for so long.
Here is the repro/example. Let me know if it's minimal enough.
I've also found this issue: #370, which I was not aware of before.
I've also prepared the configuration necessary to run Ring apps with GraalVM CE 21.3.0. See here. If you're interested in pushing it upstream, I'm happy to help with this.
This PR is not yet ready to merge. @borkdude found a corner case.
When serving a resource directory e.g. public at /public and trying to access the /public the resource-data will return an URL instead of nil.
Thanks for the heads up.
skynet-gh
commented
Mar 24, 2022
Any updates on this? It seems for now that I need to add these lines manually to every project using ring (or perhaps reitit with ring) that I want to build a native image.
Waiting for this too!
@agorgl @skynet-gh I forgot to create an issue on the GraalVM repo. I will try to find some time this week to address it, but I don't promise anything 😂
4c18803 to
a01030f
Compare
0d7f29a to
0103527
Compare
13fdd61 to
475f4dd
Compare
Dear @weavejester please consider adding the following patch to
ring.Why this is important?
I'm trying to patch as many libraries as it's possible to make the GraalVM Clojure applications easier to configure.
With the following change, I would be able to deploy a full Clojure application with
metosin/swagger-uion AWS Lambda.