Open FieryCod opened 2 years ago
For completeness, I'm attaching the full stack of what happens:
response/resource-response
under the hood https://github.com/metosin/reitit/blob/master/modules/reitit-ring/src/reitit/ring.cljc#L237GraalVM 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.
Why is it important to add the following change to Ring if it's only for GraalVM?
frameworks
are based on Ring. If we add the following change in the Ring
we will not have to patch other libraries that use response/resource-response
.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
.
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:
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
, bb
commands. Make sure you have a docker
, 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
, bb
CLI'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: https://github.com/ring-clojure/ring/issues/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.
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 :joy:
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-ui
on AWS Lambda.