jarohen / frodo

A lein plugin to start a Ring server via configuration in Nomad
38 stars 4 forks source link

Just wondering if frodo is deployable to heroku? #4

Closed Folcon closed 10 years ago

Folcon commented 10 years ago

I've tried using nomad to set the PORT env as any heroku app should bind to that:

{:nomad/environments
 {"dev"
  {:frodo/config {:web {:port 3000
                        :handler-fn foo.core/-main}
                  :cljs-repl? true}}}
 {"prod"
  {:frodo/config {:web {:port #nomad/env-var "PORT"
                        :handler-fn foo.core/-main}
                  :cljs-repl? false}}}}

but it keeps failing with a No dispatch macro for n {:type :reader-exception}

Or perhaps this is the wrong approach and I should just use http-kit?

jarohen commented 10 years ago

Hi Folcon - thanks for the bug report!

This was an error message that I hit a while back (pre 0.5.1) but seems to have come up in a different situation. Could you upload a sample project and the command you're using to start it?

A few things to try in the meantime:

Cheers,

James

jarohen commented 10 years ago

You could also work-around the second bullet-point (uberjarring etc) by writing a -main that calls

(frodo.core/init-frodo! (clojure.java.io/resource "config.edn"))

Maybe this is already in your -main? What does foo.core/-main look like?

James

jarohen commented 10 years ago

Also, now that I think about it, -main is a strange value for the handler-fn - Frodo expects it to be a 0-arg function that returns a Ring handler.

It'd definitely be very helpful to see a sample project ;)

James

Folcon commented 10 years ago

Here's some of the output from heroku and the example project.

2014-02-09T21:45:27.370457+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2014-02-09T21:45:27.370776+00:00 heroku[web.1]: Stopping process with SIGKILL
2014-02-09T21:45:29.261386+00:00 heroku[web.1]: State changed from starting to crashed
2014-02-09T21:45:29.261386+00:00 heroku[web.1]: State changed from crashed to starting
2014-02-09T21:45:29.248691+00:00 heroku[web.1]: Process exited with status 137

The Procfile shows the command that is run by heroku after getting the changes of the pushed repo and building it on the remote machine. In this case what appears after web:

I've commented out parts of the config file as I really couldn't get nomad to work.

jarohen commented 10 years ago

Hi - thanks for uploading this!

lein prod is just a lein alias - to build your CLJS and then run lein trampoline frodo - so this doesn't have anything to do with environment variables. You'll have to set the NOMAD_ENV variable in your Procfile for Nomad to use your 'prod' config. Something like web: NOMAD_ENV=prod lein prod should do it.

I've also updated Nomad + Frodo with the change that I described in the earlier comment - they're now 0.6.2 and 0.2.11 respectively. Nomad now has a #nomad/edn-env-var macro that you can use for the PORT variable, so that it is read in as a number rather than a string.

I'm going to close this issue as I've fixed the underlying problem, but I'd be interested to hear about your experiences with Nomad and answer any questions you've got - could you let me know how you're getting on?

Thanks again,

James

Folcon commented 10 years ago

Hey James,

Trying it a little this weekend, one oddity is that the #nomad/edn-env-var still evaluates even if I'm not presently in the prod environment. This requires me setting redundant duplicate environmental variables. Not sure if that is desired behaviour however. I'll probably be doing some more playing around, I'll keep you posted on anything I notice :)...

jarohen commented 10 years ago

Hi Folcon - thanks! This isn't desired behaviour - I don't think it's a good idea to force people to specify each env-var every time, even when they're not going to be used!

I've pushed a 0.6.3-SNAPSHOT to Clojars with a fix - could you let me know whether this fixes the issue? Previously, with env-vars being implemented as reader-macros, tools.reader would throw an exception if the reader-macro returned nil (even if the edn-env-var was missing, or intentionally nil) but this fix hopefully works around that bug.

Cheers,

James

Folcon commented 10 years ago

Looks good James, I'll give you a shout if I spot other issues! :)...