Closed ilyabo closed 9 years ago
you should be generating a standalone runnable jar using leing ring uberjar
instead of lein uberjar
. Once built that way you should be able to use web: java $JVM_OPTS -jar target/myapp.jar
to run it. I'll update the procfile to use that method.
Thanks Dmitry! But how do I make Heroku run lein ring uberjar
instead of lein uberjar
when the slug is compiled? Do I need a special buildpack for that?
Hmm, there does appear to be one here, but I haven't actually tried running it. I've used the lein trampoline
approach myself, so this will be interesting to figure out. :)
hmm the buildpack still uses lein 1.7 so that's quite out of date
I finally decided to add a main function starting jetty to the handler namespace:
(:require [ring.adapter.jetty :as ring])
...
(defn -main [& args]
(let [port (Integer/parseInt (or (System/getenv "PORT") "8080"))]
(ring/run-jetty #'app {:port port :join? false})))
This way there is no need for a buildpack. The Procfile template must look like this then:
web: java $JVM_OPTS -jar target/{{name}}.jar -m {{name}}.handler
Is there any downside to this?
There isn't any difference for uberjar, and lein ring will pretty much do the same thing. The main reason I'm using lein-ring is because it can also produce an uberwar for container deployment and it allows specifying the handler/init/destroy functions in the project file.
It might be worthwhile to add a main as well for heroku deployment or running with http-kit.
Ok, I see. Would it make sense then to move the dev-only dependencies (figwheel, piggieback, weasel etc) to the :dev
profile in project.clj so that they are not downloaded in production?
Yeah that would probably be a good plan. :)
But this would also require excluding the dev .clj files from the compilation.
shouldn't those already be excluded based on the profile though?
I think it is currently only true for the .cljs files
ah right, so the dev.clj
should probably be moved over to the env folder as well then.
What's the preferred way to deploy to heroku right now ? You proposed a Procfile running the uberjar but the template one still use lein trempoline. Also, the template Procfile is -web: lein with-profile production trampoline ring server And I think the leading dash make it be ignored by heroku so it uses its default clojure web proctype
The dash is a typo, but otherwise the lein version should be fine for most cases. The alternative would be to add a main and use web: java $JVM_OPTS -jar target/myapp.jar
in the Procfile as described above.
Ok, I had to use this one to avoid the 60sec timeout
On Sat, Jan 24, 2015 at 10:59 PM, Dmitri Sotnikov notifications@github.com wrote:
The dash is a typo, but otherwise the lein version should be fine for most cases. The alternative would be to add a main and use web: java $JVM_OPTS -jar target/myapp.jar in the Procfile as described above.
— Reply to this email directly or view it on GitHub https://github.com/reagent-project/reagent-template/issues/25#issuecomment-71339550 .
I think I'll just add a main for heroku to avoid the confusion
Yep, would be useful :p
On Sat, Jan 24, 2015 at 11:11 PM, Dmitri Sotnikov notifications@github.com wrote:
I think I'll just add a main for heroku to avoid the confusion
— Reply to this email directly or view it on GitHub https://github.com/reagent-project/reagent-template/issues/25#issuecomment-71340030 .
ok just push out a new version with a server.clj
that's used as a main when building using lein uberjar
this will make it easier to add support for http-kit in the future as well since lein-ring doesn't support it either.
A previously working build threw an R10 and H10 on a redeploy. Redeploying fixed it - there must be some cache that needs to heat up on Heroku. Worrying that it's not dependable. May also have something to do with queued up requests hitting cold app at once and triggering an alarm that causes an H10 state.
I am having difficulties deploying an app built with the template to Heroku. The generated Procfile tries to run the following task in a web worker:
When executing this task Leiningen begins downloading a gazillion of dependencies including the ones unnecessary for production (e.g figwheel), in spite of the fact that the standalone .jar file had already been built by the slug compiler. This results in the following error:
I tried changing the Procfile so that the jar file is executed directly:
But this doesn't work either, as the ring handler namespace does not include the -main method, and for some reason,
lein uberjar
does not generate a self-executable ring server.What's the right way to run the app on Heroku and to avoid fetching dependencies in the web worker?